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 .
I'm sure the question pin R / W LCD . I Realized que he is on a pin , but he is in the right GND ? I've done some lcd connections in Proteus and it was so . Got it , thanks for the tip .
Jonatan souza. it seems that your code is changed and is different from what was on my mind.use these codes.
#ifndef __PORTLCD_H #define __PORTLCD_H #define USE_FIO 1 #if USE_FIO #define IODIR_LCD FIO0DIR #define IOSET_LCD FIO0SET #define IOCLR_LCD FIO0CLR #define IOPIN_LCD FIO0PIN #else #define IODIR_LCD IODIR0 #define IOSET_LCD IOSET0 #define IOCLR_LCD IOCLR0 #define IOPIN_LCD IOPIN0 #endif /* LCD IO definitions */ #define LCD_E ( 1 << 26 ) /* Enable control pin */ #define LCD_RW ( 1 << 25 ) /* Read/Write control pin */ #define LCD_RS ( 1 << 24 ) /* Data/Instruction control */ #define LCD_CTRL ( LCD_E | LCD_RW | LCD_RS ) /* Control lines mask */ #define LCD_DATA ( 0x0f << 27 ) #define LCD_DATA_START 27 /* Data lines mask */ extern void LCD_init(void); extern void delay (DWORD cnt) ; extern void LCD_load(BYTE *fp, DWORD cnt); extern void LCD_gotoxy(DWORD x, DWORD y); extern void LCD_cls(void); extern void LCD_cur_off(void); extern void LCD_on(void); extern void LCD_putc(BYTE c); extern void LCD_puts(BYTE *sp); extern void LCD_bargraph(DWORD val, DWORD size); extern void LCD_cur_blink( void ); #endif /* end __PORTLCD_H */
you should just change the Port number and pins according to your project. and Source code for 20 character length LCDs.
/****************************************************************************** void LCD_init( void ) { /* Initialize the ST7066 LCD controller to 4-bit mode. */ #if USE_FIO SCS |= 0x00000001; /* set GPIOx to use Fast I/O */ #endif IODIR_LCD |= LCD_CTRL | LCD_DATA; IOCLR_LCD = LCD_RW | LCD_RS | LCD_DATA; lcd_write_4bit(0x3); /* Select 4-bit interface */ delay (10); lcd_write_4bit(0x3); delay (10); lcd_write_4bit(0x3); lcd_write_4bit(0x2); lcd_write_cmd(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; } /****************************************************************************** void LCD_gotoxy( DWORD x, DWORD y ) { /* Set cursor position on LCD display. Left corner: 1,1, right: 16,2 */ DWORD c; c = x; if (y) { c |= 0x40; } lcd_write_cmd (c | 0x80); lcd_ptr = y*20 + x; return; } /****************************************************************************** void LCD_putc( BYTE c ) { /* Print a character to LCD at current cursor position. */ if (lcd_ptr == 20) { lcd_write_cmd (0xc0); } lcd_write_data(c); lcd_ptr++; return; } /***************************************************************************** ** End Of File ******************************************************************************/
I'm using the same code , but I'm getting messages such as: "Controller received command whilst busy" and then another " Attempted to read controller date whilst busy" . What is it?
proteus is not a reliable simulator.test your code on a real hardware. I used this module in some of my projects and is working well. try more.