1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| #include "xil_io.h" #include "stdio.h" #include "xgpio.h" #include "sleep.h" #include "xtmrctr.h" #include "xintc_l.h" int main() { char button = 0x0; char segtable[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; short segcode[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; short pos=0xff7f; Xil_Out16(XPAR_GPIO_0_BASEADDR+XGPIO_TRI_OFFSET,0xffff); Xil_Out16(XPAR_GPIO_1_BASEADDR+XGPIO_TRI_OFFSET,0X0); Xil_Out16(XPAR_GPIO_1_BASEADDR+XGPIO_TRI2_OFFSET,0x0); Xil_Out8(XPAR_GPIO_2_BASEADDR+XGPIO_TRI_OFFSET,0x1f); while(1) { while((Xil_In8(XPAR_GPIO_2_BASEADDR+XGPIO_DATA_OFFSET)&0X1f)!=0) { button = Xil_In8(XPAR_GPIO_2_BASEADDR + XGPIO_DATA_OFFSET)&0x1f; short sw = Xil_In16(XPAR_GPIO_0_BASEADDR+XGPIO_DATA_OFFSET); while((Xil_In8(XPAR_GPIO_2_BASEADDR + XGPIO_DATA_OFFSET)&0x1f)!=0); switch (button) { case 0x1: for(int j=0;j<8;j++) { segcode[7-j]=segtable[(sw>>j)&0x1]; } break; case 0x2: for(int j=0;j<4;j++) { segcode[7-j]=segtable[(sw>>(4*j))&0xf]; } for(int j=4;j<8;j++) { segcode[7-j]=0xff; } break; case 0x10: int a=sw; for(int j=0;j<5;j++) { switch (a%10) { { case(0):segcode[7-j]=segtable[0];break; case(1):segcode[7-j]=segtable[1];break; case(2):segcode[7-j]=segtable[2];break; case(3):segcode[7-j]=segtable[3];break; case(4):segcode[7-j]=segtable[4];break; case(5):segcode[7-j]=segtable[5];break; case(6):segcode[7-j]=segtable[6];break; case(7):segcode[7-j]=segtable[7];break; case(8):segcode[7-j]=segtable[8];break; case(9):segcode[7-j]=segtable[9];break; } } a/=10; } for(int j=5;j<8;j++) { segcode[7-j]=0xff; } break; default: break; } } for(int i=0;i<8;i++) { Xil_Out8(XPAR_AXI_GPIO_1_BASEADDR+XGPIO_DATA_OFFSET,pos); Xil_Out8(XPAR_AXI_GPIO_1_BASEADDR+XGPIO_DATA2_OFFSET,segcode[i]); for(int j=0;j<10000;j++); pos=pos>>1; } pos=0xff7f; } }
|