Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

how can i develop a programme which control lcd?

I want to develop a programme to control the lcd,but i don not know how to start. who can help me?

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello blackslave,

    Do you mean a standard LCD (like 20x2)? If yes you can take the provided software examples which are included in the Nios package. Which Nios are you using?

    Bye,

    niosIIuser
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    First,thank you for your reply.I sorry for that i have not made it clear that i use the linux which provide by the coporation of Microtronix to develop programme for the nios2. My board is cyclone,and the lcd is 16207. Now i want to develop a programme to control the lcd,need i write a devie driver for the lcd? If not,what should i do?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I've been busy with other software and haven't got back to playing with Nios II yet. When I was playing with Nios II, I was using uClinux and my main interest was in writing a device driver for a simple device. I built a very basic hello world device driver as a module and was able to insmod it into memory - my biggest hurdle was figuring out how to get the module to build, I wrote a thread which contained some instructions on how to build a module for a Nios II uClinux kernel. It's this thread here (http://www.niosforum.com/forum/index.php?act=st&f=17&t=93).

    Once you've got a module that you can insmod it should be pretty straightforward to customize it for your lcd, a good starting point would be to look at the device driver for the buttons that exists in the drivers section of the kernel source - you'll also need a skeleton 2.6 module driver to put your code in, but there's only a few lines of code required for a basic driver so you should be able to find one very easily.

    Adrian
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I think the Nios II includes a driver for the 16207 LCD (the included one). If you include the "Character LCD (16x2, Optrex 16207)" component in SOPC Builder (it is under 'Display') the driver should automatically get built into your system, and you just need to read the source and/or documentation to find out how to use the driver in your software. Even if the driver isn't included, there is definitely one in the Nios I SDK, so you could adapt that into a kernel module.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It's, literally, as simple as....

    FILE *lcd = fopen( "/dev/lcd_display", "w" );

    fprintf( lcd, "Your message here....with formatting %s", some_string );

    That being said, there are multiple examples of this in the software templates that are included with the kit.

    Good luck,

    slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i have tried a lot to find the 16*2 lcd driver in the core of uclinux (in the menuconfig).

    but until now i can't find such a option.

    if somebody knows how to add it to the core ,can you help me?

    and i also tried to write a driver of it, but it didnt word well.

    i'd like to share it to you , and i hope anybody can point what the problem is in the file.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    #include <linux/module.h># include <linux/errno.h># include <linux/cdev.h># include <linux/config.h># include <linux/types.h># include <linux/errno.h># include <linux/miscdevice.h># include <linux/slab.h># include <linux/ioport.h># include <linux/fcntl.h># include <linux/mc146818rtc.h># include <linux/netdevice.h># include <linux/sched.h># include <linux/delay.h>

    # include <asm/io.h># include <asm/uaccess.h># include <asm/system.h># include <linux/delay.h>

    # define LCD_On 1# define LCD_Off 2# define LCD_Clear 3# define LCD_Reset 4# define LCD_Cursor_Left 5# define LCD_Cursor_Right 6# define LCD_Disp_Left 7# define LCD_Disp_Right 8# define LCD_Get_Cursor 9# define LCD_Set_Cursor 10# define LCD_Home 11# define LCD_Read 12# define LCD_Write 13# define LCD_Cursor_Off 14# define LCD_Cursor_On 15# define LCD_Get_Cursor_Pos 16# define LCD_Set_Cursor_Pos 17# define LCD_Blink_Off 18

    # define kLCD_IR na_led_green# define kLCD_DR (na_led_green + 8)

    # define LCDWriteData(x) outl(x , kLCD_DR)# define LCDWriteInst(x) outl(x , kLCD_IR)

    # define LCDReadData inl(kLCD_DR)# define LCDReadInst inl(kLCD_IR)

    # define Major 250

    static int Device_Open = 0;

    static int lcd_16207_ioctl(struct inode *inode,struct file *filp,

    unsigned int cmd,unsigned long arg);

    static int lcd_16207_open(struct inode *inode,struct file *filp)

    {

    static int counter = 0;

    if(Device_Open)return -EBUSY;

    Device_Open++;

    printk("You have open the device %d times\n",counter++);

    return 0;

    }

    static int lcd_16207_release(struct inode *inode,struct file *filp)

    {

    Device_Open--;

    printk("You have release the device\n");

    return 0;

    }

    static int lcd_16207_ioctl(struct inode *inode,struct file *filp,

    unsigned int cmd,unsigned long arg)

    {

    volatile unsigned long display;

    switch (cmd) {

    case LCD_On:

    if (copy_from_user

    (&display, (unsigned long *) arg,

    sizeof(display)))

    return -EFAULT;

    LCDWriteInst(display);

    break;

    case LCD_Off:

    if (copy_from_user

    (&display, (unsigned long *) arg,

    sizeof(display)))

    return -EFAULT;

    LCDWriteData(display);

    break;

    default:

    return -EINVAL;

    }

    return 0;

    }

    static struct file_operations lcd_16207_fops={

    .ioctl = lcd_16207_ioctl,

    .open = lcd_16207_open,

    .release = lcd_16207_release,

    };

    static int lcd_16207_init(void)

    {

    int ret = register_chrdev(Major,"LCD_PIO",&lcd_16207_fops);

    if(ret<0)

    {

    printk("Registering the device failed with %d\n",Major);

    return Major;

    }

    printk("You have init Device %d\n",Major);

    return 0;

    }

    static void lcd_16207_exit(void)

    {

    if(unregister_chrdev(Major,"LCD_PIO"))

    printk("exit failed");

    }

    module_init(lcd_16207_init);

    module_exit(lcd_16207_exit);

    MODULE_AUTHOR("Andrew Bose");

    MODULE_LICENSE("GPL");