
实验平台:DE2-115
软件版本:Quartus II 15.1
为节约时间,qsys中系统的搭建就不啰嗦了,直接贴图。
DE2-115中SDRAM的配置如下图所示:
HarDWare code:
1 module LCD1602( 2 clk, 3 rst_n, 4 led, 5 lcd1602_RS, 6 lcd1602_RW, 7 lcd1602_data, 8 lcd1602_E, 9 sdram_addr,10 sdram_ba,11 sdram_cas_n,12 sdram_cke,13 sdram_cs_n,14 sdram_dq,15 sdram_dqm,16 sdram_ras_n,17 sdram_we_n,18 sdram_clk,19 lcd1602_vl,20 lcd1602_on 21 );22 23 input clk;24 output lcd1602_RS;25 output lcd1602_RW;26 inout [7:0] lcd1602_data;27 output lcd1602_E;28 output lcd1602_vl;29 output lcd1602_on;30 31 input rst_n;32 output[12:0]sdram_addr;33 output[1:0] sdram_ba;34 output sdram_cas_n;35 output sdram_cke;36 output sdram_cs_n;37 inout [31:0]sdram_dq;38 output[3:0] sdram_dqm;39 output sdram_ras_n;40 output sdram_we_n;41 output sdram_clk;42 43 output[3:0] led;44 45 wire c0;46 reg[3:0] vl_cnt;47 [email protected](posedge clk or negedge rst_n)48 if(!rst_n)49 vl_cnt <= 4‘d0;50 else51 vl_cnt <= vl_cnt + 4‘d1;52 53 assign lcd1602_vl = (vl_cnt > 9);54 assign lcd1602_on = 1;55 56 57 58 PLL PLL_inst (59 .inclk0 ( clk ),60 .c0 ( c0 ),61 .c1 ( sdram_clk )62 );63 64 my_cpu u0 (65 .clk_clk (c0),// clk.clk66 .lcd1602_RS (lcd1602_RS),// lcd1602.RS67 .lcd1602_RW (lcd1602_RW),// .RW68 .lcd1602_data (lcd1602_data),// .data69 .lcd1602_E (lcd1602_E),// .E70 71 .reset_reset_n (rst_n),// reset.reset_n72 .sdram_addr (sdram_addr),// sdram.addr73 .sdram_ba (sdram_ba),// .ba74 .sdram_cas_n (sdram_cas_n),// .cas_n75 .sdram_cke (sdram_cke),// .cke76 .sdram_cs_n (sdram_cs_n),// .cs_n77 .sdram_dq (sdram_dq),// .dq78 .sdram_dqm (sdram_dqm),// .dqm79 .sdram_ras_n (sdram_ras_n),// .ras_n80 .sdram_we_n (sdram_we_n),// .we_n81 .pio_led_export(led)82 );83 84 85 86 endmodule@H_605_419@ VIEw CodeSoftware code:
1 /* 2 * LCD1602.h 3 * 4 * Created on: 2019年8月26日 5 * Author: Legend 6 */ 7 8 #ifndef LCD1602_H_ 9 #define LCD1602_H_10 11 #define lcd_write_cmd(base,data) IOWR(base,data)12 #define lcd_read_cmd(base) IORD(base,1)13 #define lcd_write_data(base,data) IOWR(base,2,data)14 #define lcd_read_cmd(base) IORD(base,3)15 16 voID LCD_Init();17 voID LCD_Show_Text(char*Text);18 voID LCD_line2();19 voID LCD_Text();20 21 22 23 24 #endif /* LCD1602_H_ */@H_605_419@ VIEw Code1 /* 2 * LCD1602.c 3 * 4 * Created on: 2019年8月25日 5 * Author: Legend 6 */ 7 8 #include <stdio.h> 9 #include <altera_avalon_pio_regs.h>10 #include <alt_types.h>11 #include <unistd.h>12 #include <system.h>13 #include <string.h>14 #include <io.h>15 #include <sys/alt_irq.h>16 #include "../inc/lcd1602.h"17 18 19 voID LCD_Init()20 {21 lcd_write_cmd(LCD1602_BASE,0x38); //初始化LCD22 usleep(2000);23 24 lcd_write_cmd(LCD1602_BASE,0x0c); //关显示,光标闪烁方式25 usleep(2000);26 27 lcd_write_cmd(LCD1602_BASE,0x01); //清显示28 usleep(2000);29 30 lcd_write_cmd(LCD1602_BASE,0x06); //光标迁移方式,不允许整屏移动31 usleep(2000);32 33 lcd_write_cmd(LCD1602_BASE,0x80); //显示光标指示的位置34 usleep(2000);35 }36 37 voID LCD_Show_Text(char*Text)38 {39 int i;40 for(i=0;i<strlen(Text);i++)41 {42 lcd_write_data(LCD1602_BASE,Text[i]);43 usleep(2000);44 45 }46 }47 48 voID LCD_line2() //换行49 {50 lcd_write_cmd(LCD1602_BASE,0xc0);51 usleep(2000);52 }53 54 55 int main()56 {57 char Text1[16]=" Hello DE2-115 ";58 char Text2[16]=" Legend of NCU ";59 LCD_Init();60 LCD_Show_Text(Text1);61 LCD_line2();62 LCD_Show_Text(Text2);63 64 return 0;65 }66 67 68 69 //http://blog.sina.com.cn/s/blog_457bf05a0100k8vy.HTML@H_605_419@ VIEw Code实际效果图:
总结以上是内存溢出为你收集整理的基于Nios II的LCD16027驱动实例全部内容,希望文章能够帮你解决基于Nios II的LCD16027驱动实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)