Forum Discussion
What's wrong with my programm?
I have write a programme to initialize the lcd16207,but it couldn't work correctly. The code is:# include <unistd.h># include <stdlib.h># include <stdio.h>
//#include "lcd_16207.h" /* Commands which can be written to the COMMAND register */ enum /* Write to character RAM */ { LCD_CMD_WRITE_DATA = 0x80 /* Bits 6:0 hold character RAM address */ }; enum /* Write to character generator RAM */ { LCD_CMD_WRITE_CGR = 0x40 /* Bits 5:0 hold character generator RAM address */ }; enum /* Function Set command */ { LCD_CMD_FUNCTION_SET = 0x20, LCD_CMD_8BIT = 0x10, LCD_CMD_TWO_LINE = 0x08, LCD_CMD_BIGFONT = 0x04 }; enum /* Shift command */ { LCD_CMD_SHIFT = 0x10, LCD_CMD_SHIFT_DISPLAY = 0x08, LCD_CMD_SHIFT_RIGHT = 0x04 }; enum /* On/Off command */ { LCD_CMD_ONOFF = 0x08, LCD_CMD_ENABLE_DISP = 0x04, LCD_CMD_ENABLE_CURSOR = 0x02, LCD_CMD_ENABLE_BLINK = 0x01 }; enum /* Entry Mode command */ { LCD_CMD_MODES = 0x04, LCD_CMD_MODE_INC = 0x02, LCD_CMD_MODE_SHIFT = 0x01 }; enum /* Home command */ { LCD_CMD_HOME = 0x02 }; enum /* Clear command */ { LCD_CMD_CLEAR = 0x01 };# define na_lcd_pio_command ((volatile int *) 0x80920850)# define na_lcd_pio_status ((volatile int *) 0x80920851)# define na_lcd_pio_wr_data ((volatile int *) 0x80920852)# define na_lcd_pio_rd_data ((volatile int *) 0x80920853) # define PIO_LCD_IO_COMMAND (*na_lcd_pio_command)# define PIO_LCD_IO_STATUS (*na_lcd_pio_status)# define PIO_LCD_IO_WR_DATA (*na_lcd_pio_wr_data)# define PIO_LCD_IO_RD_DATA (*na_lcd_pio_rd_data) void delay(int para)//delay for 0.2*para ms { int i=0,j=0; for(i=0;i<para;i++) for(j=0;j<10000;j++) } int main() { delay(75); PIO_LCD_IO_COMMAND=LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT; delay(21); PIO_LCD_IO_COMMAND=LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT; delay(1); PIO_LCD_IO_COMMAND=LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT; PIO_LCD_IO_COMMAND=LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT | LCD_CMD_TWO_LINE; PIO_LCD_IO_COMMAND=LCD_CMD_ONOFF; PIO_LCD_IO_COMMAND=LCD_CMD_CLEAR; PIO_LCD_IO_COMMAND=LCD_CMD_MODES | LCD_CMD_MODE_INC; PIO_LCD_IO_COMMAND=LCD_CMD_ONOFF | LCD_CMD_ENABLE_DISP; delay(1000); return 0; } My operation system is uClinux,and the board is cyclone,what's wrong with me? help!15 Replies
- Altera_Forum
Honored Contributor
<div class='quotetop'>QUOTE </div>
--- Quote Start --- PIO_LCD_IO_COMMAND=LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT; PIO_LCD_IO_COMMAND=LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT | LCD_CMD_TWO_LINE; PIO_LCD_IO_COMMAND=LCD_CMD_ONOFF; PIO_LCD_IO_COMMAND=LCD_CMD_CLEAR; PIO_LCD_IO_COMMAND=LCD_CMD_MODES | LCD_CMD_MODE_INC; PIO_LCD_IO_COMMAND=LCD_CMD_ONOFF | LCD_CMD_ENABLE_DISP;[/b] --- Quote End --- There's no delays here, presumably these commands will be far too quick for the LCD. Have you traced through the code? Strictly speaking you sh9uldn't be writing directly to a device from userland, but a lack of MMU on nios shouldn't prevent this from happening. What exactly "not works", have you looked at the signals under a scope? Adrian - Altera_Forum
Honored Contributor
I'm a pretty bad programmer, but if you have data cache, I don't think you're writes will be working (volatile doesn't mean the same thing it did in NIOS I). Use the IOWR, IORD to bypass the cache so you're data goes out (or use the HAL stuff if you know how to use it)
Volatile in NIOS II just means it doesn't optimize out the variable. This is why you can't directly upgrade from NIOS I to NIOS II/f (because the compiler wouldn't understand what's suppose to use cache and what is not to use it). One way to check if this is turn is to check to see if the very first write to it worked and nothing else did (nothing else would go to it because it's in cache and therefor not updated) Cheers - Altera_Forum
Honored Contributor
Thanks for all the replies,I have added a delay,and the problem resloved.That is to say the lcd16207 could be initialized. But i am so stupid and i can not understand how to control the lcd to make it display a character .I have seen the lcd16207's datasheet,and i don't know how to use the DD RAM,CG RAM.
Wait for your reply! - Altera_Forum
Honored Contributor
If you can't display characters then how do you know it's working?
- Altera_Forum
Honored Contributor
oh,h..h,I find that the screen has been cleared after executing the init() function,so i think that the lcd16207 should be working, right or wrong? Waiting for your reply.
- Altera_Forum
Honored Contributor
This is the LCD that comes with the development boards right? If so I think you should probably just use the HAL stuff because it sounds like it'll be much easier that way.
- Altera_Forum
Honored Contributor
In the nios1 kit there was a file named lcd_demo1.c
Maybe you could use that to run on the lcd? If you don't have it email me and I'll send it to you. I have never used it with nios II, but with minor mods or no mods it should work. - Altera_Forum
Honored Contributor
Why are you bothering with initialization?
With Nios II (and the HAL), you should be able to open the device and use fprintf to print to it, like so: char *your_msg = "All work and No play..."; /* Get a file handle */ /* NOTE: Your name will match the name you chose from SOPC Builder... the example, below, matches the name in the standard and full_featured designs*/ FILE *lcd = fopen( "/dev/lcd_display", "w"); /* Using the lcd file handle, "print" to the LCD Device */ fprintf(lcd, "%s\n", your_msg); The syntax may not be *exactly* like this, but this is what I recall from several of the software "templates". For some reason Count Binary comes to mind.... Cheers, - slacker - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by slacker@Aug 12 2004, 01:26 PM why are you bothering with initialization?with nios ii (and the hal), you should be able to open the device and use fprintf to print to it, like so:
char *your_msg = "all work and no play...";
/* get a file handle */
/* note: your name will match the name you chose from sopc builder... the example, below, matches the name in the standard and full_featured designs*/
file *lcd = fopen( "/dev/lcd_display", "w");
/* using the lcd file handle, "print" to the lcd device */
fprintf(lcd, "%s\n", your_msg);
the syntax may not be *exactly* like this, but this is what i recall from several of the software "templates". for some reason count binary comes to mind....
cheers,
- slacker --- Quote End --- he's trying to use ucLinux, not HAL. It sounds like he's now got it initialising under ucLinux, so it should be a matter of reading the datasheet now..... Adrian
- Altera_Forum
Honored Contributor
What's involved in the initialization process? (not sure what part of you're code is doing that, I'm not very good with anything ending in "nix" so the syntax is quite different then what I'm used to).
Also what core are you using?