|
求助 LPC2132 串口通讯 程序的目的是判断接受以0x06开头的后续6个数据,但是实际运行却包含0x06在内的6个数据
![](http://cache.amobbs.com/bbs_upload782111/files_34/ourdev_590511CRGZ8M.jpg)
通讯数据截图 (原文件名:未命名.jpg)
#include "config.h"
#define BEEP 1<<7
#define lcd_rs_1() IO0SET|=(1<<19)
#define lcd_rs_0() IO0CLR|=(1<<19)
#define lcd_rw_1() IO0SET|=(1<<6)
#define lcd_rw_0() IO0CLR|=(1<<6)
#define lcd_en_1() IO0SET|=(1<<4)
#define lcd_en_0() IO0CLR|=(1<<4)
unsigned char lcdcode_1[]="haorenmeihaomeng";
unsigned char lcdcode_2[]="0331631123456000000";
unsigned char *lan;
char *test1;
uint8 jsok;
uint8 jshou[20];
unsigned int lcdcode_3[20]={};
unsigned int lcdcode_4[20]={};
unsigned int segcode[18] ={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0xff};//0-9 a-f È«Ãð È«ÁÁ ²»´øСÊýµã
unsigned int segdotcode[18] ={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0xff};//0-9 a-f È«Ãð È«ÁÁ ´øСÊýµã
uint32 temp;
uint32 wendu,dianya;
char shi,fen,miao;
uint32 time;
char testwe[10];
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<5000; i++);
}
/*int crc16 (char *dat, int cont)
{
int crc=0xffff;
char i;
while(cont!=0)
{
crc^=*dat;
for(i=0;i<8;i++)
{
if ((crc&0x0001)==0) crc=crc>>1;
else
{
crc=crc>>1;
crc^=0xa001;
}
cont-=1;
*dat+1;
}
}
return crc;
}*/
int crc16 (uint8 *dat, int cont)
{
int crc=0xffff;
int kk;
char i;
kk=0;
while(cont!=0)
{
//crc^=testwe[kk];
crc^=*dat;
for(i=0;i<8;i++)
{
if ((crc&0x0001)==0) crc=crc>>1;
else
{
crc=crc>>1;
crc^=0xa001;
}
}
//kk++;
*dat++;
cont-=1;
}
return crc;
}
uint8 UART0_SeceiveByte (void)
{ uint8 data;
while((U0LSR&0x01)==0); //µÈ´ýÊý¾Ý½ÓÊÕ
data=U0RBR;
return (data);
}
void get_com0(uint8 *s,uint32 n)
{
int nm;
for(nm=0;nm<n;nm++)
//for (;n>0;n--)
{
jshou[(nm)]=UART0_SeceiveByte();
}
}
void com_06(uint8 *s,uint32 n)
{
uint8 data;
int nm;
if ((U0LSR&0x01)==1)
{
data=U0RBR;
switch(data)
{
case 0x06:
for(nm=0;nm<n;nm++)
//for (;n>0;n--)
{
jshou[(nm)]=UART0_SeceiveByte();
}
jsok=11;
break;
}
}
/*else data=0x00;
if (data==0x06)
{
//DelayNS(1);
for(nm=0;nm<n;nm++)
//for (;n>0;n--)
{
jshou[(nm)]=UART0_SeceiveByte();
}
jsok=11;
}*/
}
void send_com0(uint8 const *aa,uint32 n)
{
//while(1)
// {
int nm1;
for (nm1=0;nm1<n;nm1++)
{
//if(*aa=='\0') break;
UART0_SendByte (jshou[(nm1)]);
}
}
int main (void)
{
int k;
int m,i;
char *tem11;
char *tem00,jieshou;
int biaozhi;
uint8 kan1,kan2;
float fa,fb,fc,fd,fe;
biaozhi=0;
shi=19;
fen=13;
miao=0;
//PINSEL0 = 0x00000000; // ÉèÖùܽÅÁ¬½ÓGPIO
PINSEL0 = 0x00000005; // ¹Ü½ÅÁ¬½Ó´®¿ÚUART0
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000004; //ÉèÖùܽÅÁ¬½ÓGPIO
IO0DIR = 0x00000000 ;
IO0CLR = 0x00000000 ;
IO0SET = 0x00000000 ;
IO0CLR = 0x00000000 ;
IO1DIR = 0xffffffff;
IO1SET = IO1SET |(0xff<<16); //³õʼ»¯ ledÈ«Ãð
UART0_Init();
while (1)
{
com_06(jshou,6);
//get_com0(jshou,6);
//DelayNS(10);
if (jsok==11)
{
wendu=crc16(jshou,6);
kan2=(wendu>>8);
kan1=(wendu&0x00ff);
jshou[6]=kan1;
jshou[7]=kan2;
DelayNS(10);
send_com0(jshou,8);
jsok=0;
}
if (jshou[1]==0x11) IO1CLR=IO1CLR|(0xff<<16);
if (jshou[2]==0x22) IO1SET=IO1SET|(0xff<<16);
DelayNS(10);
//if ((U0LSR&0x01)==0) IO1CLR|=(1<<17);
//else IO1CLR|=(1<<17);
}
return -1;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|