Hangman game using qp a 16x2 LCD and joystick.

Dependencies:   TextLCD mbed qp

Committer:
tylerjw
Date:
Wed Feb 08 22:20:11 2012 +0000
Revision:
0:1521c946a57b
Child:
1:4efaebc256d3
Problems with lib/qp, please help!
Player class hasn\t been developed yet.
BSP is still missing some features.

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