|
#include
#define uchar unsigned char
#define uint unsigned int
sbit E=P2^7; //1602使能引脚
sbit RW=P2^6; //1602读写引脚
sbit RS=P2^5; //1602数据/命令选择引脚
uint t;
uchar input[16];
void delay(uchar z)
{
uchar x, y;
for (x = 110; x > 0; x--)
{
for (y = z; y > 0; y--);
}
}
void com_init(void)
{
TMOD=0x20;
SCON=0x50;
PCON=0x00;
TH1=-(11059200/384/9600);
TR1=1;
EA=1;
ES=1;
}
void writecom(uchar com) //液晶的写指令
{
RS=0;
E=0;
P0=com;
delay(5);
E=1;
delay(5);
E=0;
}
void writedate(uchar date) //液晶的写数据
{
RS=1;
E=0;
P0=date;
delay(5);
E=1;
delay(5);
E=0;
}
void inti1() //液晶的初始化
{
RW=0;
writecom(0x38);
writecom(0x0c);
writecom(0x06);
writecom(0x01);
writecom(0x80);
}
void receive() interrupt 4 using 1
{
if(RI)
{
input[t] = SBUF;
RI=0;
SBUF = input[t]; //返回接收值
//writecom(0x80+m);
//writedate(input[t]);
//m++;
t++;
}
if(TI)
{
TI=0;
}
}
/**************************************************/
void display(uchar dy,uchar *p)
{
writecom(0x80+dy);
while(1)
{
if(*p == '\0') break;
writedate(*p);
p++;
}
}
/****************************/
void main(void)
{
t = 0;
com_init(); //串口初始化函数
inti1();
input[t]='\0';
display(2,input);
while(1);
}
这个程序能够把发送的给单片机的返回给电脑,但就是在1602上面显示不正确
|
|