1、实验操作考试复习题 解 析,建立硬件平台的步骤: 1. 搭建最小系统 2. 添加GPIO IP核并进行配置(8位输入,8位输出,并且要激活通道2) 3. 配置ucf文件,保存后生成bit流 4. 导出硬件到SDK,再建立相应的工程,(与第6章习题8类似) 1.采用某8位独立开关输入十六进制字符(09,af,AF)的ASCII码,并将该ASCII码表示的十六进制字符通过一位七段数码管显示出来,其余数值显示“-”。要求: 只有按下某个按钮时,才可以改变显示的字符。 字符显示只能为A,b,C,d,E,F 如8位独立开关的值为0110 0001时, 仅1位7段数码管显示大写的A,(0x 61为a的AS
2、CII码表示,但显示为A) 不能多位同时显示,UCF文件配置如下:NET “CLK“ TNM_NET = sys_clk_pin; TIMESPEC TS_sys_clk_pin = PERIOD sys_clk_pin 100000 kHz; NET “CLK“ LOC=“E3“ | IOSTANDARD=“LVCMOS33“; NET “RESET“ LOC=“E16“ | IOSTANDARD=“LVCMOS33“;NET “RsRx“ LOC=“C4“ | IOSTANDARD=“LVCMOS33“; NET “RsTx“ LOC=“D4“ | IOSTANDARD=“LVCMOS33
3、“;NET “sw“ LOC=“U9“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“U8“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“R7“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“R6“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“R5“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“V7“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“V6“ | IOSTANDARD=“LVCMOS33
4、“; NET “sw“ LOC=“V5“ | IOSTANDARD=“LVCMOS33“;NET “seg“ LOC=“L3“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“N1“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“L5“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“L4“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“K3“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“M2“ | IOSTANDARD=“LV
5、CMOS33“; NET “seg“ LOC=“L6“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“M4“ | IOSTANDARD=“LVCMOS33“;,.c文件(需要进一步完善),建立硬件平台: 1.搭建最小系统 2.添加连个GPIO IP核并进行配置: GPIO0:8位输入,8位输出(段码),并且要激活通道2 GPIO1:8位输出(位码) 3.配置ucf文件,保存后生成bit流 4.打开SDK,建立相应的工程,UCF 文件配置:NET “CLK“ TNM_NET = sys_clk_pin; TIMESPEC TS_sys_clk_pin = PER
6、IOD sys_clk_pin 100000 kHz;NET “CLK“ LOC=“E3“ | IOSTANDARD=“LVCMOS33“; NET “RESET“ LOC=“E16“ | IOSTANDARD=“LVCMOS33“; NET “RsRx“ LOC=“C4“ | IOSTANDARD=“LVCMOS33“; NET “RsTx“ LOC=“D4“ | IOSTANDARD=“LVCMOS33“;NET “sw“ LOC=“U9“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“U8“ | IOSTANDARD=“LVCMOS33“; NET “sw
7、“ LOC=“R7“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“R6“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“R5“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“V7“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“V6“ | IOSTANDARD=“LVCMOS33“; NET “sw“ LOC=“V5“ | IOSTANDARD=“LVCMOS33“;NET “seg“ LOC=“L3“ | IOSTANDARD=“LVCMOS33“; NET “s
8、eg“ LOC=“N1“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“L5“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“L4“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“K3“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“M2“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“L6“ | IOSTANDARD=“LVCMOS33“; NET “seg“ LOC=“M4“ | IOSTANDARD=“LVCMOS33“
9、;NET “an“ LOC = “N6“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “M6“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “M3“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “N5“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “N2“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “N4“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “L
10、1“ | IOSTANDARD = “LVCMOS33“; NET “an“ LOC = “M1“ | IOSTANDARD = “LVCMOS33“;,.C文件(需要进一步完善),效果图,(与第6章习题10类似) 3.用16个理想开关输入二进制数,16只发光二极管显示二进制数。设输入的二进制数为原码,输出的二进制数为补码。要求只有按下某个按键时,才可以改变输出。,简单来说,就是要求:输入原码,输出补码。 1、得到switch开关的状态(即原码): code = Xil_In16(0x40000000); 2、求补码: (正数不变;负数符号位不变,其余位数取反加1) if(code32768)
11、Xil_Out16(XPAR_LEDS_BASEADDR,code); elseXil_Out16(XPAR_LEDS_BASEADDR,(code)+32769);,源码:,#include “xparameters.h“ #include “xil_io.h“ int main() u16 code,state;while(1)if(state)code = Xil_In16(0x40000000);if(code32768)Xil_Out16(XPAR_LEDS_BASEADDR,code);elseXil_Out16(XPAR_LEDS_BASEADDR,(code)+32769);r
12、eturn 0; ,4. 用16个理想开关输入二进制数,16只发光二极管显示二进制数。设输入的二进制数为补码,输出的二进制数为原码。要求只有按下某个按键时,才可以改变输出。,简单来说,就是要求:输入补码,输出原码。 1、得到switch开关的状态(即 补码): code = Xil_In16(0x40000000); 2、求补码: (正数不变;负数符号位不变,其余位数取反加1) if(code32768)Xil_Out16(XPAR_LEDS_BASEADDR,code); elseXil_Out16(XPAR_LEDS_BASEADDR,(code)+32769);,源码:,#include
13、 “xparameters.h“ #include “xil_io.h“ int main() u16 code;int state;while(1)if(state)code = Xil_In16(0x40000000);if(code32768)Xil_Out16(XPAR_LEDS_BASEADDR,code);elseXil_Out16(XPAR_LEDS_BASEADDR,(code)+32769);return 0; ,5.用16个理想开关输入二进制数,16只发光二极管倒序显示该二进制数各位。设开关从左到右依次表示D15 D0 ,发光二极管从右到左依次表示D15 D0 。要求只有按
14、下某个按键时,才可以改变输出。,简单来说,就是要求:输入一个16位的数,把它倒置输出。 1、得到switch开关的状态(即原码):code = Xil_In16(0x40000000); 2、求第i位上的值:(codei)%2 3、把16位倒置后,重写:newcode = 0;for(i=0;ii)%2)(15-i) + newcode;Xil_Out16(XPAR_LEDS_BASEADDR,newcode);,源码:,#include “xparameters.h“ #include “xil_io.h“ int main() int i;u16 code;u16 newcode;whil
15、e(1)newcode = 0;code = Xil_In16(0x40000000);for(i=0;ii)%2)(15-i) + newcode;Xil_Out16(XPAR_LEDS_BASEADDR,newcode);return 0; ,6.用16个理想开关输入二进制数,16只发光二极管显示该二进制数字节序变换后的数值。要求只有按下某个按键时,才可以改变输出。,简单来说,就是要求:把高8位跟低8位互换。 1、得到switch开关的状态(即原码): code = Xil_In16(0x40000000); 2、把高8位跟低8位互换: newcode = (code8) + (code8
16、); 3、输出给LED: Xil_Out16(XPAR_LEDS_BASEADDR,newcode);,源码:,#include “xparameters.h“ #include “xil_io.h“int main() u16 code;u16 newcode;while(1)newcode = 0;code = Xil_In16(0x40000000);newcode = (code8) + (code8);Xil_Out16(XPAR_LEDS_BASEADDR,newcode);return 0; ,实验七、八、九,硬件框图,锯齿波,while(1)WriteBuffer0 = (u8
17、)(Count);WriteBuffer1 = (u8)(Count8) ,三角波,while(1)WriteBuffer0 = (u8)(Count);WriteBuffer1 = (u8)(Count8) ,方波,while(1)WriteBuffer0 = (u8)(Count);WriteBuffer1 = (u8)(Count8) ,第10题,单通道模拟电压信号采样,要求采样率为1Hz(1秒显示一次采样结果),并且将该模拟信号的电压值显示到console(单位为mV) 如输入模拟信号电压为3.3V时,console上显示的值应为3300mV左右,允许一定的误差 如输入模拟信号电压为0
18、V时,console上显示的值应为0mV左右,允许一定的误差,硬件建立,UART SPI *Timer AXI Interrupt Controller参见实验教材 P210(*Timer) P277(AD),延时方法,不需要时钟 参考实验教材P279代码,while(1)/设置传输状态标志为1TransferInProgress = TRUE;/一次传输2个字节XSpi_Transfer( ,定时器中断方法,需要配置时钟中断 参考P212代码, int main() .TransferInProgress = TRUE;while(1)/一次传输2个字节if(TransferInProgre
19、ss)XSpi_Transfer( ,时钟中断处理函数 每1s触发一次#define RESET_VALUE 0x5f5e100void TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber) if(!TransferInProgress) int val = ReadBuffer0 + (ReadBuffer1 8);val = val * 3300 / 0xfff;xil_printf(“ Voltage: %dmVrn“, val);TransferInProgress = TRUE; else xil_printf(“Transferring data. plz wait.“); ,