注: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 #
/*******************************************************************************/
module Avalon_MM_Slave_LCD1602
(
//clock input
input icsi_clk ,//
input ireset_n ,//
//Avalon_MM_Slave interface
input iavs_chipselect ,//片选信号
input [ :] iavs_address ,//地址,译码后确定寄存器offset
input iavs_write ,//写使能信号
input [:] 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 [ :] oLCD1602_DAT //
);
//-------------------------------------------------------------------------------
wire oLCD1602_RS_N ;//
wire oLCD1602_RW_N ;//
wire oLCD1602_EN_N ;//
wire [:] oLCD1602_DAT_N ;// //LCD1602_RS
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_RS <= 'h0;
else
oLCD1602_RS <= oLCD1602_RS_N ;//
end
assign oLCD1602_RS_N = ((iavs_write && iavs_chipselect) && (iavs_address == 'h0)) ? iavs_writedata[0] : oLCD1602_RS; //LCD1602_RW
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_RW <= 'h0;
else
oLCD1602_RW <= oLCD1602_RW_N ;//
end
assign oLCD1602_RW_N = ((iavs_write && iavs_chipselect) && (iavs_address == 'h1)) ? iavs_writedata[0] : oLCD1602_RW; //LCD1602_EN
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_EN <= 'h0;
else
oLCD1602_EN <= oLCD1602_EN_N ;//
end
assign oLCD1602_EN_N = ((iavs_write && iavs_chipselect) && (iavs_address == 'h2)) ? iavs_writedata[0] : oLCD1602_EN; //LCD1602_DAT
always@(posedge icsi_clk or negedge ireset_n)begin
if(!ireset_n)
oLCD1602_DAT <= 'h0;
else
oLCD1602_DAT <= oLCD1602_DAT_N ;//
end
assign oLCD1602_DAT_N = ((iavs_write && iavs_chipselect) && (iavs_address == '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();//LCD_RS = 0;
usleep();
LCD_DATA(com);//LCD_DATA = com;
usleep();
LCD_EN();//LCD_EN = 1;
usleep();
LCD_EN();//LCD_EN = 0;
usleep();
}
/*Write Data*/
void Write_Data(alt_u8 data)
{
LCD_RS();// LCD_RS = 1;
usleep();
LCD_DATA(data);//LCD_DATA = data;
usleep();
LCD_EN();//LCD_EN = 1;
usleep();
LCD_EN();//LCD_EN = 0;
usleep();
}
/*LCD 1602 Initialization*/
void LCD_Init(void)
{
LCD_EN();// LCD_EN = 0;
LCD_RW();//LCD_RW = 0;
usleep();
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 == )
addr = 0x80 + col;
else
addr = 0xC0 + col;
Write_Com(addr);
//while(*(pCN) != '\0')
for(i=; i<strlen(pCN); i++)
{
Write_Data(*(pCN+i));
}
} int main(void)
{
LCD_Init();
LCD_Display(,,(alt_u8*)"Avalon-MM IP2012");
LCD_Display(,,(alt_u8*)" Made By Na Xia");
while()
{ }
}

最新文章

  1. [LeetCode] Design Phone Directory 设计电话目录
  2. XAMARIN +VS2015 ANDROID 开发判断gps 是否打开。
  3. Sql Server 2008 无法启动T-Sql调试问题的解决方案
  4. 在帝都的Android面试感想
  5. jade学习01
  6. 查看windows系统热键占用情况
  7. iOS开发:记录开发中遇到的编译或运行异常以及解决方案
  8. [USACO08JAN]电话线Telephone Lines
  9. 解密电子书之三:MCU(君正)
  10. 使用 CXF 做 webservice 简单例子[转]
  11. AspNet.WebAPI.OData.ODataPQ实现WebAPI的分页查询服务-(个人拙笔)
  12. putty连接远程局域网的MySql(不需要单独打开plink)
  13. spring-mybatis的整合
  14. poj3162
  15. 破解sublime的sftp
  16. POJ 2195 - Going Home - [最小费用最大流][MCMF模板]
  17. centos下gitlab私服完整安装部署(nginx+MySQL+redis+gitlab-ce+gitlab-shell+)
  18. Windows:使用Dos命令管理服务(Services)
  19. IntelliJ IDEA 把Json字符串 增加到IDE里 用windows记事本 能自动转换(自动增加转义字符)
  20. [Arc074E] RGB Sequence

热门文章

  1. Java中8进制数和16进制数的表示方法
  2. idea的插件库连不上网络
  3. C++ stringstream用法(转)
  4. MyBatis 动态代理开发
  5. Redis 数据结构的底层实现 (二) dict skiplist intset
  6. element 表格里的input点击回车聚焦下个input
  7. [HTML] websocket的模拟日志监控界面
  8. 后端工具——Maven——初篇——目录
  9. 初识Docker:BusyBox容器后台运行失败
  10. DOM的方法和属性