我用KEIL写的12864的驱动,控制芯片是LM3S811,初始化都不成功,硬件检查几遍了,没有问题。请大家帮我看看代码有没有问题,感激不尽!代码如下:
#define lcddata_periph SYSCTL_PERIPH_GPIOD #define lcddata_port GPIO_PORTD_BASE
#define lcdcon_periph SYSCTL_PERIPH_GPIOB #define lcdcon_port GPIO_PORTB_BASE
#define lcd_data 0xff #define EN GPIO_PIN_3 #define RW GPIO_PIN_4 #define CS GPIO_PIN_0 #define RS GPIO_PIN_6 #define RST GPIO_PIN_2 以上是借口定义
void check_busy() { uchar read_data=0xff; GPIOPinWrite(lcdcon_port,RS,0x00 ); //clear_rs GPIOPinWrite(lcdcon_port,RW,0xff ); //set_rw GPIOPinWrite(lcdcon_port,CS,0x00 ); //clear_cs GPIOPinTypeIn(lcddata_port, lcd_data); // 设置LCD数据所在管脚为输入 do { GPIOPinWrite(lcdcon_port,EN,0xff ); //set_en LCD_Delay(5); read_data=GPIOPinRead(lcddata_port, lcd_data); LCD_Delay(5); GPIOPinWrite(lcdcon_port,EN,0x00 ); //clear_en }while(read_data&0x80); GPIOPinWrite(lcdcon_port,CS,0xff ); //set_cs GPIOPinTypeOut(lcddata_port, lcd_data); // 设置LCD数据所在管脚为输出
} ////*****************//// ////***写数据函数****//// ////*****************//// void write_data(uchar dat) { check_busy(); GPIOPinWrite(lcdcon_port,RS,0xff ); //set_rs GPIOPinWrite(lcdcon_port,CS,0x00 ); //clear_cs GPIOPinWrite(lcdcon_port,RW,0x00 ); //clear_rw GPIOPinWrite(lcddata_port, lcd_data,dat); LCD_Delay(5); GPIOPinWrite(lcdcon_port,EN,0xff ); //set_en LCD_Delay(5); GPIOPinWrite(lcdcon_port,EN,0x00 ); //clear_en GPIOPinWrite(lcdcon_port,CS,0xff ); //set_cs } ////*****************//// ////****写命令函数***//// ////*****************//// void write_command(uchar command) { check_busy(); GPIOPinWrite(lcdcon_port,RS,0x00 ); //clear_rs GPIOPinWrite(lcdcon_port,RW,0x00 ); //clear_rw GPIOPinWrite(lcdcon_port,CS,0x00 ); //clear_cs GPIOPinWrite(lcddata_port, lcd_data,command); LCD_Delay(5); GPIOPinWrite(lcdcon_port,EN,0xff ); //set_en LCD_Delay(5); GPIOPinWrite(lcdcon_port,EN,0x00 ); //clear_en GPIOPinWrite(lcdcon_port,CS,0xff ); //set_cs } ////*****************//// ////*****复位函数****//// ////*****************//// void reset(void) { GPIOPinWrite(lcdcon_port,RST,0x00); //clear_reset LCD_Delay(200); GPIOPinWrite(lcdcon_port,RST,0xff );//set_reset }
////*****************//// ////***初始化函数****//// ////*****************//// void lcd_initial() { SysCtlPeriEnable(lcddata_periph); // 使能LCD数据所在的GPIO端口 GPIOPinTypeOut(lcddata_port, lcd_data); // 设置LCD数据所在管脚为输出
SysCtlPeriEnable(lcdcon_periph); // 使能LCD控制所在的GPIO端口 GPIOPinTypeOut(lcdcon_port,RS|CS|EN|RW|RST); // 设置LCD控制所在管脚为输出 GPIOPinWrite(lcdcon_port,EN,0x00 ); //clear_en GPIOPinWrite(lcdcon_port,RW,0x00 ); //clear_rw GPIOPinWrite(lcdcon_port,CS,0x00 ); //clear_cs reset();
write_command(0xe2); //复位函数 write_command(0xa2); //液晶背光电压选择 write_command(0xa0); //液晶驱动输出和内部RAM列选择 write_command(0xc0); //控制输出模式选择 write_command(0x24); //液晶背光灯电压设置为总电压的50% write_command(0x81); //液晶背光灯电压设置控制使能 write_command(0x28); //对比度控制,液晶所有控制电压全关 write_command(0x2f); //对比度控制,液晶所有控制电压全开 write_command(0xa6); //现实模式设置(正常) write_command(0xaf); //开显示 write_command(0xa5); //液晶上所有显示点开 LCD_Delay(1000); write_command(0xa4); //液晶正常显示 clear_screen(0); //以清屏 write_command(0x40); //显示起始行设置 write_command(0xb0); //设置起始页 write_command(0x10); //设定列高八位 write_command(0x00); //设定列低八位
}
|