#include <REGX51.H>
#include<stdio.h>
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P1^2;
char x;
void delay30ms(void)
{
TMOD=0x10;
TH1=35535/256;
TL1=35535%256;
TR1=1;
while(!TF1);
TR1=TF1=0;
}
void delay(unsigned long int t)
{
unsigned long int i;
for(i=0;i<t;++i);
}
void busy_flag(void)
{
P2=0xFF;
RS=0;
RW=1;
do
{
EN=1;
delay(10);
EN=0;
x=P2;
x=x&0x80;
}
while(x!=0x80);
}
void write_command(unsigned char LCD_command)
{
busy_flag();
P2 = LCD_command;
RS=0;
RW=0;
EN=1;
delay(50);
EN=0;
delay(50);
}
void write_data(unsigned char LCD_data)
{
busy_flag();
P2 = LCD_data;
RS=1;
RW=0;
EN=1;
delay(50);
EN=0;
delay(50);
}
void write_string(char *s)
{
while(*s)
{
write_data(*s);
s++;
}
}
void init(void)
{
write_command(0x03);
write_command(0x38);
write_command(0x06);
write_command(0x0E);
}
void main(void)
{
delay30ms();
init();
while(1)
{
write_command(0x01);
write_command(0x80);
write_string(" dai hoc cong nghiep");
write_command(0xc0);
write_string("khoa dien tu");
}
}
các sư huynh xem giùm nó có sai đâu hok,mình ktra hoài mà hok thấy,,bỏ vô chương trình hok chạy
#include<stdio.h>
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P1^2;
char x;
void delay30ms(void)
{
TMOD=0x10;
TH1=35535/256;
TL1=35535%256;
TR1=1;
while(!TF1);
TR1=TF1=0;
}
void delay(unsigned long int t)
{
unsigned long int i;
for(i=0;i<t;++i);
}
void busy_flag(void)
{
P2=0xFF;
RS=0;
RW=1;
do
{
EN=1;
delay(10);
EN=0;
x=P2;
x=x&0x80;
}
while(x!=0x80);
}
void write_command(unsigned char LCD_command)
{
busy_flag();
P2 = LCD_command;
RS=0;
RW=0;
EN=1;
delay(50);
EN=0;
delay(50);
}
void write_data(unsigned char LCD_data)
{
busy_flag();
P2 = LCD_data;
RS=1;
RW=0;
EN=1;
delay(50);
EN=0;
delay(50);
}
void write_string(char *s)
{
while(*s)
{
write_data(*s);
s++;
}
}
void init(void)
{
write_command(0x03);
write_command(0x38);
write_command(0x06);
write_command(0x0E);
}
void main(void)
{
delay30ms();
init();
while(1)
{
write_command(0x01);
write_command(0x80);
write_string(" dai hoc cong nghiep");
write_command(0xc0);
write_string("khoa dien tu");
}
}
các sư huynh xem giùm nó có sai đâu hok,mình ktra hoài mà hok thấy,,bỏ vô chương trình hok chạy
Comment