bác nào biết chỉ mình code này với nhé:
#include <REGX51.H>
#define LCD_PORT P0
#define LCD_RS P1_0
#define LCD_RW P1_1
#define LCD_EN P1_2
#define lcdLine1() lcd_write(0, 0x80)
#define lcdLine2() lcd_write(0, 0xc0)
void uart_init();
void lcd_init();
void delay(unsigned int i){
while(i--);
}
void lcd_write(unsigned char mode, unsigned char d){
LCD_PORT = d;
LCD_RW = 0;
if(mode == 1) LCD_RS = 1;
else LCD_RS = 0;
LCD_EN = 1;
delay(4);
LCD_EN = 0;
delay(40);
}
void lcd_PutStr(char const *str){
char const *sPtr;
sPtr = str;
while(*sPtr != '\0'){
lcd_write(1, *sPtr);
sPtr++;
}
}
void main(void){
unsigned char kt, pos, line, str[16];
uart_init();
lcd_init();
while(1){
TR1 = 1;
RI = 0;
kt = 0;
line = 0;
while(!RI);
str[kt++] = SBUF;
pos++;
if(str[0] == '~') line = 1;
if(str[0] == '!') line = 2;
if(line == 1) {
pos = 0;
lcdLine1();
}
if(line == 2) {
pos = 0;
lcdLine2();
}
if(pos > 0) lcd_PutStr(str);
}
}
void uart_init(){
SCON = 0x52;
TMOD = 0x22;
TH1 = TL1 = -3;
}
void lcd_init(){
lcd_write(0, 0x38);
lcd_write(0, 0x0C);
lcd_write(0, 0x01);
delay(500);
}
#include <REGX51.H>
#define LCD_PORT P0
#define LCD_RS P1_0
#define LCD_RW P1_1
#define LCD_EN P1_2
#define lcdLine1() lcd_write(0, 0x80)
#define lcdLine2() lcd_write(0, 0xc0)
void uart_init();
void lcd_init();
void delay(unsigned int i){
while(i--);
}
void lcd_write(unsigned char mode, unsigned char d){
LCD_PORT = d;
LCD_RW = 0;
if(mode == 1) LCD_RS = 1;
else LCD_RS = 0;
LCD_EN = 1;
delay(4);
LCD_EN = 0;
delay(40);
}
void lcd_PutStr(char const *str){
char const *sPtr;
sPtr = str;
while(*sPtr != '\0'){
lcd_write(1, *sPtr);
sPtr++;
}
}
void main(void){
unsigned char kt, pos, line, str[16];
uart_init();
lcd_init();
while(1){
TR1 = 1;
RI = 0;
kt = 0;
line = 0;
while(!RI);
str[kt++] = SBUF;
pos++;
if(str[0] == '~') line = 1;
if(str[0] == '!') line = 2;
if(line == 1) {
pos = 0;
lcdLine1();
}
if(line == 2) {
pos = 0;
lcdLine2();
}
if(pos > 0) lcd_PutStr(str);
}
}
void uart_init(){
SCON = 0x52;
TMOD = 0x22;
TH1 = TL1 = -3;
}
void lcd_init(){
lcd_write(0, 0x38);
lcd_write(0, 0x0C);
lcd_write(0, 0x01);
delay(500);
}