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 .
So it would make sense to check whether you're actually executing SysTick_Handler.
//LCD.c void lcd_delay(int msec) { volatile uint32_t done = msTicks + msec; while (msTicks != done) ; } //LCD.h volatile uint32_t msTicks; //... //VTABLE.c void SysTick_Handler(void) { msTicks++; }
All these variables are declared.
Yes, but as I asked:
Have you forgotten to make msTicks volatile?
If you don't, then it's unlikely to work with an optimizing compiler.
All these variables are declared. As said above , I am studying the systicks , delay ... Below is the code of main.c. Operating at 72Mhz.
Grateful.
#include <stdio.h> #include <stdint.h> #include "../cmsis/device/lpc134x.h" #include "../core/gpio/gpio.h" int main(void) { SystemCoreClockUpdate(); // 72Mhz SysTick_Config(SystemCoreClock / 100); // 1 = 1us / 10 = 1ms / 100 = 10ms / 1000 = 100ms gpioSetDir(GPIO_GPIO1_BASE, GPIO_PIN3, gpioDirection_Output); while (1) { gpioSetValue(GPIO_GPIO1_BASE, GPIO_PIN3, GPIO_PIN3); systickDelay(10000); gpioSetValue(GPIO_GPIO1_BASE, GPIO_PIN3, 0x00); systickDelay(10000); } }
Have you forgotten to make msTicks volatile? Making done volatile is not necessary because it doesn't get changed elsewhere.
I believe that this is the problem. On and off the pins have learned and fix what was wrong . But I have questions about this delay . If I leave without "return" it is locked as in an infinite loop and does not pursue the code. I also noticed that the variable msticks does not increase . How come?
///LCD.c void lcd_delay(int msec) { volatile uint32_t done = msTicks + msec; while (msTicks != done) ; } ///VTABLE.c void SysTick_Handler(void) { msTicks++; }
Right. So get down to learning how to set & clear its pins with defined timing...
Sorry personal now that I realized . But I am using LPC1343 . Sorry, sorry . It was bad.
6-Jan-2015 18:59 GMT: "I am trying to use a LCD 20x4 ( 4 bits ) with a lm3s328"
9-Jan-2015 09:29 GMT: "I am using an LPC1343"
So what chip are you really using??
Again, leave the LCD part alone until you mastered driving the point pins with specific timing.
Learn to walk before trying to run.
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.
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?
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 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 .
Yes, but isn't it confusing if you have source code that makes use of a constant named "IO1DIR" which seems to imply port 1. But you have a #define that translates IO1DIR into GPIO_GPIO2DIR which seems to be port 2? Wouldn't you be extremely confused if an assign to port 1 actually changes the state of port 2?
Wouldn't you be confused if you indicate blinkers left on your car and the indication inside the car indicates left but the lamps on the outside instead indicates right?
The time/cost of maintainance of source code very much depends on how easy it is to read and understand. So the code should "speak" to the developer. And it most definitely shouldn't lie, because it will come back and haunt you.
I know that simply means IO1DIR IO = Input / Output 1 = Port Identifier DIR = port the operating direction ( input, output ) . Sorry if I'm learning to confuse a month and your help was important. I'm sure the question pin R / W lcd . I realized that he is on a pin , but he is in the right GND ? I've done some lcd connections in Proteus and it was so.
View all questions in Keil forum