程序如下:
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit lcdrs= P1^0;
- sbit lcdrw= P1^1;
- sbit lcden= P2^5;
- uchar i,daa[];
- void delay(unsigned int i){while(--i);}
- void write(uchar da,bit cr)
- {
- lcdrs=cr;
- P0=da;
- delay(5);
- lcden=1;
- delay(15);
- lcden=0;
- }
- void init()
- {
- lcdrw=0;
- lcden=0;
- delay(1);
- write(0x38,0);
- write(0x0c,0);
- write(0x01,0);//??
- delay(155);
- write(0x80,0); //???
- }
- void URATinit( )
- {
- TMOD=0x20;
- SCON=0x50;
- EA=1;
- ES=1;
- TH1=0xfd;
- TL1=0xfd;
- TR1=1;
- }
- void receive() interrupt 4
- {
- if(RI)
- {
- RI=0;
- daa[i]=SBUF;
- write(daa[i],1);
- }
- i++;
- if(i>20)i=0;
- }
- void main()
- {
- init();
- URATinit( );
- while(1);
- }
复制代码 |