#include "DELAY.H"
#include "lcd1602.h"
#include "uart.h"
#include<string.h>
#define Uart1_Buf_Max 70
#define Uart2_Buf_Max 70
#define uint unsigned int
#define uchar unsigned char
write_com(unsigned char);
u8 count = 0;
u8 idata Rec_Buf[Uart1_Buf_Max];
u8 point1 = 0;
u8 a,flag;
u8 xdata Uart2_Rec_Buf[Uart2_Buf_Max];
u8 point2 = 0;
bit B_TX2_Busy = 0;
void GPIO_config(void)
{
P5M0 &= ~(1<<5);
P5M1 &= ~(1<<5);
}
void UartInit(void) //9600bps@11.0592MHz
{
PCON &= 0x7F;
SCON = 0x50;
AUXR |= 0x40;
AUXR &= 0xFE;
TMOD &= 0x0F;
TMOD |= 0x20;
TL1 = 0xDC;
TH1 = 0xDC;
ET1 = 0;
TR1 = 1;
S2CON = 0x50;
AUXR |= 0x04;
T2L = 0xE0;
T2H = 0xFE;
AUXR |= 0x10;
UART2_INT_ENABLE();
ES = 1;
EA = 1;
}
void SendData(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0;
}
void SendString(char *s)
{
while (*s)
{
SendData(*s++);
}
}
void Send(unsigned char *s,unsigned int len)
{
for(a = 0;a<len;a++)
{
SendData(*s++);
}
}
bit Hand(unsigned char *a)
{
if(strstr(Rec_Buf,a)!=NULL)
return 1;
else
return 0;
}
void CLR_Buf(void)
{
memset(Rec_Buf, 0, Uart1_Buf_Max);
point1 = 0;
}
void Uart2SendData(unsigned char ch)
{
while(B_TX2_Busy);
S2BUF = ch;
B_TX2_Busy = 1;
}
void Uart2SendString(char *s)
{
while (*s)
{
Uart2SendData(*s++);
}
}
bit Uart2Hand(unsigned char *a)
{
if(strstr(Uart2_Rec_Buf,a)!=NULL)
return 1;
else
return 0;
}
void Uart2CLR_Buf(void)
{
memset(Uart2_Rec_Buf, 0, Uart2_Buf_Max);
point2 = 0;
}
void main(void)
{
unsigned char add;
unsigned char hh;
hh=Uart2_Rec_Buf[20],10;
GPIO_config();
UartInit();
Init_LCD1602();
LCD1602_write_com(0x80);
LCD1602_write_word("weidu ");
LCD1602_write_com(0x80+0x40);
LCD1602_write_word("jingdu ");
Send(&Uart2_Rec_Buf[32],11);
hh=Uart2_Rec_Buf[32];
LCD1602_write_word("hh ");
write_com(0x80+0x40+add);
write_date(0x30+hh);
delay_ms(200);
while(1)
{
SendString("\r\n");
Send(&Uart2_Rec_Buf[0],70);
SendString("\r\nweidu:\r\n");
Send(&Uart2_Rec_Buf[20],10);
SendString("\r\nnanbeibanqiu:\r\n");
Send(&Uart2_Rec_Buf[30],1);
SendString("\r\n");
SendString("jindu:\r\n");
Send(&Uart2_Rec_Buf[32],11);
SendString("\r\n");
SendString("dongxibanqiu:\r\n");
Send(&Uart2_Rec_Buf[43],1);
SendString("\r\n");
SendString("shijian(shi fen miao):\r\n");
Send(&Uart2_Rec_Buf[7],6);
SendString("\r\n");
SendString("shijian(nian yue ri):\r\n");
Send(&Uart2_Rec_Buf[61],2);
Send(&Uart2_Rec_Buf[59],2);
Send(&Uart2_Rec_Buf[57],2);
SendString("\r\n");
SendString("dimiansudu:\r\n");
Send(&Uart2_Rec_Buf[45],6);
SendString("\r\n");
SendString("dimianhangxiang:\r\n");
Send(&Uart2_Rec_Buf[51],6);
SendString("\r\n");
SendString("cipianjiaofangxiang:\r\n");
Send(&Uart2_Rec_Buf[66],1);
SendString("\r\n");
/*
flag = 0;
point1=0;
point2=0;
ES = 1; */
clrStruct();
SendString("\r\n");
Send(&Uart2_Rec_Buf[0],70);
SendString("\r\nweidu:\r\n");
Send(&Uart2_Rec_Buf[20],10);
SendString("\r\nnanbeibanqiu:\r\n");
Send(&Uart2_Rec_Buf[30],1);
SendString("\r\n");
SendString("jindu:\r\n");
Send(&Uart2_Rec_Buf[32],11);
SendString("\r\n");
SendString("dongxibanqiu:\r\n");
Send(&Uart2_Rec_Buf[43],1);
SendString("\r\n");
SendString("shijian(shi fen miao):\r\n");
Send(&Uart2_Rec_Buf[7],6);
SendString("\r\n");
SendString("shijian(nian yue ri):\r\n");
Send(&Uart2_Rec_Buf[61],2);
Send(&Uart2_Rec_Buf[59],2);
Send(&Uart2_Rec_Buf[57],2);
SendString("\r\n");
SendString("dimiansudu:\r\n");
Send(&Uart2_Rec_Buf[45],6);
SendString("\r\n");
SendString("dimianhangxiang:\r\n");
Send(&Uart2_Rec_Buf[51],6);
SendString("\r\n");
SendString("cipianjiaofangxiang:\r\n");
Send(&Uart2_Rec_Buf[66],1);
SendString("\r\n");
}
}
void Usart2() interrupt 8 using 1
{
UART2_INT_DISABLE();
if(RI2)
{
CLR_RI2();
Uart2_Rec_Buf[point2] = S2BUF;
if(Uart2_Rec_Buf[0]!='$')
{
point2=0;
return;
}
point2++;
if(point2>=Uart2_Buf_Max)
{
//flag=1;
point2 = 0;
return;
}
}
if (TI2)
{
CLR_TI2();
B_TX2_Busy = 0;
Uart2CLR_Buf() ;
}
UART2_INT_ENABLE();
}
void Usart() interrupt 4 using 1
{
ES = 0;
if (RI)
{
RI = 0;
Rec_Buf[point1] = SBUF;
point1++;
if(point1>=Uart1_Buf_Max)
{
point1 = 0;
// flag=1;
}
}
if (TI)
{
TI = 0;
// CLR_Buf();
}
ES = 1;
}
这个代码只能提取出数据,不能在液晶上显示数据 |