hello everyone I am trying to use a LCD 20x4 ( 4 bits ) with a lm3s328 , but have not found a proper lib , can someone give me a hand . Thank you .
Never write code that lies to the reader.
A person who reads IO1DIR assumes that he knows the meaning of IO1DIR. It clearly indicates something happening to port 1 - while you try to remap to port 2. Bad, bad, bad, bad!
Consider something like:
#define LCD_RS (1u << 28) #define LCD_RW (1u << 29) ... #define LCD_SET_OUTPUT(bits) (GPIO_GPIO2DIR |= (bits)) #define LCD_SET(bits) (GPIO_GPIO2DATA |= (bits)) #define LCD_CLR(bits) (GPIO_GPIO2DATA &= ~(bits)) ...
and then:
LCD_SET_OUTPUT(LCD_RS|LCD_RW|...); LCD_SET(LCD_RS); LCD_CLR(LCD_RW); ...
OK. My question is in setting the ports . For I am using an LPC1343 and examples are for LPC series 2000. I'm trying mater the maximum of origial code , so the " #define 's"
//THE PORTLCD.C #include <../cmsis/device/lpc134x.h> #include "portlcd.h" #define USE_FIO 3 #if USE_FIO == 1 #define IO1DIR FIO1DIR #define IO1SET FIO1SET #define IO1CLR FIO1CLR #define IO1PIN FIO1PIN #elif USE_FIO == 2 #define IO1DIR IODIR1 #define IO1SET IOSET1 #define IO1CLR IOCLR1 #define IO1PIN IOPIN1 #elif USE_FIO == 3 #define IO1DIR GPIO_GPIO2DIR #define IO1SET GPIO_GPIO2DATA #define IO1CLR GPIO_GPIO2DATA #define IO1PIN GPIO_PIN0 #endif /* Please note, on old MCB2300 board, the LCD_E bit is p1.30, on the new board it's p1.31, please check the schematic carefully, and change LCD_CTRL and LCD_E accordingly if you have a different board. */ /* LCD IO definitions */ #define LCD_E GPIO_PIN0 // 0x80000000 /* Enable control pin */ #define LCD_RW GPIO_PIN1 // 0x20000000 /* Read/Write control pin */ #define LCD_RS GPIO_PIN2 // 0x10000000 /* Data/Instruction control */ #define LCD_CTRL GPIO_PIN3 // 0xB0000000 /* Control lines mask */ #define LCD_DATA GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7// 0x0F000000 /* Data lines mask void LCD_init(void) { /* Initialize the ST7066 LCD controller to 4-bit mode. */ //PINSEL3 = 0x00000000; #if USE_FIO == 1 SCS |= 0x00000001; /* set GPIOx to use Fast I/O */ #endif IO1DIR |= LCD_CTRL | LCD_DATA; IO1CLR = !LCD_RW | !LCD_RS | !LCD_DATA; lcd_write_4bit(0x3); /* Select 4-bit interface */ LCD_delay(100000); lcd_write_4bit(0x3); LCD_delay(10000); lcd_write_4bit(0x3); lcd_write_4bit(0x2); lcd_write_cmd(0x28); /*0x28 2 lines, 5x8 character matrix */ lcd_write_cmd(0x0e); /* Display ctrl:Disp/Curs/Blnk=ON */ lcd_write_cmd(0x06); /* Entry mode: Move right, no shift */ LCD_load((BYTE *) &UserFont, sizeof(UserFont)); LCD_cls(); return; } ///THE MAIN.C #include "../cmsis/device/lpc134x.h" #include "../drivers/displays/lcd20x4/portlcd.h" int main(void) { gpioInit(); LCD_init(); LCD_cls(); LCD_gotoxy(1,1); LCD_putc("Test"); for (;;) { } }
What "help" do you need?
What have you tried?
Where are you stuck?
Remember that the LCD neither knows nor cares what chip you use - you just have to follow the correct protocol and the correct timing.
The only things that will be specific to the particular chip are the control of the port pins, and getting the timing right...
Do you can help-me in this implementations? Tanks!
There are sample codes for lpc devices in order to drive a character lcd ( 4 bit ). search portlcd.c and portlcd.h on web.they are initiated especially for 16*2 lcds. you must make some changes in initialize function to adapt it with a 20*4 one.
View all questions in Keil forum