E viết xòng nhưng lúc mô phỏng thì nó không chạy gì cả , màn hình cứ cái LCD cứ trăng xóa thế thôi mà chả biết sai chỗ nào Mọi người xem hộ e với
#include"regx51.h"
#include"string.h"
#define LCD_PORT P1
#define RS P3_5
#define RW P3_6
#define EN P3_7
#define D7 P1_7
void delay(unsigned char ms)
{
int i,j;
for(i=0;i<=ms;i++)
for(j=0;j<=120;j++)
{}
}
void wait(void)
{
D7=1;
RS=0;
RW=1;
while(D7!=0)
{
EN=1;
EN=0;
}
}
void ghi_lenh(unsigned char x)
{
wait();
LCD_PORT=x;
RS=0;
RW=0;
EN=1;
EN=0;
}
void ghi_data(unsigned char x)
{
wait();
LCD_PORT=x;
RS=1;
RW=0;
EN=1;
EN=0;
}
void khoitao(void)
{
ghi_lenh(0x30);
ghi_lenh(0x38);
ghi_lenh(0xc0);
ghi_lenh(0x06);
ghi_lenh(0x01);
}
void chuoi(unsigned char *s)
{
while(*s)
{
ghi_data(*s);
s++;
}
}
void main(void)
{
khoitao();
ghi_lenh(0x01);
ghi_lenh(0x80);
chuoi("DT7");
ghi_lenh(0xc0);
chuoi("HAUI");
}
#include"regx51.h"
#include"string.h"
#define LCD_PORT P1
#define RS P3_5
#define RW P3_6
#define EN P3_7
#define D7 P1_7
void delay(unsigned char ms)
{
int i,j;
for(i=0;i<=ms;i++)
for(j=0;j<=120;j++)
{}
}
void wait(void)
{
D7=1;
RS=0;
RW=1;
while(D7!=0)
{
EN=1;
EN=0;
}
}
void ghi_lenh(unsigned char x)
{
wait();
LCD_PORT=x;
RS=0;
RW=0;
EN=1;
EN=0;
}
void ghi_data(unsigned char x)
{
wait();
LCD_PORT=x;
RS=1;
RW=0;
EN=1;
EN=0;
}
void khoitao(void)
{
ghi_lenh(0x30);
ghi_lenh(0x38);
ghi_lenh(0xc0);
ghi_lenh(0x06);
ghi_lenh(0x01);
}
void chuoi(unsigned char *s)
{
while(*s)
{
ghi_data(*s);
s++;
}
}
void main(void)
{
khoitao();
ghi_lenh(0x01);
ghi_lenh(0x80);
chuoi("DT7");
ghi_lenh(0xc0);
chuoi("HAUI");
}
Comment