//接收模块
/*--------------------------------
Program make by AC
Date xx/08/2011
--------------------------------*/
#include"LCD12864.h"
#define N 11
/*-----------------------------------
此为接收端:
通讯协议: 确定发送的位数n+3.
接收数据: "0123456789"
帧数据头:
------------------------------------*/
uchar rpt=0;
uchar flags=1; //接收标志
//uchar PT2622[N]={1,2,3,4,5,6,7,8,9,10,11};
uchar PT2622[N]="01234567890";
uchar PT2622_Table[N];
sfr PortReceive=0x90;
uchar ReceivePt2622()
{
uchar temp;
temp=PortReceive&0x0f;
return temp;
}
void Init0 () interrupt 0
{
uchar i=0;
EA=0;
if(0==flags)
{
if(rpt>=N) rpt=0;
else
{
PT2622[rpt]=ReceivePt2622();
if(1==rpt)
{
//compare 要求两个数据取反后相等 when received 0x0a,0x05
if( (PT2622[1])!=(~PT2622[0]) )
{
rpt=0;
PT2622[0]=0;
PT2622[1]=0;
goto exit;
}
}
else if((N-1)==rpt)
{
//compare 0x0a when received 0101B
if( 0x0a!=(~PT2622[N-1]) )
{
rpt=0;
for(i=N-1;i>=0;i--){
PT2622[i]=0;
}
}
else flags=1; //成功接收
}
else
{
rpt++;
}
}
}
exit:
_nop_();
EA=1;
}
void ProcessRecive()
{
//process data except first and last here!
uchar i=0;
for(i=2;i<N-2;i++){
PT2622_Table[i]=PT2622[i];
}
flags=0;
}
void InitBreak(void)
{
PX0=1;
IE0=1;
EX0=1;
EA=1;
}
void Delay(uint n)
{
uchar i;
while(n--)
for(i=0;i<100;i++);
}
uchar code table[]="01234567890";
void main()
{
uchar i=0;
Delay400Ms(); //启动等待,等LCD讲入工作状态
LCDInit(); //LCM初始化
InitBreak();
while(1){
if(1==flags){
ProcessRecive();
}
// for(i=0;i<8;i++){
// PT2622_Table[i]=table[PT2622_Table[i]];
// }
DisplayListChar(0,2,PT2622_Table);;
}
}
//发送模块
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define N (8+3)
/*-----------------------------------
此为发送端:
通讯协议: 确定发送的位数N+3.
发送数据: "12345678"
------------------------------------*/
uchar a,b;
sfr PortSend=0xA0;
void Delay(uint n)
{
uchar i;
while(n--)
for(i=0;i<100;i++);
}
void SendData(uchar dat)
{
//get data here!
PortSend=dat&0x0f;
}
//delay times must >slave process times!
uchar p[]={1,2,3,4,5,6,7,8,9};
void main()
{
uchar i;
while(1){
SendData(0x0a);
Delay(10);
SendData(0x05);
Delay(10);
for(i=0;i<8;i++){
SendData(p[i]);
Delay(10);
}
SendData(0x05);
Delay(10);
}
}
//0x0a,0x05,0x05为校验数据,防止数据在传送过程中发生错误!详细请参照《数字通信原理》