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_KEY_LED 23 ( 24 //clock input 25 input icsi_clk ,// 26 input ireset_n ,// 27 //Avalon_MM_Slave interface 28 input iavs_chipselect ,//片選信號 29 input iavs_address ,//地址,譯碼後肯定寄存器offset 30 input iavs_write ,//寫使能信號 31 input [31:0] iavs_writedata ,//32位寫數據值 32 input iavs_read ,//讀時能信號 33 output reg [31:0] oavs_readdata ,//32位讀數據值 34 input [3 :0] iavs_byteenable ,//字節使能信號 35 //hardware interface(Conduit End) 36 input [17:0] iavs_export_KEY ,// 37 output reg [17:0] oavs_export_LEDR // 38 ); 39 //------------------------------------------------------------------------------- 40 // 41 reg [17:0] oavs_export_LEDR_N; 42 always@(posedge icsi_clk or negedge ireset_n)begin 43 if(!ireset_n) 44 oavs_export_LEDR <= 18'h0; 45 else 46 oavs_export_LEDR <= oavs_export_LEDR_N; 47 end 48 always@(*)begin 49 if(iavs_chipselect && iavs_write && (iavs_address == 1'h0)) 50 oavs_export_LEDR_N = iavs_writedata[17:0]; 51 else 52 oavs_export_LEDR_N = oavs_export_LEDR; 53 end 54 // 55 reg [31:0] oavs_readdata_N; 56 always@(posedge icsi_clk or negedge ireset_n)begin 57 if(!ireset_n) 58 oavs_readdata <= 32'h0; 59 else 60 oavs_readdata <= oavs_readdata_N; 61 end 62 always@(*)begin 63 if(iavs_chipselect && iavs_read && (iavs_address == 1'h1)) 64 oavs_readdata_N = iavs_export_KEY; 65 else 66 oavs_readdata_N = oavs_readdata; 67 end 68 //------------------------------------------------------------------------------- 69 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 LED(data) IOWR(KEY_LED_BASE, 0, data) 27 #define KEY IORD(KEY_LED_BASE, 1) 28 29 unsigned int i; 30 31 int main(void) 32 { 33 34 while(1) 35 { 36 i = KEY; 37 LED(i); 38 } 39 }