uart.c
#include <reg52.h>
#include "uart.h"
#define uint unsigned int
#define uchar unsigned char
typedef unsigned int u16;
typedef unsigned char u8;
void URATinit()
{
TMOD=0x20;
SCON=0x50;
TR1=1;
TH1=0xfd;
TL1=0xfd;
EA=1;
ES=1;
}
void Uart_Send_Byte(unsigned char dat)
{
SBUF = dat;
while(!TI);
TI=0;
}
void Uart_Send_String(unsigned char *p)
{
while(*p)
{
Uart_Send_Byte(*p++);
}
}
u8 ch,i;
u8 RX_BUF[10],RX_DAT[10],RX_CNT=0,RX_OVER=0;
void Uart_IRQ() interrupt 4
{
if(RI)
{
ch=SBUF;
if(ch!='}')
{
RX_BUF[RX_CNT++]=ch;
}
else
{
for(i=0;i<RX_CNT;i++)
{
RX_DAT[i]=RX_BUF[i];
}
RX_CNT=0;
RX_OVER=1;
}
RI=0;
}
}
uart.h
#ifndef __UART_H__
#define __UART_H__
extern unsigned char RX_DAT[10],RX_OVER;
extern unsigned char i;
void URATinit();
void Uart_Send_Byte(unsigned char dat);
void Uart_Send_String(unsigned char *p);
void Uart_IRQ();
#endif
main.c
#include <reg52.h>
#include "Delay.h"
#include "uart.h"
#include "string.h"
void main()
{
URATinit( );
while(1)
{
RX_OVER=0;
}
}
}
|