这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » LPC938控制1602液晶显示的问题???

共3条 1/1 1 跳转至

LPC938控制1602液晶显示的问题???

菜鸟
2012-05-08 23:57:12     打赏
各位好!我现在用LPC938单片机控制1602液晶显示,但为什么显示不出来,问一下,IO配置为推挽输出还是准双向口?演示用多大?代码如下,哪位大神解释下: #include #include sbit rs=P1^1; sbit rw=P2^6; sbit e=P2^7; sbit led=P1^0; #define dataport P0 void delay_us(unsigned int t) //延时(t*2+5) us { t *= 6; while(--t); } void delay_ms(unsigned int t) //延时t ms { while(t--) { delay_us(245); delay_us(245); } } void LPC938_Init(void) { //CLK_RESET_Init(); // UCFG1=0x40; //禁止看门狗复位、禁止掉电检测、使能P1.5复位,使用外部高频晶振12MHz DIVM=0x00; //外部晶振作为CPU时钟,不分频 //IO_Init(); P0M1=0x00; P0M2=0xff; P1M1=0x2c; //P15(RST)、P12(SCL/T0)、P13(SDA/INT0)配置为输入,其他的均为准双向口 P1M2=0xd3; P2M1=0x00; P2M2=0xff; } void lcd_write_com(unsigned char com) { // while(lcd_check_busy()); //忙则等待 rs=0; rw=0; e=1; dataport=com; _nop_(); e=0; } void lcd_write_data(unsigned char dat) { // while(lcd_check_busy()); //忙则等待 rs=1; rw=0; e=1; dataport=dat; _nop_(); e=0; } void lcd_clear(void) { lcd_write_com(0x01); delay_ms(5); } void lcd_write_char(unsigned char x,unsigned char y,unsigned char dat) { if (y==0) { lcd_write_com(0x80+x); } else { lcd_write_com(0xC0+x); } lcd_write_data(dat); } void lcd_write_string(unsigned char x,unsigned char y,unsigned char *s) { while(*s) { lcd_write_char(x,y,*s); s++;x++; } } void lcd_init(void) { lcd_write_com(0x38); /*显示模式设置*/ delay_ms(5); lcd_write_com(0x38); delay_ms(5); lcd_write_com(0x38); delay_ms(5); lcd_write_com(0x38); lcd_write_com(0x08); /*显示关闭*/ lcd_write_com(0x01); /*显示清屏*/ lcd_write_com(0x06); /*显示光标移动设置*/ delay_ms(5); lcd_write_com(0x0C); /*显示开及光标设置*/ } main() { LPC938_Init(); lcd_init(); lcd_clear(); lcd_write_string(0,1,"lcd1602"); delay_ms(500); while(1) { led =~ led; delay_ms(500); } } 下载时时钟配置为:高频外部晶振12MHz,使能P1^5,那位有用过的代码让我参考下!!!谢谢啦!!!



关键词: LPC938     控制     液晶显示     问题     delay     u    

菜鸟
2012-05-17 10:46:13     打赏
2楼
#include #define uchar unsigned char #define uint unsigned int sbit rs=P3^5; sbit lcden=P3^4; sbit dula=P2^6; sbit wela=P2^7; uchar table1[]="TX-1B MCU"; uchar table2[]="www.mcuhx.com"; void delay(uint x) { uint a,b; for(a=x;a0;a--) for(b=10;b0;b--); } void delay1(uint x) { uint a,b; for(a=x;a0;a--) for(b=100;b0;b--); } void write_com(uchar com) { P0=com; rs=0; lcden=0; delay(10); lcden=1; delay(10); lcden=0; } void write_date(uchar date) { P0=date; rs=1; lcden=0; delay(10); lcden=1; delay(10); lcden=0; } void init() { dula=0; wela=0; write_com(0x38); delay(20); write_com(0x0f); delay(20); write_com(0x06); delay(20); write_com(0x01); delay(20); } 字数超了

菜鸟
2012-05-17 10:48:27     打赏
3楼
void init() { dula=0; wela=0; write_com(0x38); delay(20); write_com(0x0f); delay(20); write_com(0x06); delay(20); write_com(0x01); delay(20); } void main() { uchar a; init(); write_com(0x80+19); delay(20); for(a=0;a 不知道为什么贴不上去,网上很多的,自己找找吧。

共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]