发表于:2014/11/2 10:05:28
#0楼
各位高手,小弟正在基于AVR单片机开发一款智能小车,遇到“LCD无法显示速度数据”,调试了一下,屏蔽了大部分代码保留了对LCD操作的代码,当执行到“LCD_RS_PORT&=~LCD_RS;”这一句时,测量了RS管脚的电平,发现RS管脚电平并未拉低,仍然为高电平。请教其中的原因。谢谢。部分代码如下:
void LCD_init(void)
{
LCD_DATA_DDR|=LCD_DATA;
LCD_EN_DDR|=LCD_EN;
LCD_RS_DDR|=LCD_RS;
LCD_RW_DDR|=LCD_RW;
LCD_RW_PORT&=~LCD_RW; //RW=0
LCD_write_command(0x28);
#if 0
LCD_en_write();
delay_nus(40);
LCD_write_command(0x28);
LCD_write_command(0x0c);
LCD_write_command(0x01);
delay_nms(2);
#endif
}
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
LCD_init();
time1_init();
time2_init();
INT_init();
TIMSK |= BIT(2);
TIMSK |= BIT(0);
TIMSK |= BIT(6);
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
int counter = 0;
int i;
int stop_count = 0;
//MCUCSR &= ~BIT(4);
MCUCSR |= BIT(7);
MCUCSR |= BIT(7);
//vInitEeprom();
uart0_init();
init_devices();
//EECR |= BIT(EERIE);
DUTY1=50;
DUTY2=50;
addr = 1;
while (1)
{
delay_ms (10);
}
}
void LCD_init(void)
{
LCD_DATA_DDR|=LCD_DATA;
LCD_EN_DDR|=LCD_EN;
LCD_RS_DDR|=LCD_RS;
LCD_RW_DDR|=LCD_RW;
LCD_RW_PORT&=~LCD_RW; //RW=0
LCD_write_command(0x28);
#if 0
LCD_en_write();
delay_nus(40);
LCD_write_command(0x28);
LCD_write_command(0x0c);
LCD_write_command(0x01);
delay_nms(2);
#endif
}
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
LCD_init();
time1_init();
time2_init();
INT_init();
TIMSK |= BIT(2);
TIMSK |= BIT(0);
TIMSK |= BIT(6);
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
int counter = 0;
int i;
int stop_count = 0;
//MCUCSR &= ~BIT(4);
MCUCSR |= BIT(7);
MCUCSR |= BIT(7);
//vInitEeprom();
uart0_init();
init_devices();
//EECR |= BIT(EERIE);
DUTY1=50;
DUTY2=50;
addr = 1;
while (1)
{
delay_ms (10);
}
}
10分悬赏