0331631 发表于 2010-10-17 13:28:50

求助 LPC2132 串口通讯 程序的目的是判断接受以0x06开头的后续6个数据,但是实际

求助   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;
unsigned int lcdcode_3={};
unsigned int lcdcode_4={};
unsigned int segcode ={        0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0xff};//0-9 a-f &Egrave;&laquo;&Atilde;&eth; &Egrave;&laquo;&Aacute;&Aacute; &sup2;&raquo;&acute;&oslash;&ETH;&iexcl;&Ecirc;&yacute;&micro;&atilde;               
unsigned int segdotcode ={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0xff};//0-9 a-f &Egrave;&laquo;&Atilde;&eth; &Egrave;&laquo;&Aacute;&Aacute; &acute;&oslash;&ETH;&iexcl;&Ecirc;&yacute;&micro;&atilde;
uint32 temp;
uint32 wendu,dianya;
char shi,fen,miao;
uint32 time;
char testwe;
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;
        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);         //&micro;&Egrave;&acute;&yacute;&Ecirc;&yacute;&frac34;&Yacute;&frac12;&Oacute;&Ecirc;&Otilde;
        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;                // &Eacute;è&Ouml;&Atilde;&sup1;&Uuml;&frac12;&Aring;&Aacute;&not;&frac12;&Oacute;GPIO
        PINSEL0 = 0x00000005;          // &sup1;&Uuml;&frac12;&Aring;&Aacute;&not;&frac12;&Oacute;&acute;&reg;&iquest;&Uacute;UART0
        PINSEL1 = 0x00000000;       
        PINSEL2 = 0x00000004;          //&Eacute;è&Ouml;&Atilde;&sup1;&Uuml;&frac12;&Aring;&Aacute;&not;&frac12;&Oacute;GPIO       
        IO0DIR = 0x00000000 ;
        IO0CLR = 0x00000000 ;
        IO0SET = 0x00000000 ;
        IO0CLR = 0x00000000 ;
        IO1DIR= 0xffffffff;       
    IO1SET = IO1SET |(0xff<<16);      //&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;led&Egrave;&laquo;&Atilde;&eth;   
       
        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=kan1;
                jshou=kan2;
                DelayNS(10);               
               send_com0(jshou,8);
               jsok=0;
               }
              
               if (jshou==0x11) IO1CLR=IO1CLR|(0xff<<16);
               if (jshou==0x22) IO1SET=IO1SET|(0xff<<16);
               DelayNS(10);
                //if ((U0LSR&0x01)==0) IO1CLR|=(1<<17);
                //else IO1CLR|=(1<<17);
        }
        return -1;

}

0331631 发表于 2010-10-17 15:55:16

自己顶一下!大家帮忙看看!./emotion/em071.gif
页: [1]
查看完整版本: 求助 LPC2132 串口通讯 程序的目的是判断接受以0x06开头的后续6个数据,但是实际