金牌会员
- 积分
- 1646
- 威望
- 682
- 贡献
- 634
- 兑换币
- 433
- 注册时间
- 2012-12-8
- 在线时间
- 165 小时
|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
uchar buff2[10];
void SetBusCLK_64M()
{
CLKSEL=0X00;
PLLCTL_PLLON=1;
SYNR=0xc0 | 0x07;
REFDV=0x80 | 0x01;
POSTDIV=0x00;
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1));
CLKSEL_PLLSEL =1;
}
void AD_init()
{
ATD0DIEN=0X00;
ATD0CTL1=0X40;
ATD0CTL2=0X40;
ATD0CTL3=0X88;
ATD0CTL4=0X4F;
ATD0CTL5=0X20;
}
void SCI_init()
{
SCI0BD=416;
SCI0CR1=0X00;
SCI0CR2=0X0C;
}
void SCI_send(uchar AD_capture)
{
while(!SCI0SR1_TDRE);
SCI0DRH=AD_capture;
}
void CRC_CHECK(unsigned char *Buf, unsigned char Len)
{
unsigned int CRC_Temp;
unsigned char i,j;
CRC_Temp = 0xffff; //CRC初始化
for (i=0;i<Len; i++)//要循环的次数,就是Buf的字节数
{
CRC_Temp ^= *(Buf+i); //逐字节异或
for (j=0;j<8;j++)
{
if (CRC_Temp & 0x01) //如果低位为1
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001; //将CRC右移一位后与0xA001异或
else //如果低位为0
CRC_Temp = CRC_Temp >> 1; //将CRC右移一位
}
}
Buf[8] = CRC_Temp & 0x00ff; //将第9个数据赋上CRC的低字节
Buf[9] =CRC_Temp >>8;//第10数据上是CRC的高字节
}
void main(void)
{
uchar AD_RESULT,i;
SetBusCLK_64M();
AD_init();
SCI_init();
for(;;)
{
while(!ATD0STAT2_CCF0);
AD_RESULT=ATD0DR0;
buff2[0]= AD_RESULT;
CRC_CHECK(buff2,8);
for(i=0;i<10;i++)
SCI_send(*(buff2+i));
}
}
|
|