這個真的蠻簡單的,但是我因為port宣告錯誤而搞了一整天,所以紀錄一下,提醒自己還是要去看一下生成出來的port是哪個類別的,承接DAY3,我想去控制板子上的LCD panel(https://www.coderbridge.com/series/9187887612284144b73f569ae1c8a1e7/posts/3af35b32ed5c42a389ec8b5e88ca22a6),因為這樣之後debug和演示都會方便許多
實作:
第一步:
1.我在platform designer那裡多加一個lcd component
2.在conduit那邊宣告成lcd port
第二步:
1.在qurtus中要呼叫出剛拉好的qsys檔案和.v檔,並新增一個.v檔叫做sdram_sw_led.v,其內容如下圖,只是把要用的port宣告進來,還有Instantiate the Nios II system module generated by the Platform Designer tool
(然後要記得LCD_data port是inout port,我最一開始宣告成Output port,所以才不work)
module Lcd_display (SW, KEY, CLOCK_50, LEDR, DRAM_CLK, DRAM_CKE,
DRAM_ADDR, DRAM_BA, DRAM_CS_N, DRAM_CAS_N, DRAM_RAS_N,
DRAM_WE_N, DRAM_DQ, DRAM_DQM,HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7,LCD_DATA,LCD_RW,LCD_EN,
LCD_RS);
input [7:0] SW;
input [0:0] KEY;
input CLOCK_50;
output [7:0] LEDR;
output [12:0] DRAM_ADDR;
output [1:0] DRAM_BA;
output DRAM_CAS_N, DRAM_RAS_N, DRAM_CLK;
output DRAM_CKE, DRAM_CS_N, DRAM_WE_N;
output [3:0] DRAM_DQM;
inout [31:0] DRAM_DQ;
//////////// SEG7 //////////
output [6:0] HEX0;
output [6:0] HEX1;
output [6:0] HEX2;
output [6:0] HEX3;
output [6:0] HEX4;
output [6:0] HEX5;
output [6:0] HEX6;
output [6:0] HEX7;
//////// 7-SEG //////////////
wire HEX0P;
wire HEX1P;
wire HEX2P;
wire HEX3P;
wire HEX4P;
wire HEX5P;
wire HEX6P;
wire HEX7P;
//////// LCD //////////////
inout [7:0]LCD_DATA;
output LCD_RW;
output LCD_EN;
output LCD_RS;
// Instantiate the Nios II system module generated by the Platform Designer tool
NiosII_lcd1 lcd1(
.clk_clk(CLOCK_50), // clk.clk
.lcd_data(LCD_DATA), // lcd.DATA
.lcd_E(LCD_EN), // .EN
.lcd_RS(LCD_RS), // .RS
.lcd_RW(LCD_RW), // .RW
.leds_export(LEDR), // leds.export
.reset_reset(~KEY[0]), // reset.reset
.sdram_clk_clk(DRAM_CLK), // sdram_clk.clk
.sdram_wire_addr(DRAM_ADDR), // sdram_wire.addr
.sdram_wire_ba(DRAM_BA), // .ba
.sdram_wire_cas_n(DRAM_CAS_N), // .cas_n
.sdram_wire_cke(DRAM_CKE), // .cke
.sdram_wire_cs_n(DRAM_CS_N), // .cs_n
.sdram_wire_dq(DRAM_DQ), // .dq
.sdram_wire_dqm(DRAM_DQM), // .dqm
.sdram_wire_ras_n(DRAM_RAS_N), // .ras_n
.sdram_wire_we_n(DRAM_WE_N), // .we_n
.seg7_export({
HEX7P, HEX7, HEX6P, HEX6,
HEX5P, HEX5, HEX4P, HEX4,
HEX3P, HEX3, HEX2P, HEX2,
HEX1P, HEX1, HEX0P, HEX0}), // seg7_conduit_end.export
.switches_export(SW), // switches.export
);
endmodule
2.這樣即可以去做analysis&synthesis
第三步:
1.要做pin assignment,我一樣就是直接在qsf那邊輸入我要用的腳位
2.做完了以後就可以compile design,如果過了的話就可以在上方工具欄中開啟tools=>
nios software buils tools for eclipse了
第四步:
1.開啟之後會是空的,在右上角選擇file=>new=>niosii application and bsp from template選擇在quartus中生成的sopc(system-on-a-programmable-chip)info file,
然後將hello.c改成以下的code,可以看到lcd 生成文字了
#include<stdio.h>
#include<stdlib.h>
#include"system.h"
#include "altera_avalon_pio_regs.h"
void hello_world(void);
#define switches (volatile char *) 0x10101040
#define leds (char *) 0x10101030
int main()
{
printf("lcd say hi");
hello_world();
return 0;
}
void hello_world(void){
FILE *pLCD;
char szHello[] = "lcd \nsay hi\n";
pLCD = fopen("/dev/lcd_16207_0","w");
if(pLCD){
fwrite(szHello,strlen(szHello),1,pLCD);
fclose(pLCD);
}else{
printf("failed");
}
}
可以看到下圖在lcd印出字來