Hangman game using qp a 16x2 LCD and joystick.

Dependencies:   TextLCD mbed qp

Committer:
tylerjw
Date:
Thu Feb 09 03:57:44 2012 +0000
Revision:
1:4efaebc256d3
Parent:
0:1521c946a57b
Problems with qp library...
TODO: BSP for button and joystick then main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:1521c946a57b 1 #include "qp_port.h"
tylerjw 0:1521c946a57b 2 #include "hangman.h"
tylerjw 0:1521c946a57b 3 #include "bsp.h"
tylerjw 0:1521c946a57b 4 #include "LPC17xx.h"
tylerjw 0:1521c946a57b 5 #include "mbed.h"
tylerjw 0:1521c946a57b 6
tylerjw 1:4efaebc256d3 7 Q_DEFINE_THIS_FILE
tylerjw 1:4efaebc256d3 8
tylerjw 0:1521c946a57b 9 enum ISR_Priorities { // ISR priorities from highest urgency to lowest
tylerjw 0:1521c946a57b 10 BUTTON_PRIO,
tylerjw 0:1521c946a57b 11 SYSTICK_PRIO,
tylerjw 0:1521c946a57b 12 };
tylerjw 0:1521c946a57b 13
tylerjw 0:1521c946a57b 14
tylerjw 0:1521c946a57b 15 #define LED_PORT LPC_GPIO1
tylerjw 0:1521c946a57b 16 #define LED1_BIT (1U << 18)
tylerjw 0:1521c946a57b 17 #define LED2_BIT (1U << 20)
tylerjw 0:1521c946a57b 18 #define LED3_BIT (1U << 21)
tylerjw 0:1521c946a57b 19 #define LED4_BIT (1U << 23)
tylerjw 0:1521c946a57b 20
tylerjw 0:1521c946a57b 21 //............................................................................
tylerjw 0:1521c946a57b 22 extern "C" void SysTick_Handler(void) {
tylerjw 0:1521c946a57b 23 QK_ISR_ENTRY(); // inform the QK kernel of entering the ISR
tylerjw 0:1521c946a57b 24
tylerjw 0:1521c946a57b 25 #ifdef Q_SPY
tylerjw 0:1521c946a57b 26 uint32_t volatile dummy = SysTick->CTRL; // clear the COUNTFLAG in SysTick
tylerjw 0:1521c946a57b 27 l_tickTime += l_tickPeriod; // account for the clock rollover
tylerjw 0:1521c946a57b 28 #endif
tylerjw 0:1521c946a57b 29
tylerjw 0:1521c946a57b 30 QF::TICK(&l_SysTick_Handler); // process all armed time events
tylerjw 0:1521c946a57b 31
tylerjw 0:1521c946a57b 32 QK_ISR_EXIT(); // inform the QK kernel of exiting the ISR
tylerjw 0:1521c946a57b 33 }
tylerjw 0:1521c946a57b 34
tylerjw 0:1521c946a57b 35 //............................................................................
tylerjw 0:1521c946a57b 36 void BSP_init(void) {
tylerjw 0:1521c946a57b 37 SystemInit(); // initialize the clocking system
tylerjw 0:1521c946a57b 38
tylerjw 0:1521c946a57b 39 // set LED port to output
tylerjw 0:1521c946a57b 40 LED_PORT->FIODIR |= (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
tylerjw 0:1521c946a57b 41
tylerjw 0:1521c946a57b 42 // clear the LEDs
tylerjw 0:1521c946a57b 43 LED_PORT->FIOCLR = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
tylerjw 0:1521c946a57b 44
tylerjw 0:1521c946a57b 45 QS_OBJ_DICTIONARY(&l_SysTick_Handler);
tylerjw 0:1521c946a57b 46 }
tylerjw 0:1521c946a57b 47
tylerjw 0:1521c946a57b 48 //............................................................................
tylerjw 0:1521c946a57b 49 void BSP_lcdScrollIn(char* line1, char* line2) {
tylerjw 0:1521c946a57b 50 // scroller algorithm
tylerjw 0:1521c946a57b 51 lcd.cls();
tylerjw 0:1521c946a57b 52 char output1[17];
tylerjw 0:1521c946a57b 53 char output2[17];
tylerjw 0:1521c946a57b 54 for ( int i = 0; i < 17; i++) {
tylerjw 0:1521c946a57b 55 output1[i] = ' ';
tylerjw 0:1521c946a57b 56 output2[i] = ' ';
tylerjw 0:1521c946a57b 57 }
tylerjw 0:1521c946a57b 58 for (int i = 0; i < 17; i++) {
tylerjw 0:1521c946a57b 59 for (int col = 0; col < 17; col++) {
tylerjw 0:1521c946a57b 60
tylerjw 0:1521c946a57b 61 if (col >= i) {
tylerjw 0:1521c946a57b 62 output1[col] = ' ';
tylerjw 0:1521c946a57b 63 output2[col] = ' ';
tylerjw 0:1521c946a57b 64 } else {
tylerjw 0:1521c946a57b 65 output1[col] = (line1[col+(16-i)]);
tylerjw 0:1521c946a57b 66 output2[col] = (line2[col+(16-i)]);
tylerjw 0:1521c946a57b 67 }
tylerjw 0:1521c946a57b 68 lcd.locate(col,0);
tylerjw 0:1521c946a57b 69 lcd.putc(output1[col]);
tylerjw 0:1521c946a57b 70 lcd.locate(col,1);
tylerjw 0:1521c946a57b 71 lcd.putc(output2[col]);
tylerjw 0:1521c946a57b 72 }
tylerjw 0:1521c946a57b 73 wait(0.4);
tylerjw 0:1521c946a57b 74 }
tylerjw 0:1521c946a57b 75 }
tylerjw 0:1521c946a57b 76
tylerjw 0:1521c946a57b 77 //............................................................................
tylerjw 0:1521c946a57b 78 void BSP_lcdUpdate(char* line1,char* line2) {
tylerjw 0:1521c946a57b 79 uint8_t length1 = strlen(line1);
tylerjw 0:1521c946a57b 80 uint8_t length2 = strlen(line2);
tylerjw 0:1521c946a57b 81 if (length1 > length2)
tylerjw 0:1521c946a57b 82 length1 = length2;
tylerjw 0:1521c946a57b 83 lcd.cls();
tylerjw 0:1521c946a57b 84 if (length1 < 17)
tylerjw 0:1521c946a57b 85 for (int col = 0; col < 17 && col < length1; col++) {
tylerjw 0:1521c946a57b 86 lcd.locate(col,0);
tylerjw 0:1521c946a57b 87 lcd.putc(*(line1+col));
tylerjw 0:1521c946a57b 88 lcd.locate(col,1);
tylerjw 0:1521c946a57b 89 lcd.putc(*(line2+col));
tylerjw 0:1521c946a57b 90 }
tylerjw 0:1521c946a57b 91 else
tylerjw 0:1521c946a57b 92 for (int col = 0; col < 17; col++) {
tylerjw 0:1521c946a57b 93 lcd.locate(col,0);
tylerjw 0:1521c946a57b 94 lcd.putc(*(line1+col));
tylerjw 0:1521c946a57b 95 lcd.locate(col,1);
tylerjw 0:1521c946a57b 96 lcd.putc(*(line2+col));
tylerjw 0:1521c946a57b 97 }
tylerjw 0:1521c946a57b 98 }
tylerjw 0:1521c946a57b 99
tylerjw 0:1521c946a57b 100 //............................................................................
tylerjw 0:1521c946a57b 101 void QF::onStartup(void) {
tylerjw 0:1521c946a57b 102 // set up the SysTick timer to fire at BSP_TICKS_PER_SEC rate
tylerjw 0:1521c946a57b 103 SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SEC);
tylerjw 0:1521c946a57b 104
tylerjw 0:1521c946a57b 105 // set priorities of all interrupts in the system...
tylerjw 0:1521c946a57b 106 NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIO);
tylerjw 0:1521c946a57b 107 //NVIC_SetPriority(EINT0_IRQn, GPIOPORTA_PRIO);
tylerjw 0:1521c946a57b 108
tylerjw 0:1521c946a57b 109 //NVIC_EnableIRQ(EINT0_IRQn);
tylerjw 0:1521c946a57b 110 }
tylerjw 0:1521c946a57b 111 //............................................................................
tylerjw 0:1521c946a57b 112 void QF::onCleanup(void) {
tylerjw 0:1521c946a57b 113 }
tylerjw 0:1521c946a57b 114 //............................................................................
tylerjw 0:1521c946a57b 115 void QK::onIdle(void) {
tylerjw 0:1521c946a57b 116
tylerjw 0:1521c946a57b 117 QF_INT_LOCK(dummy);
tylerjw 0:1521c946a57b 118 LED_PORT->FIOSET = LED4_BIT; // turn the LED4 on
tylerjw 0:1521c946a57b 119 __NOP(); // delay a bit to see some light intensity
tylerjw 0:1521c946a57b 120 __NOP();
tylerjw 0:1521c946a57b 121 __NOP();
tylerjw 0:1521c946a57b 122 __NOP();
tylerjw 0:1521c946a57b 123 LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off
tylerjw 0:1521c946a57b 124 QF_INT_UNLOCK(dummy);
tylerjw 0:1521c946a57b 125
tylerjw 0:1521c946a57b 126 __WFI();
tylerjw 0:1521c946a57b 127 }
tylerjw 0:1521c946a57b 128
tylerjw 0:1521c946a57b 129 //............................................................................
tylerjw 0:1521c946a57b 130 void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
tylerjw 0:1521c946a57b 131 (void)file; // avoid compiler warning
tylerjw 0:1521c946a57b 132 (void)line; // avoid compiler warning
tylerjw 0:1521c946a57b 133 QF_INT_LOCK(dummy); // make sure that all interrupts are disabled
tylerjw 0:1521c946a57b 134 // light up all LEDs
tylerjw 0:1521c946a57b 135 LED_PORT->FIOSET = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
tylerjw 0:1521c946a57b 136
tylerjw 0:1521c946a57b 137 for (;;) { // NOTE: replace the loop with reset for final version
tylerjw 0:1521c946a57b 138 }
tylerjw 0:1521c946a57b 139 }