Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.
We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.
Thank you for your understanding.
hi, guys I have a doubt regarding interfacing lcd to arm7. I have an lpc2148 development board. This board did have a lcd interfacing example. I also have another program I got from internet. I see that the function to initialize the lcd are written in different ways in both the examples. In the example I got with the board the "void lcd_init()" is little complex. But the other example I got from internet the has "void init_lcd( void )" written in a simple way. I have edited and tried the codes in different ways and I see only the code I received with the board works. I am new to ARM, but I don't think this should be correct, we should be able to make new codes. Hoping someone can understand my doubt.
CODE THAT CAME WITH THE DEVELOPMENT BOARD
#include <LPC214x.H> #define LCD_RS (1<<10) #define LCD_RW (1<<12) #define LCD_EN (1<<13) #define LCD_D4 (1<<20) #define LCD_D5 (1<<21) #define LCD_D6 (1<<22) #define LCD_D7 (1<<23) #define LCD_DATA_MASK (LCD_D7|LCD_D6|LCD_D5|LCD_D4) #define LCD_IOALL_MASK (LCD_D7|LCD_D6|LCD_D5|LCD_D4|LCD_RS|LCD_EN|LCD_RW) //*************************** void enable_lcd(void) { unsigned int i; IOSET0 = LCD_EN; for (i=0;i<400000;i++); IOCLR0 = LCD_EN; } //************************** void lcd_init() { unsigned int i; PINSEL1 = 0x00000000; IODIR0 |= LCD_IOALL_MASK; for (i=0;i<1000;i++); IOCLR0 = (LCD_IOALL_MASK); IOSET0 = (LCD_D5|LCD_D4); enable_lcd(); for (i=0;i<100;i++); IOCLR0 = (LCD_IOALL_MASK); IOSET0 = (LCD_D5|LCD_D4); enable_lcd(); for (i=0;i<100;i++); IOCLR0 = (LCD_IOALL_MASK); IOSET0 = (LCD_D5|LCD_D4); enable_lcd(); delay(10000); while(busy_lcd()); IOCLR0 = (LCD_IOALL_MASK); IOSET0 = (LCD_D5); enable_lcd(); delay(10000); while(busy_lcd()); lcd_write_control(0x28); lcd_write_control(0x0C); lcd_write_control(0x06); lcd_write_control(0x01); lcd_write_control(0x0F); lcd_write_control(0x01); for (i=0;i<100000;i++); } //***************************** char busy_lcd(void) { unsigned long busy_status; unsigned int i; IODIR0 &= LCD_DATA_MASK; IOCLR0 = LCD_RS; IOSET0 = LCD_RW; IOSET0 = LCD_EN; for (i=0;i<1000;i++); busy_status = (IOPIN1 & 0x80000000); if(busy_status == 0x80000000) { IOCLR0 = LCD_EN; IOCLR0 = LCD_RW; IODIR0 |= LCD_IOALL_MASK; return 1; } else { IOCLR0 = LCD_EN; IOCLR0 = LCD_RW; IODIR0 |= LCD_IOALL_MASK; return 0; } } //****************************** void lcd_out_data4(unsigned char val) { IOCLR0 = (LCD_DATA_MASK); IOSET0 = (val<<20); } //********************************** void lcd_write_byte(unsigned char val) { lcd_out_data4((val>>4)&0x0F); enable_lcd(); lcd_out_data4(val&0x0F); enable_lcd(); delay(100000); // while(busy_lcd()); } //********************************** void lcd_write_control(unsigned char val) { IOCLR0 = LCD_RS; lcd_write_byte(val); } //********************************** void lcd_write_ascii(unsigned char c) { IOSET0 = LCD_RS; lcd_write_byte(c); } //******************************** void goto_cursor(unsigned char i) { i |= 0x80; lcd_write_control(i); } //******************************* void lcd_print(unsigned char* str) { int i; for (i=0;i<16 && str[i]!=0;i++) { lcd_write_ascii(str[i]); } } //****************************** void delay(unsigned long int count1) { while(count1 > 0) {count1--;} }
I will copy the other code in the below thread
Sorry the second code didn't come properly. Let me post it again THE OTHER EXAMPLE here i see the initialization of the lcd is done in a very simple way
#include <LPC214x.H> #include "lcd.h" #define LCD_DATA_DIR IO0DIR #define LCD_DATA_SET IO0SET #define LCD_DATA_CLR IO0CLR #define LCD_CTRL_DIR IO0DIR #define LCD_CTRL_SET IO0SET #define LCD_CTRL_CLR IO0CLR #define LCDRS (1 << 10) #define LCDRW (1 << 12) #define LCDEN (1 << 13) #define LCD_D4 (1 << 20) #define LCD_D5 (1 << 21) #define LCD_D6 (1 << 22) #define LCD_D7 (1 << 23) #define LCD_DATA_MASK (LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7) #define LCD_BUSY_FLAG LCD_D7 //****************************************************** void delay(int count) { int j=0,i=0; for(j=0;j<count;j++) { for(i=0;i<35;i++); } } //****************************** void wait_lcd( void ) { LCD_CTRL_CLR |= LCDRS; LCD_CTRL_SET |= LCDRW |LCDEN; while(IO0PIN & LCD_BUSY_FLAG); LCD_CTRL_CLR |= LCDEN | LCDRW; LCD_DATA_DIR |= LCD_DATA_MASK; delay(100); } //****************************** void lcd_command_write( unsigned char command ) { unsigned char temp=0; unsigned int temp1=0; temp=command; temp=(temp>>4)&0x0F; temp1=(temp<<20)&LCD_DATA_MASK; LCD_CTRL_CLR = LCDRS; LCD_CTRL_SET = LCDEN; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; delay(10000); LCD_CTRL_CLR = LCDEN; temp=command; temp&=0x0F; temp1=(temp<<20)&LCD_DATA_MASK; delay(100*2); LCD_CTRL_CLR |= LCDRS; LCD_CTRL_SET |= LCDEN; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; delay(10000); LCD_CTRL_CLR |= LCDEN; wait_lcd(); } //****************************** void set_lcd_port_output( void ) { LCD_CTRL_DIR |= ( LCDEN | LCDRS | LCDRW ); LCD_CTRL_CLR |= ( LCDEN | LCDRS | LCDRW ); LCD_DATA_DIR |= LCD_DATA_MASK; } //******************************* void lcd_clear( void) { lcd_command_write( 0x01 ); } //******************************** int lcd_gotoxy( unsigned int x, unsigned int y) { int retval = 0; if( (x > 1) && (y > 15) ) { retval = -1; } else { if( x == 0 ) { lcd_command_write( 0x80 + y ); } else if( x==1 ){ lcd_command_write( 0xC0 + y ); } } return retval; } //****************************** void lcd_data_write( unsigned char data ) { unsigned char temp=0; unsigned int temp1=0; temp=data; temp=(temp>>4)&0x0F; temp1=(temp<<20)&LCD_DATA_MASK; LCD_CTRL_SET |= LCDEN|LCDRS; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; LCD_CTRL_CLR |= LCDEN; temp=data; temp&=0x0F; temp1=(temp<<20)&LCD_DATA_MASK; LCD_CTRL_SET |= LCDEN|LCDRS; LCD_DATA_CLR = LCD_DATA_MASK; LCD_DATA_SET = temp1; LCD_CTRL_CLR |= LCDEN; wait_lcd(); } //******************************* void lcd_putchar( int c ) { lcd_data_write( c ); } //******************************* void lcd_putstring( unsigned char line, char *string ) { unsigned char len = MAX_CHAR_IN_ONE_LINE; lcd_gotoxy( line, 0 ); while(*string != '\0' && len--) { lcd_putchar( *string ); string++; } } //******************************* void lcd_backlight_on() { LCD_BACK_LIGHT_DIR |= LCD_BACKLIGHT; LCD_BACK_LIGHT_SET |= LCD_BACKLIGHT; } //********************************* void turn_off_lcd_back_light_cb(void) { LCD_BACK_LIGHT_DIR |= LCD_BACKLIGHT; LCD_BACK_LIGHT_CLR |= LCD_BACKLIGHT; } //********************************* void init_lcd( void ) { set_lcd_port_output(); delay(100*100); lcd_command_write(0x28); lcd_clear() ; lcd_command_write(0x02); lcd_command_write(0x06); lcd_command_write(0x0C); lcd_gotoxy(0, 0); lcd_clear(); }
I have copied only the lcd file, please let me know, if I need to explain anything
Check the LCD Initialization section in www.ocfreaks.com/.../
Thanks, I will go through the link
Thanks Foster, the link did help me.