yukul
04-03-2012, 02:55 AM
các a vào xem giúp mình với.mình viết bỏ hàm busy_flag thì nó hiển thị chữ lên LCD,nhưng khi mình viết thêm hàm busy_flag vào thì nó không chạy nữa mà không biết sai chỗ nào.mong anh em sửa giúp.thanks các a nhiều lắm.
đây là code và mô phỏng e nó :
#include <18f4520.h>
#fuses nowdt,hs
#device *=16 adc=8
#use delay(clock=12000000)
#use fast_io(c)
#use fast_io(d)
#byte portc=0xf82
#bit RS=0xf82.0
#bit RW=0xf82.1
#bit E=0xf82.2
#byte portd=0xf83
void busy_flag() // ham kiem tra co ban cho LCD
{
int8 x;
//portd=0xff;
RS=0; //ghi lenh len LCD
RW=1; //doc thong tin tu LCD
do
{
E=1;
delay_ms(1);
E=0;
x=portd;
x=x&0x80;
}
while(x==0x80);
}
void write_command() //ham gui lenh cho LCD
{
//busy_flag();
RS=0;
RW=0;
E=1;
delay_ms(1);
E=0;
}
void write_data() // ham gui du lieu cho LCD
{
//busy_flag();
RS=1;
RW=0;
E=1;
delay_ms(1);
E=0;
}
void main()
{
set_tris_c(0x00);
set_tris_d(0x00);
//delay_ms(100);
portd=0x38;
write_command();
portd=0x0c;
write_command();
portd=0x85;
write_command();
portd='D';
write_data();
portd='T';
write_data();
portd='4';
write_data();
portd='K';
write_data();
portd='3';
write_data();
}
đây là code và mô phỏng e nó :
#include <18f4520.h>
#fuses nowdt,hs
#device *=16 adc=8
#use delay(clock=12000000)
#use fast_io(c)
#use fast_io(d)
#byte portc=0xf82
#bit RS=0xf82.0
#bit RW=0xf82.1
#bit E=0xf82.2
#byte portd=0xf83
void busy_flag() // ham kiem tra co ban cho LCD
{
int8 x;
//portd=0xff;
RS=0; //ghi lenh len LCD
RW=1; //doc thong tin tu LCD
do
{
E=1;
delay_ms(1);
E=0;
x=portd;
x=x&0x80;
}
while(x==0x80);
}
void write_command() //ham gui lenh cho LCD
{
//busy_flag();
RS=0;
RW=0;
E=1;
delay_ms(1);
E=0;
}
void write_data() // ham gui du lieu cho LCD
{
//busy_flag();
RS=1;
RW=0;
E=1;
delay_ms(1);
E=0;
}
void main()
{
set_tris_c(0x00);
set_tris_d(0x00);
//delay_ms(100);
portd=0x38;
write_command();
portd=0x0c;
write_command();
portd=0x85;
write_command();
portd='D';
write_data();
portd='T';
write_data();
portd='4';
write_data();
portd='K';
write_data();
portd='3';
write_data();
}