📄 emu-tdd.c
字号:
FIFO_CS1=0;
}
else
{
FIFO_CS2=1;
_nop_();
FIFO_CS2=0;
}
for(i=0;i<16;i++)
{
DOUT=((config_data&0x8000)==0x8000)?1:0;
config_data<<=1;
SCLK=0;
_nop_();
SCLK=1;
_nop_();
SCLK=0;
}
SCLK=0;
if(chip_cs==1) // chip select ,disable MAX3100
{
_nop_();
FIFO_CS1=1;
}
else
{
_nop_();
FIFO_CS2=1;
}
EA=1;
}
uint R_Config_uart(uchar chip_cs, uint config_data) // read the configuration of MAX3100
{
uchar i;
unsigned int aa,bb;
bb=0;
aa=0;
EA=0;
if(chip_cs==1) // chip select ,enable MAX3100
{
FIFO_CS1=1;
_nop_();
FIFO_CS1=0;
}
else
{
FIFO_CS2=1;
_nop_();
FIFO_CS2=0;
}
for(i=0;i<16;i++)
{
DOUT=((config_data&0x8000)==0x8000)?1:0;
config_data<<=1;
bb<<=1;
aa=(DIN==1)?1:0;
bb=bb|aa;
SCLK=0;
_nop_();
SCLK=1;
_nop_();
SCLK=0;
// bb<<=1;
// aa=(DIN==1)?1:0;
// bb=bb|aa;
}
if(chip_cs==1) // chip select ,disable MAX3100
{
FIFO_CS1=1;
}
else
{
FIFO_CS2=1;
}
EA=1;
return(bb);
}
uint Write_uart(uchar chip_cs,uchar *frame_tx,uchar frame_len) // write data into MAX3100
{
uint write_data,bb,aa;
uchar i,j;
EA=0;
if(chip_cs==1) // chip select ,enable MAX3100
{
FIFO_CS1=1;
_nop_();
FIFO_CS1=0;
}
else
{
FIFO_CS2=1;
_nop_();
FIFO_CS2=0;
}
for(j=0; j<frame_len; j++)
{
write_data = 0x8000;
write_data = write_data | *frame_tx;
/* if(chip_cs==1) // chip select ,enable MAX3100
{
FIFO_CS1=1;
_nop_();
FIFO_CS1=0;
}
else
{
FIFO_CS2=1;
_nop_();
FIFO_CS2=0;
}*/
for(i=0;i<16;i++)
{
DOUT=((write_data&0x8000)==0x8000)?1:0;
write_data<<=1;
bb<<=1;
aa=(DIN==1)?1:0;
bb=bb|aa;
SCLK=0;
_nop_();
SCLK=1;
_nop_();
SCLK=0;
}
/* if(chip_cs==1) // chip select ,disable MAX3100
{
FIFO_CS1=1;
}
else
{
FIFO_CS2=1;
}*/
frame_tx++;
}
if(chip_cs==1) // chip select ,disable MAX3100
{
FIFO_CS1=1;
}
else
{
FIFO_CS2=1;
}
EA=1;
return(bb);
}
uint Read_uart(uchar chip_cs,uchar *frame_rx) // read data out of MAX3100
{
uint read_data,bb,aa;
uchar i;
EA=0;
// for(j=0;j<frame_len;j++)
{
read_data=0x0000;
read_data=read_data|*frame_rx;
if(chip_cs==1) // chip select ,enable MAX3100
{
FIFO_CS1=1;
_nop_();
FIFO_CS1=0;
}
else
{
FIFO_CS2=1;
_nop_();
FIFO_CS2=0;
}
for(i=0;i<16;i++)
{
DOUT=((read_data&0x8000)==0x8000)?1:0;
read_data<<=1;
bb<<=1;
aa=(DIN==1)?1:0;
bb=bb|aa;
SCLK=0;
_nop_();
SCLK=1;
_nop_();
SCLK=0;
}
if(chip_cs==1) // chip select ,disable MAX3100
{
FIFO_CS1=1;
}
else
{
FIFO_CS2=1;
}
// frame_tx++;
}
*frame_rx=bb;
EA=1;
return(bb);
}
void Send_7281(uchar reg_add,uchar reg_data)
{
uchar i;
EA=0;
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
do
{
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
} while(BC_DATA);
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
while(!BC_DATA);
for( i=0;i<8;i++ )
{
BC_DATA=((reg_add&0x80)==0)?0:1;
reg_add<<=1;
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
BC_DATA=1;
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
do
{
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
} while(BC_DATA);
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
while(!BC_DATA);
for( i=0;i<8;i++ )
{
BC_DATA=((reg_data&0x80)==0)?0:1;
reg_data<<=1;
BC_CLK=0;
_nop_();
_nop_();
BC_CLK=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
BC_DATA=1;
EA=1;
}
uchar Read_c66(uint read_addr) // read data at address=0
{
uchar i,bb,cc;
EA=0;
EEPROM_CS=C66_EN;
for(i=0;i<12;i++)
{
DOUT=((read_addr&0x8000)==0)?0:1;
read_addr<<=1;
SCLK=0;
SCLK=1;
SCLK=0;
}
DOUT=0;
SCLK=1; // output one extra clock pulse to avoid reading dummy bit 0
SCLK=0;
for(i=0;i<8;i++)
{
bb<<=1;
cc=(DIN)?1:0;
bb=cc|bb;
SCLK=0;
SCLK=1;
SCLK=0;
}
EEPROM_CS=C66_DIS;
EA=1;
return(bb);
}
void Write_c66(uint write_addr,uchar write_data)
{
uchar i;
EA=0;
EEPROM_CS=C66_EN;
for(i=0;i<12;i++)
{
DOUT=((write_addr&0x8000)==0)?0:1;
write_addr<<=1;
SCLK=0;
_nop_();
SCLK=1;
_nop_();
SCLK=0;
}
for(i=0;i<8;i++)
{
DOUT=((write_data&0x80)==0)?0:1;
write_data<<=1;
SCLK=0;
_nop_();
SCLK=1;
_nop_();
SCLK=0;
}
DOUT=0;
EEPROM_CS=C66_DIS;
_nop_();
_nop_();
EEPROM_CS=C66_EN;
while(!DIN);
EEPROM_CS=C66_DIS;
EA=1;
}
void Ewen_c66(uint ewen_ins) // enable erase and write opration
{
uchar i;
EA=0;
EEPROM_CS=C66_EN;
for(i=0;i<12;i++)
{
DOUT=((ewen_ins&0x8000)==0)?0:1;
ewen_ins<<=1;
SCLK=0;
SCLK=1;
SCLK=0;
}
DOUT=0;
EEPROM_CS=C66_DIS;
EA=1;
}
void Erase_c66(uint erase_addr) // erase unit at address=0
{
uchar i;
EEPROM_CS=C66_EN;
for(i=0;i<12;i++)
{
DOUT=((erase_addr&0x8000)==0)?0:1;
erase_addr<<=1;
SCLK=0;
SCLK=1;
SCLK=0;
}
DOUT=0;
EEPROM_CS=C66_DIS;
}
uint Analog_input(uchar ch)
{
uchar ii,con_byte;
uint ana_byte0=0;
uchar channel[8] = {0x8f, 0xcf, 0x9f, 0xdf,0xaf,0xef,0xbf,0xff};
bit aa_bit;
EA=0;
con_byte = channel[ch];
ADC_CS = 0;
for(ii=0;ii<8;ii++)
{
DOUT = (con_byte&0x80)?1:0;
con_byte<<=1;
SCLK = 0; // data clocked in by rising_edge
_nop_();
SCLK=1;
_nop_();
SCLK=0; // data clocked out by down_edge
}
for(ii=0;ii<5;ii++) _nop_();
// while(!sstrb_186);
for(ii=0;ii<16;ii++)
{
SCLK = 1;
_nop_();
SCLK = 0;
_nop_();
aa_bit = DIN;
ana_byte0 = ana_byte0*2|aa_bit;
}
ADC_CS = 1;
ana_byte0 >>= 4;
EA=1;
return ana_byte0;
}
uint calCRC(uchar *ptr, uchar len)
{
uint crc = 0;
uchar halfByte;
uint crcTab[16]={0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,
0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF}; // table of CRC-16 remainders
while(len--)
{
halfByte = (uchar)((crc >> 12) & 0x000F); // save CRC higher 4 bits
crc <<= 4; // shift left 4 bits
crc ^= crcTab[halfByte ^ (*ptr >> 4)]; // the CRC value of the current byte equals to the lower 12 bits of the previous CRC code plus
// the CRC value from the sum of the higher 4 bits of the previous CRC code and the current byte
halfByte = (uchar)((crc >> 12) & 0x000F); // save CRC higher 4 bits
crc <<= 4; // shift left 4 bits
crc ^= crcTab[halfByte ^ (*ptr & 0x0F)]; // the CRC value of the current byte equals to the lower 12 bits of the previous CRC code plus
// the CRC value from the sum of the lower 4 bits of the previous CRC code and the current byte
ptr++;
}
return(crc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -