/* * Setup the IO for the LED outputs. */ void vParTestInitialise( void ) { /* Set both sets of LED's on the demo board to outputs. */ XGpio_mSetDataDirection( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT ); XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT ); /* Start with all outputs off. */ uxCurrentOutput8Bit = 0; XGpio_mSetDataReg( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, 0x00 ); uxCurrentOutput5Bit = 0; XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 ); }
int kc_SendCmd(int cmd) { int temp=0; // STEP1: send D7-D4, rs=0,rw=0,en=1 // get upper nibble from given command temp |= (cmd& 0x10) << 2; // place D4 in position 6 temp |= (cmd& 0x20) << 0; // place D5 in position 5 temp |= (cmd& 0x40) >> 2; // place D6 in position 4 temp |= (cmd& 0x80) >> 4; // place D7 in position 3 // en=1, rs=0, rw=0 temp |= 0x1; //xil_printf("cmd.h1: 0x%x\r\n", temp); msleep(1); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, temp); // en=0, rs=0, rw=0 temp &= ~(0x1); //xil_printf("cmd.h2: 0x%x\r\n", temp); msleep(1); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, temp); // STEP2: send D3-D0, rs=0,rw=0,en=0 // get lower nibble from given command temp=0; temp |= (cmd& 0x01) << 6; // place D0 in position 6 temp |= (cmd& 0x02) << 4; // place D1 in position 5 temp |= (cmd& 0x04) << 2; // place D2 in position 4 temp |= (cmd& 0x08) >> 0; // place D3 in position 3 // en=1, rs=0, rw=0 temp |= 0x1; //xil_printf("cmd.l1: 0x%x\r\n", temp); msleep(1); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, temp); // en=0, rs=0, rw=0 temp &= ~(0x1); //xil_printf("cmd.l2: 0x%x\r\n\r\n", temp); msleep(1); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, temp); // wait for busy / delay msleep(1); return 0; }
int hello_rotary2(void) { unsigned int data; int pulses=0, dir=0; //set GPIO input mode XGpio_mSetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 4, 0xffffffff); ///////////////////////////////////// // STATE 1: Get the direction pulse //xil_printf(" \r\nState1 \r\n"); do { // get hold of a pulse that tells one of below // bits[1:0] = 01 Left rotation // bits[1:0] = 10 Right rotation // bit 2 = 1 button press data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if(data & 0x1) { dir = DIR_LEFT; break; } if(data & 0x2) { dir = DIR_RIGHT; break; } } while( (data& 0x3) == 0); ////////////////////////////////////////////// // STATE 2: Get the pulses from both switches //xil_printf(" State2 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); } while( (data& 0x3) != 0x3); ///////////////////////////////////////////////////// // STATE 3: Get the pulses from both switches to NULL //xil_printf(" State3 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); } while( (data& 0x3) != 0); // RESULT TO USER pulses += dir; xil_printf("%s-%d [Exit: press anykey]\r\n", (dir==DIR_RIGHT) ? "Anti-Clockwise" : " Clockwise", abs(pulses) ); return dir; }
void LED_Toggle (INT8U led) { INT32U led_status; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif led_status = XGpio_mGetDataReg(BSP_GPIO_ADDR,1); OS_ENTER_CRITICAL(); switch (led) { case 0: //led_status ^= 0xFFFFFFFF; led_status ^= 0x000001FF;; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 1: led_status ^= 0x00000001; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 2: led_status ^= 0x00000002; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 3: led_status ^= 0x00000004; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; case 4: led_status ^= 0x00000008; XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status); break; default: break; } OS_EXIT_CRITICAL(); }
void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) { unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue; portENTER_CRITICAL(); { /* Which IO section does the LED being toggled belong to? The 4 bit or 5 bit outputs? */ if( uxLED <= partstMAX_8BIT_LED ) { uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR; puxCurrentValue = &uxCurrentOutput5Bit; } else { uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR; puxCurrentValue = &uxCurrentOutput8Bit; uxLED -= partstMAX_8BIT_LED; } /* Setup the bit mask accordingly. */ uxLED = 0x01 << uxLED; /* Maintain the current output value. */ if( *puxCurrentValue & uxLED ) { *puxCurrentValue &= ~uxLED; } else { *puxCurrentValue |= uxLED; } /* Write the value to the port. */ XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue ); } portEXIT_CRITICAL(); }
int hello_rotary(void) { unsigned int data; int pulses=0, dir=0; /*** XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE); XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS); ***/ xil_printf("\n\r********************************************************"); xil_printf("\n\r********************************************************"); xil_printf("\n\r** KC705 - Rotary Switch Test **"); xil_printf("\n\r********************************************************"); xil_printf("\n\r********************************************************\r\n"); xil_printf("Watch the ROTARY pulses count:\r\n"); xil_printf("press any key to exit the test\r\n"); XUartNs550_ReadReg(STDIN_BASEADDRESS, XUN_RBR_OFFSET); //set GPIO input mode XGpio_mSetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 4, 0xffffffff); while(1) { ///////////////////////////////////// // STATE 1: Get the direction pulse //xil_printf(" \r\nState1 \r\n"); do { // get hold of a pulse that tells one of below // bits[1:0] = 01 Left rotation // bits[1:0] = 10 Right rotation // bit 2 = 1 button press data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if(data & 0x1) { dir = DIR_LEFT; break; } if(data & 0x2) { dir = DIR_RIGHT; break; } if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; } while( (data& 0x3) == 0); ////////////////////////////////////////////// // STATE 2: Get the pulses from both switches //xil_printf(" State2 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; } while( (data& 0x3) != 0x3); ///////////////////////////////////////////////////// // STATE 3: Get the pulses from both switches to NULL //xil_printf(" State3 \r\n"); do { data = XGpio_mGetDataReg(XPAR_ROTARY_GPIO_BASEADDR, 0); if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; } while( (data& 0x3) != 0); // PRESS ANY KEY TO EXIT if( XUartNs550_IsReceiveData(STDIN_BASEADDRESS) ) goto rotary_exit; // RESULT TO USER pulses += dir; xil_printf("%s-%d [Exit: press anykey]\r\n", (dir==DIR_RIGHT) ? "Anti-Clockwise" : " Clockwise", abs(pulses) ); } rotary_exit: XUartNs550_ReadReg(STDIN_BASEADDRESS, XUN_RBR_OFFSET); return 0; }
int kc_initLCD(void) { xil_printf("reset LCD\r\n"); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 4, 0); //// RESET, needed for 4-bit mode only XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0xff); msleep(20); //xil_printf("1\r\n"); //send cmd 0x30 XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x61); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x60); msleep(15); //xil_printf("2\r\n"); //send cmd 0x30 XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x61); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x60); msleep(5); //xil_printf("3\r\n"); //send cmd 0x30 XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x61); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x60); msleep(5); //xil_printf("4\r\n"); //send cmd 0x20 // set 4-bit mode XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x21); XGpio_mSetDataReg(XPAR_LCD_GPIO_BASEADDR, 0, 0x20); msleep(5); // note: BUSY flag will be valid only after above sequence //xil_printf("initializing LCD\r\n"); //// INITIALIZATION, common to 4bit and 8bit modes kc_FunctionSet(4, 2); // 0x28 kc_CursorMode(2); // 0x0f kc_EntryMode(0); // 0x06 kc_SetDDRAM(0); // 0x80 #if 0 // TEST PURPOSE ONLY kc_SendData('A'); kc_SendData('B'); kc_SendData('C'); kc_SendData('D'); kc_SendData('E'); kc_SendData('F'); kc_SendData('G'); kc_SendData('H'); kc_SendData('I'); kc_SendData('J'); kc_SendData('K'); kc_SendData('L'); kc_SendData('M'); kc_SendData('N'); kc_SendData('O'); kc_SendData('P'); kc_SetDDRAM(0x40); kc_SendData('Q'); kc_SendData('R'); kc_SendData('S'); kc_SendData('T'); kc_SendData('U'); kc_SendData('V'); kc_SendData('W'); kc_SendData('X'); kc_SendData('Y'); kc_SendData('Z'); #endif return 0; }