#include "BD3201.h"
//BD3201 OPJ文件中的数值
const unsigned long int BD3201_DATA[]=
{
0xF0407FFF,
0x00030000,
0x00030000,
0x00030000,
0x7F000000,
0x7F400002,
0x5C201006,
0x48231007,
0x0043200B,
0x5CA01006,
0x48A31007,
0x10E0200D,
0x0023200B,
0x00430000,
0x7F000000,
0x00430001,
0x00000000,
0x00000040,
0x00000080,
0x000000C0,
0x00000100,
0x00000140,
0x00000180,
0x000001C0,
0x00000200,
0x00000240,
0x00000280,
0x000002C0,
0x00000300,
0x00000340,
0x00000380,
0x000003C0,
0x000003C0,
};
void delay_us(unsigned int n)
{
unsigned int i;
for(i=0;i<n;i++)
{
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
}
}
void delay_ms(unsigned int s)
{
unsigned int i,t;
for(i=0;i<s;i++)
{
for(t=0;t<200;t++)
delay_us(i);
}
}
//BD3201写入8 位数据
//先发送高位
//上升沿数据有效
void db3201_write_8bit(unsigned char data)
{
unsigned char i=0;
for(i=0;i<8;i++)
{
if(data&0x80) {db32_data_H;}
else {db32_data_L;}
delay_us(20);
db32_clk_L;delay_us(1);
db32_clk_H;delay_us(20);
db32_clk_L;//delay_us(20);
data<<=1;
}
}
void BD3201_start(void)
{
db32_data_H;delay_us(200);
db32_clk_H;delay_us(200);
//网上时序
db32_data_H;delay_us(20);
db32_clk_H;delay_us(20);
db32_data_L;delay_us(20);
db32_clk_L;delay_us(20);
db32_clk_H;delay_us(20);
db32_data_H;delay_us(20);
db32_data_L;delay_us(20);
db32_clk_L;delay_us(20);
db32_clk_H;delay_us(20);
db32_data_H;delay_us(20);
db32_clk_L;delay_us(20);
db32_clk_H;delay_us(20);
}
void BD3201_stop(void)
{
db32_data_L;delay_us(20);
db32_data_H;delay_us(20);
db32_data_L;delay_us(20);
db32_data_H;delay_us(20);
db32_clk_L;delay_us(20);
db32_clk_H;delay_us(20);
}
void db3201_write_data(void)
{
unsigned char i=0,j=0;
db32_DDRx=0xff;
db32_PORTx=0xff;
//delay_ms(800);
BD3201_start();
db3201_write_8bit(0x00);
for(i=0;i<32;i++)
{
db3201_write_8bit((unsigned char)((BD3201_DATA[i]>>24)&0xff));
db3201_write_8bit((unsigned char)((BD3201_DATA[i]>>16)&0xff));
db3201_write_8bit((unsigned char)((BD3201_DATA[i]>>8)&0xff));
db3201_write_8bit((unsigned char)((BD3201_DATA[i]>>0)&0xff));
}
BD3201_stop();
}
那里不对了。。看懂的说说??谢谢 |