📄 display.c
字号:
// ********************************************************************// This program named 'display.c' supplies some normally colors for user// Please use them exactly as following name convention// Red, Green, Blue, Yellow, BabyBlue, Purple// ********************************************************************#include "xparameters.h"#include "xgpio_l.h"#include "xgpio.h"#include "mb_interface.h"#include "xintc.h"#include "opb_vga.h"#include "xutil.h"#include "xtmrctr.h"#include "opb_hc164.h"#define HC164_ADDR XPAR_OPB_HC164_0_BASEADDRint TimerCounterHandler(void *CallBackRef, Xuint8 TimerCounterNumber) { Xuint32 whichLed ; Xuint32 whichDigit; Xuint32 sec; Xuint32 sec1; Xuint32 sec2; Xuint32 min; Xuint32 min1; Xuint32 min2; Xuint32 led; Xuint32 temp; XTmrCtr *InstancePtr = (XTmrCtr *)CallBackRef; //XGpio_mSetDataDirection( XPAR_LEDS_4BIT_BASEADDR, 1, 0x00000000 ); //XGpio_mSetDataReg( XPAR_LEDS_4BIT_BASEADDR, 1, 0x0 ); //XGpio_mSetDataReg( XPAR_LEDS_4BIT_BASEADDR, 1, 0x1 ); //whichLed = XIo_In32( HC164_ADDR ); temp = XIo_In32( HC164_ADDR ); whichLed = 0x00F00000 & temp; led = whichLed >> 20; whichDigit = 0x000FFFF0 & temp; sec = ( whichDigit & 0x00000FF0 ) >> 4; sec1 = ( whichDigit & 0x000000F0 ) >> 4; sec2 = ( whichDigit & 0x00000F00 ) >> 8; min = ( whichDigit & 0x000FF000 ) >> 12; min1 = ( whichDigit & 0x0000F000 ) >> 12; min2 = ( whichDigit & 0x000F0000 ) >> 16; if ( led == 0x8 && sec == 0x21 && min == 0x43 ) { led = 0;//start led count sec = 0; sec1 = 0; sec2 = 0; min1 = 0; min2 = 0; min = 0; temp = ( led << 20 ) + ( sec << 4 ) + ( min << 12 ); led_display(HC164_ADDR,temp);//output C to led return(0); } else if ( led == 0x0 ) { led = 1; //led_display(HC164_ADDR,0x00100010); } else if ( led == 0x1 ) { led = 2; //led_display(HC164_ADDR,0x00143210); } else if ( led == 0x2 ) { led = 4; //led_display(HC164_ADDR,0x00843210); } else if ( led == 0x4 ) { led = 8; } else if ( led == 0x8 ) { led = 1; } if ( sec1 < 9 ) { sec1 = sec1 + 1; } else { sec1 = 0; if ( sec2 < 5 ) { sec2 = sec2 + 1; } else { sec2 = 0; if ( min1 < 9 ) { min1 = min1 + 1; } else { min1 = 0; if ( min2 < 5 ) { min2 = min2 + 1; } else { min2 = 0; } } } } temp = ( led << 20 ) + ( sec1 << 4 ) + ( sec2 << 8 )+ ( min1 << 12 ) + ( min2 << 16 ); led_display(HC164_ADDR,temp);//output C to led }void Push_Buttons_Position ( void *InstancePtr ) { XGpio *GpioPtr = (XGpio *)InstancePtr; Xuint32 whichLed; Xuint32 whichColor; Xuint32 iRed; Xuint32 iGreen; Xuint32 iBlue; whichLed = XGpio_mGetDataReg ( XPAR_GENERIC_GPIO_BASEADDR, 1 ) ;//judge which button whichColor = XIo_In32 ( XPAR_OPB_VGA_0_BASEADDR ); iRed = ( whichColor & 0x000001C0 ) >> 6; iGreen = ( whichColor & 0x00000038 ) >>3; iBlue = whichColor & 0x00000007; if ( whichLed == 0xE ) { XIo_Out32 ( XPAR_OPB_VGA_0_BASEADDR,0x00000000 );//yellow,sw3,80,1110- led_display(HC164_ADDR,0x00000000); xil_printf("-- Clear screen --\r\n"); } if ( whichLed == 0xD ) { if ( iRed < 0x7 ) { iRed = iRed + 1; } else { iRed = 0; } whichColor = ( iRed << 6 ) + ( iGreen << 3 ) + iBlue; XIo_Out32 ( XPAR_OPB_VGA_0_BASEADDR,whichColor );//red,sw4,180,1101 xil_printf("-- Red add one --\r\n"); } if ( whichLed == 0xB ) { if ( iGreen < 0x7 ) { iGreen = iGreen + 1; } else { iGreen = 0; } whichColor = ( iRed << 6 ) + ( iGreen << 3 ) + iBlue; XIo_Out32 ( XPAR_OPB_VGA_0_BASEADDR,whichColor );//green,sw5,181,1011 xil_printf("-- Green add one --\r\n"); } if ( whichLed == 0x7 ) { if ( iBlue < 0x7 ) { iBlue = iBlue + 1; } else { iBlue = 0; } whichColor = ( iRed << 6 ) + ( iGreen << 3 ) + iBlue; XIo_Out32 ( XPAR_OPB_VGA_0_BASEADDR,whichColor );//blue,sw6,189,0111 xil_printf("-- Blue add one --\r\n"); } XGpio_InterruptClear( GpioPtr, XGPIO_IR_CH1_MASK ); }//handlerint main () { Xuint32 whichLed; XGpio Gpio;//structor XIntc Intc; XStatus status; XTmrCtr TimerCounter;//structor for timer Xuint32 Color; int temp =0x00F43210;//for test led_display(HC164_ADDR,temp);//test whether system is health xil_printf("-- Hello World! --\r\n"); RGB_Show ( XPAR_OPB_VGA_0_BASEADDR, Purple );//output purple to led, every thing is OK status = XGpio_Initialize( &Gpio, XPAR_GENERIC_GPIO_BASEADDR );//initial GPIO if ( status == XST_SUCCESS ) { RGB_Show ( XPAR_OPB_VGA_0_BASEADDR, Red );//red } xil_printf("-- Gpio initial pass. --\r\n"); status = XTmrCtr_Initialize ( &TimerCounter, XPAR_OPB_TIMER_0_DEVICE_ID ); if ( status == XST_SUCCESS ) { XIo_Out32(HC164_ADDR,0x00E43210);//output E to led } xil_printf("-- Timer initial pass. --\r\n"); status = XIntc_Initialize( &Intc, XPAR_OPB_INTC_0_DEVICE_ID );//initial INTC if ( status == XST_SUCCESS ) { RGB_Show ( XPAR_OPB_VGA_0_BASEADDR, Green );//green,intc } xil_printf("-- Intc initial pass. --\r\n"); status = XIntc_Connect ( &Intc, XPAR_OPB_INTC_0_GENERIC_GPIO_IP2INTC_IRPT_INTR, ( XInterruptHandler ) Push_Buttons_Position, &Gpio ); if ( status == XST_SUCCESS ) { RGB_Show ( XPAR_OPB_VGA_0_BASEADDR, Blue );//blue,connect } xil_printf("-- Intc connect push button handler pass. --\r\n"); status = XIntc_Connect ( &Intc , XPAR_OPB_INTC_0_OPB_TIMER_0_INTERRUPT_INTR , ( XInterruptHandler ) XTmrCtr_InterruptHandler , &TimerCounter ); //connect timer to intc if ( status == XST_SUCCESS ) { XIo_Out32(HC164_ADDR,0x00843210);//output 8 to led } xil_printf("-- Intc connect timer handler pass. --\r\n"); XTmrCtr_SetHandler ( &TimerCounter, TimerCounterHandler, &TimerCounter );//timer connect xil_printf("-- Timer set handler pass. --\r\n"); XGpio_InterruptEnable( &Gpio, XGPIO_IR_CH1_MASK ); XGpio_InterruptGlobalEnable( &Gpio );//enable interrupt in GPIO xil_printf("-- Gpio enable intc pass. --\r\n"); XIntc_Enable( &Intc, XPAR_OPB_INTC_0_GENERIC_GPIO_IP2INTC_IRPT_INTR );//enable intc XIntc_Enable( &Intc , XPAR_OPB_INTC_0_OPB_TIMER_0_INTERRUPT_INTR );//enable timer in intc xil_printf("-- Intc enable pass. --\r\n"); XTmrCtr_SetOptions ( &TimerCounter, XPAR_OPB_TIMER_0_DEVICE_ID , XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION );//choose some options XTmrCtr_mSetLoadReg ( XPAR_OPB_TIMER_0_BASEADDR , XPAR_OPB_TIMER_0_DEVICE_ID , 0x2FAF080 ); xil_printf("-- Timer sets option pass. --\r\n"); XTmrCtr_Start ( &TimerCounter, XPAR_OPB_TIMER_0_DEVICE_ID ); xil_printf("-- Timer start. --\r\n"); microblaze_enable_interrupts(); XIntc_Start( &Intc, XIN_REAL_MODE ); xil_printf("-- Intc start,please press button to change color on screen. --\r\n"); xil_printf("-- SELF TEST PASS. --\r\n"); RGB_Show ( XPAR_OPB_VGA_0_BASEADDR, BabyBlue ); while (1) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -