📄 board_kb.c
字号:
/* * "Hello World" example. * * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT * device in your system's hardware. * The memory footprint of this hosted application is ~69 kbytes by default * using the standard reference design. * * For a reduced footprint version of this template, and an explanation of how * to reduce the memory footprint for a given application, see the * "small_hello_world" template. * */#include <stdio.h>//#include <excalibur.h> // 10.27添加,为使用延迟函数nr_delay(t),t单位为ms#include "system.h"#include "altera_avalon_pio_regs.h"#include "alt_types.h"void delay(void){ int k=0; while(k<10000) k++;}//the function of writing data to the regesistersalt_u8 wadd (alt_u8 add){ int i; IOWR_ALTERA_AVALON_PIO_DATA(NCS0_PIO_BASE, 1); // nCS0=1,关片选 IOWR_ALTERA_AVALON_PIO_DATA(NWE_PIO_BASE, 1); // 关写 IOWR_ALTERA_AVALON_PIO_DATA(NOE_PIO_BASE, 1); //关读 IOWR_ALTERA_AVALON_PIO_DATA(NCS0_PIO_BASE, 0); // nCS0=0,chipselect IOWR_ALTERA_AVALON_PIO_DATA(NWE_PIO_BASE, 0); // 写使能 IOWR_ALTERA_AVALON_PIO_DATA(ADD_PIO_BASE,add); //给地址 { i = 0; while(i<1000) i++; } //延迟 IOWR_ALTERA_AVALON_PIO_DATA(NWE_PIO_BASE, 1); // 关写 //IOWR_ALTERA_AVALON_PIO_DATA(NOE_PIO_BASE, 1); IOWR_ALTERA_AVALON_PIO_DATA(NCS0_PIO_BASE, 1); // nCS0=1,关片选 }alt_u8 rdata (){ int i; alt_u8 da; IOWR_ALTERA_AVALON_PIO_DATA(NCS0_PIO_BASE, 1); // nCS0=1,关片选 IOWR_ALTERA_AVALON_PIO_DATA(NWE_PIO_BASE, 1); // 关写 IOWR_ALTERA_AVALON_PIO_DATA(NOE_PIO_BASE, 1); //关读 IOWR_ALTERA_AVALON_PIO_DATA(NCS0_PIO_BASE, 0); // nCS0=0,chipselect //IOWR_ALTERA_AVALON_PIO_DATA(NWE_PIO_BASE, 0); IOWR_ALTERA_AVALON_PIO_DATA(NOE_PIO_BASE, 0); //读使能 //IOWR_ALTERA_AVALON_PIO_DATA(ADD_PIO_BASE,add); //给地址 da=IORD_ALTERA_AVALON_PIO_DATA(SHUJU_PIO_BASE); //读数据 { i = 0; while(i<100) i++; } //延迟 //IOWR_ALTERA_AVALON_PIO_DATA(NWE_PIO_BASE, 1); // 关写 IOWR_ALTERA_AVALON_PIO_DATA(NOE_PIO_BASE, 1); IOWR_ALTERA_AVALON_PIO_DATA(NCS0_PIO_BASE, 1); // nCS0=1,关片选 return da; }int main(){ alt_u8 data_kb; wadd(0x17); while(1) { delay();delay();delay();delay(); data_kb=rdata(); delay();delay();delay();delay(); printf("You pressed \%d\n",data_kb); delay();delay();delay();delay(); delay();delay();delay();delay();delay();delay();delay();delay(); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -