LCD1602 IP Design

Avalon-MM____LCD1602 IP Design

(1)verilog代码

/********************************************************************
*    Module Name           :   Crazy_LCD1602
*    Author                :   Crazy Bingo
*    Device                :    EP2C8Q208C8 
*    Version               :   Quartus II 10.1
*    Date                  :   2011-3-3
*    Description           :  
*********************************************************************/
module Crazy_LCD1602
(    //According to the Avalon-MM Memory-Mapped interface
    //Clok Input
    input                csi_clk,
    input                csi_rst_n,
    //Avalon-MM Slave
    input                avs_chipselect,
    input        [1:0]    avs_address,
    input                avs_write,
    input        [31:0]    avs_writedata,
//    input                avs_read,
//    input        [31:0]    avs_readdata,

    //Conduit End   
    output    reg            coe_lcd1602_rs,
    output    reg            coe_lcd1602_rw,
    output    reg            coe_lcd1602_en,
    output    reg    [7:0]    coe_lcd1602_data
);

//--------------------------------
//    wiite data
always@(posedge csi_clk or negedge csi_rst_n)
begin
    if(!csi_rst_n)
        begin
        coe_lcd1602_rs         <=    1'b0;
        coe_lcd1602_rw         <=    1'b0;
        coe_lcd1602_en         <=    1'b0;
        coe_lcd1602_data     <=    8'b0;
        end
    else if(avs_chipselect & avs_write)
        begin
        case(avs_address)
        0:    coe_lcd1602_rs        <=    avs_writedata[0];
        1:    coe_lcd1602_rw        <=    avs_writedata[0];
        2:    coe_lcd1602_en        <=    avs_writedata[0];
        3:    coe_lcd1602_data    <=    avs_writedata[7:0];
        endcase
        end
end

endmodule

 

(2)SOPC导入ip

image

image

image

 

 

(3)建立Quartus 工程

/********************************************************************
*    Module Name       :   sopc_ip_test
*    Author            :   Crazy Bingo
*    Device            :   EP2C8Q208C8
*    Version           :   Quartus II 10.1
*    Date              :   2011-3-3
*    Description       :   Top moudle of the program
*********************************************************************/
module sram_test
(
    //global clk
    input            clk,
    input            rst_n,
    //sram interface
    inout    [15:0]    sram_data,
    output    [18:0]    sram_addr,
    output            sram_ce_n,
    output            sram_we_n,
    output            sram_oe_n,
    output            sram_ub_n,
    output            sram_lb_n,
    //user interface
    input    [1:0]    key_data,
    output    [1:0]    led_data,
    //lcd1602 interface
    output            lcd_en,
    output            lcd_rs,
    output            lcd_rw,
    output    [7:0]    lcd_data
);   

sram_test_core sram_test_core_inst
(
    .clk                            (clk),
    .reset_n                          (rst_n),
    .coe_SRAM_ADDR_from_the_sram      (sram_addr),
    .coe_SRAM_CE_N_from_the_sram      (sram_ce_n),
    .coe_SRAM_DQ_to_and_from_the_sram (sram_data),
    .coe_SRAM_LB_N_from_the_sram      (sram_lb_n),
    .coe_SRAM_OE_N_from_the_sram      (sram_oe_n),
    .coe_SRAM_UB_N_from_the_sram      (sram_ub_n),
    .coe_SRAM_WE_N_from_the_sram      (sram_we_n),
    .coe_lcd1602_rs_from_the_lcd1602    (lcd_rs),
    .coe_lcd1602_rw_from_the_lcd1602    (lcd_rw),
    .coe_lcd1602_en_from_the_lcd1602    (lcd_en),
    .coe_lcd1602_data_from_the_lcd1602  (lcd_data),

    .coe_key_data_to_the_key_led_data   (key_data),
    .coe_led_data_from_the_key_led_data (led_data)
);

endmodule

image

image

 

(4)建立nios2 工程

//----------------------------------------------------------

#ifndef MY_SOPC_H_
#define MY_SOPC_H_

#include "system.h"

#define    CRAZY_LCD1602

 

//---------------------------------------------------------
#ifdef    CRAZY_LCD1602
    #define    LCD1602_ADDR    (LCD1602_BASE | (1<<31))
    #define    LCD_RS        (*(volatile unsigned int*)(LCD1602_ADDR + 0x00))
    #define    LCD_RW        (*(volatile unsigned int*)(LCD1602_ADDR + 0x04))
    #define    LCD_EN        (*(volatile unsigned int*)(LCD1602_ADDR + 0x08))
    #define    LCD_DATA    (*(volatile unsigned int*)(LCD1602_ADDR + 0x0C))
#endif

 

//----------------------------------------------------------

文件 “lccd1602.h”

#ifndef CRAZY_LCD1602_H_
#define CRAZY_LCD1602_H_

#include "alt_types.h"
#include "my_sopc.h"

void Write_Com(alt_u8 com);
void Write_Data(alt_u8 data);
void LCD_Init(void);
void LCD_Display(alt_u8 row, alt_u8 col, alt_u8 *pCN);

#endif /* CRAZY_LCD1602_H_ */

 

 

//----------------------------------------------------------

文件“lcd1602.c”

/*
* Crazy_LCD1602.c
*
*  Created on: 2011-2-24
*      Author: Administrator
*/

#include <string.h>
#include "unistd.h"
#include "LCD1602.h"

/*Write Command*/
void Write_Com(alt_u8 com)
{
    LCD_RS = 0;
    usleep(5000);
    LCD_DATA = com;
    usleep(5000);
    LCD_EN = 1;
    usleep(5000);
    LCD_EN = 0;
    usleep(5000);
}
/*Write Data*/
void Write_Data(alt_u8 data)
{
    LCD_RS = 1;
    usleep(5000);
    LCD_DATA = data;
    usleep(5000);
    LCD_EN = 1;
    usleep(5000);
    LCD_EN = 0;
    usleep(5000);
}
/*LCD 1602 Initialization*/
void LCD_Init(void)
{
    LCD_EN = 0;
    LCD_RW = 0;
    usleep(5000);
    Write_Com(0x38);
    Write_Com(0x0C);
    Write_Com(0x06);
    Write_Com(0x01);
    Write_Com(0x80);
}
void LCD_Display(alt_u8 row, alt_u8 col, alt_u8 *pCN)
{
    alt_u8    i, addr;
    if(row == 0)
        addr = 0x80 + col;
    else
        addr = 0xC0 + col;
    Write_Com(addr);
    //while(*(pCN) != '\0')
    for(i=0; i<strlen(pCN); i++)
    {
        Write_Data(*(pCN+i));
    }
}

 

//----------------------------------------------------------

文件 "nios2_main.v"

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

#include "my_sopc.h"
#include "LCD1602.h"

alt_u8 key_scan(void);

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

    LCD_Init();
    LCD_Display(0,2,(alt_u8*)"Avalon-MM IP");
    LCD_Display(1,2,(alt_u8*)"Made By Bingo");

    retrurn 0;

 

run  handware OK

 

注意:地址分配的一一对应

转载于:https://www.cnblogs.com/GL-BBL/archive/2012/08/23/2651762.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值