您的位置:首页 > 运维架构

每天进步一点点------SOPC的Avalon-MM IP核(三) LCD1602 IP定制

2013-08-09 11:37 429 查看
注:Avalon信号类型命名参考图



/*********************************************************************************
* Company                    :
* Engineer                    : 空气微凉
*
* Create Date                : 00:00:00 22/03/2013
* Design Name                :
* Module Name                :
* Project Name                :
* Target Devices            :
* Tool versions                :
* Description                :
*                                   http://www.cnblogs.com/kongqiweiliang/ * Dependencies                :
*                                Avalon_MM_Slave_IP
* Revision                    :
* Revision                    : 0.01 - File Created
* Additional Comments        :
********************************************************************************/
`timescale 1ns/1ps
`define    UD  #1
/*******************************************************************************/
module Avalon_MM_Slave_LCD1602
(
//clock input
input                                         icsi_clk            ,//
input                                         ireset_n             ,//
//Avalon_MM_Slave interface
input                                         iavs_chipselect        ,//片选信号
input                            [1 :0]         iavs_address        ,//地址,译码后确定寄存器offset
input                                         iavs_write            ,//写使能信号
input                            [31:0]         iavs_writedata        ,//32位写数据值
//input                                         iavs_read            ,//读时能信号
//input                            [31:0]         iavs_readdata        ,//32位读数据值
//input                                         iavs_byteenable         //字节使能信号
//hardware interface(Conduit End)
output  reg                                 oLCD1602_RS            ,//
output  reg                                 oLCD1602_RW            ,//
output  reg                                 oLCD1602_EN            ,//
output  reg                     [7 :0]         oLCD1602_DAT         //
);
//-------------------------------------------------------------------------------
wire            oLCD1602_RS_N    ;//
wire         oLCD1602_RW_N    ;//
wire          oLCD1602_EN_N    ;//
wire  [7:0]  oLCD1602_DAT_N    ;//

//LCD1602_RS
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_RS <= 1'h0;
else
oLCD1602_RS <= oLCD1602_RS_N    ;//
end
assign oLCD1602_RS_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h0)) ? iavs_writedata[0] : oLCD1602_RS;

//LCD1602_RW
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_RW <= 1'h0;
else
oLCD1602_RW <= oLCD1602_RW_N    ;//
end
assign oLCD1602_RW_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h1)) ? iavs_writedata[0] : oLCD1602_RW;

//LCD1602_EN
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_EN <= 1'h0;
else
oLCD1602_EN <= oLCD1602_EN_N    ;//
end
assign oLCD1602_EN_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h2)) ? iavs_writedata[0] : oLCD1602_EN;

//LCD1602_DAT
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_DAT <= 8'h0;
else
oLCD1602_DAT <= oLCD1602_DAT_N    ;//
end
assign oLCD1602_DAT_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h3)) ? iavs_writedata[7:0] : oLCD1602_DAT;
//-------------------------------------------------------------------------------
endmodule








/*********************************************************************************
* Company                   :
* Engineer                  : 空气微凉
*
* Create Date               : 00:00:00 22/03/2013
* Design Name               :
* Module Name               :
* Project Name              :
* Target Devices            :
* Tool versions             :
* Description               :
*
* Dependencies              :
*
* Revision                  :
* Revision                  : 0.01 - File Created
* Additional Comments       :
********************************************************************************/
#include <stdio.h>
#include <string.h>
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include "unistd.h"

#define LCD_RS(data)       IOWR(OLCD1602_BASE, 0, data)
#define LCD_RW(data)       IOWR(OLCD1602_BASE, 1, data)
#define LCD_EN(data)       IOWR(OLCD1602_BASE, 2, data)
#define LCD_DATA(data)     IOWR(OLCD1602_BASE, 3, data)

//#define    LCD1602_ADDR    (OLCD1602_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))

/*Write Command*/
void Write_Com(alt_u8 com)
{
LCD_RS(0);//LCD_RS = 0;
usleep(5000);
LCD_DATA(com);//LCD_DATA = com;
usleep(5000);
LCD_EN(1);//LCD_EN = 1;
usleep(5000);
LCD_EN(0);//LCD_EN = 0;
usleep(5000);
}
/*Write Data*/
void Write_Data(alt_u8 data)
{
LCD_RS(1);// LCD_RS = 1;
usleep(5000);
LCD_DATA(data);//LCD_DATA = data;
usleep(5000);
LCD_EN(1);//LCD_EN = 1;
usleep(5000);
LCD_EN(0);//LCD_EN = 0;
usleep(5000);
}
/*LCD 1602 Initialization*/
void LCD_Init(void)
{
LCD_EN(0);// LCD_EN = 0;
LCD_RW(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));
}
}

int main(void)
{
LCD_Init();
LCD_Display(0,0,(alt_u8*)"Avalon-MM IP2012");
LCD_Display(1,0,(alt_u8*)" Made By Na Xia");
while(1)
{

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: