搜索
bottom↓
回复: 1

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

[复制链接]

出0入0汤圆

发表于 2010-10-17 13:28:50 | 显示全部楼层 |阅读模式
求助   LPC2132   串口通讯  程序的目的是判断接受以0x06开头的后续6个数据,但是实际运行却包含0x06在内的6个数据


通讯数据截图 (原文件名:未命名.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 &Egrave;&laquo;&Atilde;&eth; &Egrave;&laquo;&Aacute;&Aacute; &sup2;&raquo;&acute;&oslash;&ETH;&iexcl;&Ecirc;&yacute;&micro;&atilde;               
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 &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[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);         //&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[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周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2010-10-17 15:55:16 | 显示全部楼层
自己顶一下!  大家帮忙看看!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-12 22:36

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表