zoukankan      html  css  js  c++  java
  • 每天进步一点点------SOPC的Avalon-MM IP核(三) LCD1602 IP定制

     注:Avalon信号类型命名参考图

     1  /*********************************************************************************
     2 * Company                    : 
     3 * Engineer                    : 空气微凉
     4 * 
     5 * Create Date                : 00:00:00 22/03/2013 
     6 * Design Name                : 
     7 * Module Name                :         
     8 * Project Name                :  
     9 * Target Devices            : 
    10 * Tool versions                : 
    11 * Description                :  
    12 *                                   http://www.cnblogs.com/kongqiweiliang/             
    13 * Dependencies                : 
    14 *                                Avalon_MM_Slave_IP
    15 * Revision                    : 
    16 * Revision                    : 0.01 - File Created
    17 * Additional Comments        : 
    18 ********************************************************************************/
    19 `timescale 1ns/1ps
    20 `define    UD  #1
    21 /*******************************************************************************/
    22 module Avalon_MM_Slave_LCD1602
    23 ( 
    24     //clock input
    25     input                                         icsi_clk            ,// 
    26     input                                         ireset_n             ,// 
    27     //Avalon_MM_Slave interface  
    28     input                                         iavs_chipselect        ,//片选信号
    29     input                            [1 :0]         iavs_address        ,//地址,译码后确定寄存器offset
    30     input                                         iavs_write            ,//写使能信号
    31     input                            [31:0]         iavs_writedata        ,//32位写数据值
    32     //input                                         iavs_read            ,//读时能信号
    33     //input                            [31:0]         iavs_readdata        ,//32位读数据值
    34     //input                                         iavs_byteenable         //字节使能信号
    35     //hardware interface(Conduit End)
    36     output  reg                                 oLCD1602_RS            ,//
    37     output  reg                                 oLCD1602_RW            ,//
    38     output  reg                                 oLCD1602_EN            ,//
    39     output  reg                     [7 :0]         oLCD1602_DAT         //                                
    40 );  
    41 //-------------------------------------------------------------------------------
    42 wire            oLCD1602_RS_N    ;//
    43 wire         oLCD1602_RW_N    ;//
    44 wire          oLCD1602_EN_N    ;//
    45 wire  [7:0]  oLCD1602_DAT_N    ;//    
    46 
    47 //LCD1602_RS
    48 always@(posedge icsi_clk or negedge ireset_n)begin
    49     if(!ireset_n)
    50         oLCD1602_RS <= 1'h0;
    51     else
    52         oLCD1602_RS <= oLCD1602_RS_N    ;//
    53 end
    54 assign oLCD1602_RS_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h0)) ? iavs_writedata[0] : oLCD1602_RS;
    55 
    56 //LCD1602_RW
    57 always@(posedge icsi_clk or negedge ireset_n)begin
    58     if(!ireset_n)
    59         oLCD1602_RW <= 1'h0;
    60     else
    61         oLCD1602_RW <= oLCD1602_RW_N    ;//
    62 end
    63 assign oLCD1602_RW_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h1)) ? iavs_writedata[0] : oLCD1602_RW;
    64 
    65 //LCD1602_EN
    66 always@(posedge icsi_clk or negedge ireset_n)begin
    67     if(!ireset_n)
    68         oLCD1602_EN <= 1'h0;
    69     else
    70         oLCD1602_EN <= oLCD1602_EN_N    ;//
    71 end
    72 assign oLCD1602_EN_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h2)) ? iavs_writedata[0] : oLCD1602_EN;
    73 
    74 //LCD1602_DAT
    75 always@(posedge icsi_clk or negedge ireset_n)begin
    76     if(!ireset_n)
    77         oLCD1602_DAT <= 8'h0;
    78     else
    79         oLCD1602_DAT <= oLCD1602_DAT_N    ;//
    80 end
    81 assign oLCD1602_DAT_N = ((iavs_write && iavs_chipselect) && (iavs_address == 2'h3)) ? iavs_writedata[7:0] : oLCD1602_DAT;
    82 //-------------------------------------------------------------------------------
    83 endmodule 

     1 /*********************************************************************************
     2 * Company                   : 
     3 * Engineer                  : 空气微凉
     4 * 
     5 * Create Date               : 00:00:00 22/03/2013 
     6 * Design Name               : 
     7 * Module Name               :        
     8 * Project Name              :  
     9 * Target Devices            : 
    10 * Tool versions             : 
    11 * Description               :  
    12 *                                   
    13 * Dependencies              : 
    14 *
    15 * Revision                  : 
    16 * Revision                  : 0.01 - File Created
    17 * Additional Comments       : 
    18 ********************************************************************************/
    19 #include <stdio.h>
    20 #include <string.h>
    21 #include "system.h"
    22 #include "altera_avalon_pio_regs.h"
    23 #include "alt_types.h"
    24 #include "unistd.h"
    25 
    26 #define LCD_RS(data)       IOWR(OLCD1602_BASE, 0, data)
    27 #define LCD_RW(data)       IOWR(OLCD1602_BASE, 1, data)
    28 #define LCD_EN(data)       IOWR(OLCD1602_BASE, 2, data)
    29 #define LCD_DATA(data)     IOWR(OLCD1602_BASE, 3, data)
    30 
    31 //#define    LCD1602_ADDR    (OLCD1602_BASE | (1<<31))
    32 //#define    LCD_RS          (*(volatile unsigned int*)(LCD1602_ADDR + 0x00))
    33 //#define    LCD_RW          (*(volatile unsigned int*)(LCD1602_ADDR + 0x04))
    34 //#define    LCD_EN          (*(volatile unsigned int*)(LCD1602_ADDR + 0x08))
    35 //#define    LCD_DATA        (*(volatile unsigned int*)(LCD1602_ADDR + 0x0C))
    36 
    37 /*Write Command*/
    38 void Write_Com(alt_u8 com)
    39 {
    40     LCD_RS(0);//LCD_RS = 0;
    41     usleep(5000);
    42     LCD_DATA(com);//LCD_DATA = com;
    43     usleep(5000);
    44     LCD_EN(1);//LCD_EN = 1;
    45     usleep(5000);
    46     LCD_EN(0);//LCD_EN = 0;
    47     usleep(5000);
    48 }
    49 /*Write Data*/
    50 void Write_Data(alt_u8 data)
    51 {
    52     LCD_RS(1);// LCD_RS = 1;
    53     usleep(5000);
    54     LCD_DATA(data);//LCD_DATA = data;
    55     usleep(5000);
    56     LCD_EN(1);//LCD_EN = 1;
    57     usleep(5000);
    58     LCD_EN(0);//LCD_EN = 0;
    59     usleep(5000);
    60 }
    61 /*LCD 1602 Initialization*/
    62 void LCD_Init(void)
    63 {
    64     LCD_EN(0);// LCD_EN = 0;
    65     LCD_RW(0);//LCD_RW = 0;
    66     usleep(5000);
    67     Write_Com(0x38);
    68     Write_Com(0x0C);
    69     Write_Com(0x06);
    70     Write_Com(0x01);
    71     Write_Com(0x80);
    72 }
    73 void LCD_Display(alt_u8 row, alt_u8 col, alt_u8 *pCN)
    74 {
    75     alt_u8    i, addr;
    76     if(row == 0)
    77         addr = 0x80 + col;
    78     else
    79         addr = 0xC0 + col;
    80     Write_Com(addr);
    81     //while(*(pCN) != '')
    82     for(i=0; i<strlen(pCN); i++)
    83     {
    84         Write_Data(*(pCN+i));
    85     }
    86 }
    87 
    88 int main(void)
    89 {
    90     LCD_Init();
    91     LCD_Display(0,0,(alt_u8*)"Avalon-MM IP2012");
    92     LCD_Display(1,0,(alt_u8*)" Made By Na Xia");
    93     while(1)
    94     {
    95     
    96     }
    97 }

      

  • 相关阅读:
    libusb 示例
    里不是吧、
    ibeacon UUID
    Centos7系统下Docker开启认证的远程端口2376配置教程
    Consul 快速入门
    docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
    Docker 启动容器时,报错 WARNING:IPv4 forwarding is disabled. Networking will not work. 的解决办法
    【基线检查】(高)基线检查--禁用local-infile选项(访问控制)
    PyCharm 上安装 Package(以 pandas 为例)
    Python time模块和datetime模块
  • 原文地址:https://www.cnblogs.com/kongqiweiliang/p/3247895.html
Copyright © 2011-2022 走看看