kimiyang 发表于 2009-5-31 23:26:31

使用nios中lcd1602 驱动器 搞定1602

使用sopc里面免费的LCD1602 驱动IP可以直接驱动LCD1602;
    使用标准的输入输出设备 printf()函数可向LCD显示屏打印字符!使用非常简单,但是代码的容量也是比较大的!

值得注意的是,LCD_DATA 是双向口,需要使用bidir类型的管脚, 我就由于疏忽了管脚类型,导致一直调试不出来!


http://www.utou.net/attachments/month_0905/42009531223732.jpg


#include"alt_types.h"
#include <stdio.h>
#include <unistd.h>
#include"system.h"
#include "sys/alt_irq.h"
#include"altera_avalon_pio_regs.h"

#include"priv/alt_busy_sleep.h"



intmain(void)
{   

    int i=0;

      
      FILE *fp_LCD;


    fp_LCD = fopen(LCD_1602_NAME,"w");   // open LCD for write

      if(fp_LCD==0)
      {
      printf("\nError Opening \n\n");
      }
      else
      {   
      
      printf("\nLCD opened, ready for access\n");
      fprintf(fp_LCD,"SOPC-EP1C6\n");
      fprintf(fp_LCD," QQ:520283769\n");
      alt_busy_sleep(2000000);
      fclose(fp_LCD);
      }
      
   
      
    while(1)
    {
            /* 输出LED显示数据 */
            IOWR_AlterA_AVALON_PIO_DATA(LED_PIO_BASE,i++);   
            alt_busy_sleep (1500000);   // 延时150ms
      
    }
   
    return(0);
}



其实 还有一种更简单的方法,直接在设置里面将stdout设置为LCD_1602 即可,这样子 不用涉及到file文件的操作!
http://www.utou.net/attachments/month_0905/r200953123723.jpg


#include <stdio.h>

int main()
{
printf("Hello from Nios II!\n");

return 0;
}


http://www.utou.net/attachments/month_0905/52009531223015.jpg

xyz2008 发表于 2009-6-1 08:39:54

请教楼上,那是什么软件,是不是使用这个软件,可以直接用PC点亮LCD1602

xyz2008 发表于 2009-6-1 08:41:02

在问一句,楼上的板子在那儿买的,是不是STM32的板子

pulan 发表于 2009-6-1 08:43:43

1,2楼,这个板子是altera的fpga,跑得软核mcu niosII,跟stm32毫无关系

kimiyang 发表于 2009-6-1 08:49:03

那软件是 Quartus II + nios II
是在fpga 上实现一个软核!
那板子是我自己做的,上面也有stm32芯片

lichao_ecjtu 发表于 2009-7-20 23:08:16

sopc里面免费的LCD1602   是指的   Optrex 16207 LCD Controller ?
       我在系统中添加了它去控制 1602

lichao_ecjtu 发表于 2009-7-20 23:11:32

只能看到 1602 的第一排鬼影消失了(像是初始化成功) 但未出现应该见着的字符 ?

       程序如下:

#include <stdio.h>
#include "system.h"

int main()
{
FILE *fp_LCD=0;

printf("Hello from Nios II!\n");   
   
fp_LCD = fopen("/dev/lcd_16207_0","w");   // open LCD for write

if(fp_LCD==0)
   printf("\nError Opening %s\n\n");
else
   {
   printf("LCD opened, ready for access\n");
   fprintf(fp_LCD,"This message should scroll across the screen... ");
   }

return 0;
}

LZ 请教了··

smiler 发表于 2009-8-6 20:04:35

ding!

zlq999 发表于 2009-8-28 10:08:27

你在里面加个 while ,不然肯定鬼影了

tear086 发表于 2009-11-15 14:15:42

Altera DE2 例程

test.c
-----------------------------------------------------------------------------------------
#include "LCD.h"// LCD1602
//----------------------------------------------------------
int main(void)
{

//             -> ---------------- <-// 16bits
char Line1 = "LCD1602 Test";
char Line2 = "by yf.c";
LCD_Test(Line1, Line2);

return 0;
}
//----------------------------------------------------------
-----------------------------------------------------------------------------------------

LCD.h
-----------------------------------------------------------------------------------------
#ifndef   __LCD_H__
#define   __LCD_H__

//LCD Module 16*2
#define lcd_write_cmd(data)   IOWR(LCD1602_BASE, 0, data)
#define lcd_read_cmd()          IORD(LCD1602_BASE, 1)
#define lcd_write_data(data)    IOWR(LCD1602_BASE, 2, data)
#define lcd_read_data()         IORD(LCD1602_BASE, 3)
//----------------------------------------------------------
voidLCD_Init();
voidLCD_Show_Text(char* Text);
voidLCD_Line2();
voidLCD_Test(char* Text1, char* Text2);
//----------------------------------------------------------

#endif
-----------------------------------------------------------------------------------------

LCD.c
-----------------------------------------------------------------------------------------
#include <unistd.h>
#include <string.h>
#include <io.h>
#include "system.h"
#include "LCD.h"
//----------------------------------------------------------
void LCD_Init()
{
lcd_write_cmd(0x38);usleep(5000);   // Display Mode
lcd_write_cmd(0x0C);usleep(5000);   // Cursor Glint Mode
lcd_write_cmd(0x01);usleep(5000);   // Clear Display
lcd_write_cmd(0x06);usleep(5000);   // Cursor Move Forward Mode
lcd_write_cmd(0x80);usleep(5000);   // Point to the Initial Address
}
//----------------------------------------------------------
void LCD_Show_Text(char* Text)
{
int i;
for(i=0;i<strlen(Text);i++)
{
    lcd_write_data(Text);usleep(5000);
}
}
//----------------------------------------------------------
void LCD_Line2()
{
lcd_write_cmd(0xC0);usleep(5000);
}
//----------------------------------------------------------
void LCD_Test(char* Text1, char* Text2)
{
LCD_Init();         //Initial LCD
LCD_Show_Text(Text1); //Show Text of Line1 to LCD
LCD_Line2();          //Change Line2
LCD_Show_Text(Text2); //Show Text of Line2 to LCD
}
//----------------------------------------------------------

haitao178 发表于 2009-11-17 16:20:35

好,回去我也试试

ling010512 发表于 2010-8-24 21:30:52

楼主的2个方法,我都没有试出来

but 9楼“tear086 .COM 缺氧” 的方法倒是可以的
除了调用io.h下的IOWR(LCD1602_BASE, 0, data)等函数,
还可以用altera_avalon_lcd_16207_regs.h下的IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 0x38)等函数
都可以显示

不过还是有几个问题:
1 用fopen,fprintf,不能显示,何解?
2.sdtout设置成“lcd”,同样不能在lcd1602上看到任何东西
以上2个,在main中,都添加了while(1),以避免函数运行结束,指针乱飞
3.虽然用调用IOWR(LCD1602_BASE, 0, data)等函数,显示成功,但用示波器查看LCD_RS、LCD_RW管脚上的信号,发现有周期为几十ns的“方波”,因为方波的上跳与下降沿不理想,也可以看做是正弦波,这又是为什么?

Lz199222 发表于 2014-5-15 19:23:27

想请教一下您“使用nios中lcd1602 驱动器 搞定1602 “是怎么实现的,我添加了1602的核,也用了bidir,可依旧不行,在IDE中的程序有什么需要注意的么?还是添加核的时候命名有什么要求?
页: [1]
查看完整版本: 使用nios中lcd1602 驱动器 搞定1602