代码如下:
#include "stc15.h"
#include "intrins.h"
sbit E = P5^2;
sbit RW = P5^1;
sbit RS = P5^0;
void delay_ms(int ms)
{
int i,j;
for(i=0; i<ms; i++)
for(j=0; j<1005; j++);
}
//
void Port_W(char value)
{
E=0;
RW=0;
P4=value;
E=1;
delay_ms(10);
E=0;
}
void LCD_Initial()
{
P54 = 1;
RS=0;
Port_W(0x38);
delay_ms(30);
Port_W(0x38);
delay_ms(30);
Port_W(0x38);
delay_ms(30);
Port_W(0x01);
delay_ms(30);
Port_W(0x06);
delay_ms(30);
Port_W(0x0C);
delay_ms(30);
}
void disp(char addr, char dat)
{
RS=0;
Port_W(addr+0x80);
delay_ms(30);
RS=1;
Port_W(dat);
delay_ms(30);
}
#include "stc15.h"
#include "intrins.h"
#include "lcd1602.h"
unsigned char RXD[16];
unsigned char j=0;
unsigned char k=0;
void UartInit(void)
{
SCON = 0x50;
AUXR |= 0x40;
AUXR &= 0xFE;
TMOD &= 0x0F;
TL1 = 0x8F;
TH1 = 0xFD;
ET1 = 0;
TR1 = 1;
}
void uart_RX() interrupt 4
{
if(RI==1)
{
RI=0;
RXD[j]=SBUF;
j++;
}
}
void main()
{
unsigned char send[]={"WELCOME TO RADIO"};
unsigned char i;
unsigned char RXFSH;
unsigned char tmp;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x10;
P5M1 = 0x00;
LCD_Initial();
UartInit();
ES=1;
EA=1;
while(1)
{
while(!P23)
{
for(i=0;i<16;i++)disp(i,0x20);
for(i=0;i<16;i++)disp(i,send[i]);
for(i=0;i<16;i++)
{
SBUF=send[i];
while(TI==0);
TI=0;
delay_ms(1000);
}
}
if((!RXFSH)&&(j))
{
tmp = j;
delay_ms(10);
if(tmp == j)
{
RXFSH = 1;
}
}
if(RXFSH)
{
if(k==0)
{
for(i=0;i<16;i++) disp(0x40+i,0x20);
}
if(k<j)
{
disp(0x40+k,RXD[k]);
k++;
}
else
{
k = 0;
j = 0;
RXFSH = 0;
}
}
}
}
#include "stc15.h"
#include "intrins.h"
sbit E = P5^2;
sbit RW = P5^1;
sbit RS = P5^0;
void delay_ms(int ms)
{
int i,j;
for(i=0; i<ms; i++)
for(j=0; j<1005; j++);
}
//
void Port_W(char value)
{
E=0;
RW=0;
P4=value;
E=1;
delay_ms(10);
E=0;
}
void LCD_Initial()
{
P54 = 1;
RS=0;
Port_W(0x38);
delay_ms(30);
Port_W(0x38);
delay_ms(30);
Port_W(0x38);
delay_ms(30);
Port_W(0x01);
delay_ms(30);
Port_W(0x06);
delay_ms(30);
Port_W(0x0C);
delay_ms(30);
}
void disp(char addr, char dat)
{
RS=0;
Port_W(addr+0x80);
delay_ms(30);
RS=1;
Port_W(dat);
delay_ms(30);
}
#include "stc15.h"
#include "intrins.h"
#include "lcd1602.h"
unsigned char RXD[16];
unsigned char j=0;
unsigned char k=0;
void UartInit(void)
{
SCON = 0x50;
AUXR |= 0x40;
AUXR &= 0xFE;
TMOD &= 0x0F;
TL1 = 0x8F;
TH1 = 0xFD;
ET1 = 0;
TR1 = 1;
}
void uart_RX() interrupt 4
{
if(RI==1)
{
RI=0;
RXD[j]=SBUF;
j++;
}
}
void main()
{
unsigned char send[]={"WELCOME TO RADIO"};
unsigned char i;
unsigned char RXFSH;
unsigned char tmp;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x10;
P5M1 = 0x00;
LCD_Initial();
UartInit();
ES=1;
EA=1;
while(1)
{
while(!P23)
{
for(i=0;i<16;i++)disp(i,0x20);
for(i=0;i<16;i++)disp(i,send[i]);
for(i=0;i<16;i++)
{
SBUF=send[i];
while(TI==0);
TI=0;
delay_ms(1000);
}
}
if((!RXFSH)&&(j))
{
tmp = j;
delay_ms(10);
if(tmp == j)
{
RXFSH = 1;
}
}
if(RXFSH)
{
if(k==0)
{
for(i=0;i<16;i++) disp(0x40+i,0x20);
}
if(k<j)
{
disp(0x40+k,RXD[k]);
k++;
}
else
{
k = 0;
j = 0;
RXFSH = 0;
}
}
}
}