các pro sửa giúp e code này với
em build thì nó hiện lỗi một lỗi ở chố "RS=0" ĐẦU TIÊN
#include <REGX51.H>
/*=========bo tien xu li===============*/
#include<string.h>
/*===========khai bao bien toan cuc============*/
sfr LCDdata = 0xA0; // cong P2, 8 bit du lieu.
sbit BF = 0xA7; // co ban, bit DB7.
#define RS P3^0 // chon thanh ghi
#define RW P3^1 // doc/ghi
#define EN P3^2 //cho phep chot du lieu
/*===========cac chuong trinh con cua LCD==========*/
/*--------------kiem tra su san sang cua LCD------------------------*/
void wait(void)
{
RS=0; //chon thanh ghi lenh
nop();
RW=1; //doc tu LCD
LCDdata=0xff; //gia tri 0xff
while(BF) //kiem tra co ban
{
EN=0; //dua xung cao xuong thap de chot.
nop();
EN=1; //dua chan cho phep len cao
}
}
/*------------------------thiet lap lenh cho LCD--------------------------*/
void LCDcontrol(unsigned char x)
{
RS=0;//chon thanh ghi lenh
RW=0;//ghi len LCD.
LCDdata=x ;// gia tri x
EN=1;//cho phep muc cao
EN=0;//xung cao xuong thap
wait();//doi LCD san sang.
}
/*------------------------------Khoi tao LCD-------------------------*/
void LCDinit(void)
{
LCDcontrol(0x38);//2 dong va ma tran 5x7
LCDcontrol(0x0e);//bat man hinh, bat con tro
LCDcontrol(0x01);//xoa man hinh
}
/*-------------------------thiet lap du lieu cho LCD-----------------*/
void LCDwrite(unsigned char c)
{
RS=1;//ghi du lieu
RW=0;//ghi du lieu len LCD
LCDdata=c;//gia tri C
EN=1;//cho phep muc cao
EN=0;//xung cao xuong thap
wait();//cho
}
void LCDwrites(unsigned char *s)
{
unsigned char data lens,count;
lens=strlen(s);
for(count=0;count<lens;count++){
LCDwrite(*(s+count));
}
}
/*=====================chuong trinh tre================*/
void delay(long time)
{
while(time--);
}
/*========================ham chinh==================*/
void main(void)
{
LCDinit(); // khoi tao LCD
LCDcontrol(0x82);// dua con tro den vi tri thu 4 dong 1
LCDwrite("V");
LCDwrite("I");
LCDwrite("E");
LCDwrite("T");
LCDwrite(" ");
LCDwrite("N");
LCDwrite("A");
LCDwrite("M");
LCDcontrol(0xC0);
LCDwrites("VI DIEU KHIEN");
while(1); //vong lap vo han
}
em build thì nó hiện lỗi một lỗi ở chố "RS=0" ĐẦU TIÊN
#include <REGX51.H>
/*=========bo tien xu li===============*/
#include<string.h>
/*===========khai bao bien toan cuc============*/
sfr LCDdata = 0xA0; // cong P2, 8 bit du lieu.
sbit BF = 0xA7; // co ban, bit DB7.
#define RS P3^0 // chon thanh ghi
#define RW P3^1 // doc/ghi
#define EN P3^2 //cho phep chot du lieu
/*===========cac chuong trinh con cua LCD==========*/
/*--------------kiem tra su san sang cua LCD------------------------*/
void wait(void)
{
RS=0; //chon thanh ghi lenh
nop();
RW=1; //doc tu LCD
LCDdata=0xff; //gia tri 0xff
while(BF) //kiem tra co ban
{
EN=0; //dua xung cao xuong thap de chot.
nop();
EN=1; //dua chan cho phep len cao
}
}
/*------------------------thiet lap lenh cho LCD--------------------------*/
void LCDcontrol(unsigned char x)
{
RS=0;//chon thanh ghi lenh
RW=0;//ghi len LCD.
LCDdata=x ;// gia tri x
EN=1;//cho phep muc cao
EN=0;//xung cao xuong thap
wait();//doi LCD san sang.
}
/*------------------------------Khoi tao LCD-------------------------*/
void LCDinit(void)
{
LCDcontrol(0x38);//2 dong va ma tran 5x7
LCDcontrol(0x0e);//bat man hinh, bat con tro
LCDcontrol(0x01);//xoa man hinh
}
/*-------------------------thiet lap du lieu cho LCD-----------------*/
void LCDwrite(unsigned char c)
{
RS=1;//ghi du lieu
RW=0;//ghi du lieu len LCD
LCDdata=c;//gia tri C
EN=1;//cho phep muc cao
EN=0;//xung cao xuong thap
wait();//cho
}
void LCDwrites(unsigned char *s)
{
unsigned char data lens,count;
lens=strlen(s);
for(count=0;count<lens;count++){
LCDwrite(*(s+count));
}
}
/*=====================chuong trinh tre================*/
void delay(long time)
{
while(time--);
}
/*========================ham chinh==================*/
void main(void)
{
LCDinit(); // khoi tao LCD
LCDcontrol(0x82);// dua con tro den vi tri thu 4 dong 1
LCDwrite("V");
LCDwrite("I");
LCDwrite("E");
LCDwrite("T");
LCDwrite(" ");
LCDwrite("N");
LCDwrite("A");
LCDwrite("M");
LCDcontrol(0xC0);
LCDwrites("VI DIEU KHIEN");
while(1); //vong lap vo han
}
Comment