发表于:2014/8/13 10:02:10
#0楼
各位高手,小弟正在调试一个AVR单片机的程序。LCD液晶屏是1602,我想在LCD屏上显示信息,但是总是无法显示。调试的时候,屏蔽了大部分LCD控制代码,只保留了对RS和RW2个端口的设置。AVR单片机的PC4引脚与RS端口相连,写代码将PC4引脚设置为低电平,但是,当我用万用表测试PC4引脚电平的时候,发现其仍为高电平。请教其中的原因。谢谢!部分代码如下:
void init_port()
{
DDRB = 0xff;
PORTB = 0xff;
LCD_RS_DDR |= LCD_RS;
LCD_RW_DDR |= LCD_RW;
LCD_EN_DDR |= LCD_EN;
LCD_DATA_DDR |= LCD_DATA;
}
void LCD_init()
{
LCD_write_command(0x28);
//LCD_en_write();
//delay_nus(50);
//LCD_write_command(0x28);
//LCD_write_command(0x0c);
//LCD_write_command(0x01);
//delay_nms(5);
}
void LCD_write_command(uchar command)
{
delay_nus(20);
LCD_RS_PORT &= ~LCD_RS;
LCD_RW_PORT &= ~LCD_RW;
//LCD_DATA_PORT &= 0x0f;
//LCD_DATA_PORT |= command&0xf0;
//LCD_en_write();
//command = command<<4;
//LCD_DATA_PORT &= 0x0f;
//LCD_DATA_PORT |= command&0xf0;
//LCD_en_write();
}
void main()
{
init_port();
LCD_init();
//INT_init();
//timer1_init();
//LCD_write_string(0,0,dis1);
//LCD_write_string(0,1,dis2);
//forward();
while(1);
//{
// LCD_write_char(3,1,bai1);
// LCD_write_char(4,1,shi1);
// LCD_write_char(5,1,ge1);
// LCD_write_char(9,1,bai2);
// LCD_write_char(10,1,shi2);
// LCD_write_char(11,1,ge2);
// delay_nms(200);
//}
}
void init_port()
{
DDRB = 0xff;
PORTB = 0xff;
LCD_RS_DDR |= LCD_RS;
LCD_RW_DDR |= LCD_RW;
LCD_EN_DDR |= LCD_EN;
LCD_DATA_DDR |= LCD_DATA;
}
void LCD_init()
{
LCD_write_command(0x28);
//LCD_en_write();
//delay_nus(50);
//LCD_write_command(0x28);
//LCD_write_command(0x0c);
//LCD_write_command(0x01);
//delay_nms(5);
}
void LCD_write_command(uchar command)
{
delay_nus(20);
LCD_RS_PORT &= ~LCD_RS;
LCD_RW_PORT &= ~LCD_RW;
//LCD_DATA_PORT &= 0x0f;
//LCD_DATA_PORT |= command&0xf0;
//LCD_en_write();
//command = command<<4;
//LCD_DATA_PORT &= 0x0f;
//LCD_DATA_PORT |= command&0xf0;
//LCD_en_write();
}
void main()
{
init_port();
LCD_init();
//INT_init();
//timer1_init();
//LCD_write_string(0,0,dis1);
//LCD_write_string(0,1,dis2);
//forward();
while(1);
//{
// LCD_write_char(3,1,bai1);
// LCD_write_char(4,1,shi1);
// LCD_write_char(5,1,ge1);
// LCD_write_char(9,1,bai2);
// LCD_write_char(10,1,shi2);
// LCD_write_char(11,1,ge2);
// delay_nms(200);
//}
}