homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
main.cpp@11:9cae003da12b, 2013-09-07 (annotated)
- Committer:
- gatedClock
- Date:
- Sat Sep 07 20:37:37 2013 +0000
- Revision:
- 11:9cae003da12b
- Parent:
- 10:2b0a9fc39109
- Child:
- 12:e40272e1fd8f
button ISRs in progress.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gatedClock | 0:fcca4db7b32a | 1 | /*----------------------------------------------//------------------------------ |
gatedClock | 0:fcca4db7b32a | 2 | student : m-moore |
gatedClock | 0:fcca4db7b32a | 3 | class : rtos |
gatedClock | 10:2b0a9fc39109 | 4 | directory : RTOS_HW_07 |
gatedClock | 0:fcca4db7b32a | 5 | file : main.cpp |
gatedClock | 0:fcca4db7b32a | 6 | ----description---------------------------------//------------------------------ |
gatedClock | 0:fcca4db7b32a | 7 | -----includes-----------------------------------//----------------------------*/ |
gatedClock | 0:fcca4db7b32a | 8 | #include "mbed.h" // mbed class. |
gatedClock | 10:2b0a9fc39109 | 9 | #include "rtos.h" // rtos class. |
gatedClock | 10:2b0a9fc39109 | 10 | #include "C12832_lcd.h" // LCD class. |
gatedClock | 0:fcca4db7b32a | 11 | //---defines------------------------------------//------------------------------ |
gatedClock | 9:cfdb9aa5857c | 12 | #define LCD1 lcd.locate(0, 0); // LCD line 1. |
gatedClock | 9:cfdb9aa5857c | 13 | #define LCD2 lcd.locate(0,11); // LCD line 2. |
gatedClock | 9:cfdb9aa5857c | 14 | #define LCD3 lcd.locate(0,22); // LCD line 3. |
gatedClock | 9:cfdb9aa5857c | 15 | |
gatedClock | 10:2b0a9fc39109 | 16 | |
gatedClock | 9:cfdb9aa5857c | 17 | #define DEBOUNCE 0.16 // debounce pause duration in S. |
gatedClock | 0:fcca4db7b32a | 18 | //--global_definitions--------------------------//------------------------------ |
gatedClock | 0:fcca4db7b32a | 19 | //--global_variables----------------------------//------------------------------ |
gatedClock | 0:fcca4db7b32a | 20 | //--global_instances----------------------------//------------------------------ |
gatedClock | 9:cfdb9aa5857c | 21 | C12832_LCD lcd; // LCD object. |
gatedClock | 0:fcca4db7b32a | 22 | |
gatedClock | 0:fcca4db7b32a | 23 | InterruptIn iJoyStickUp (p15); // joystick up rising edge. |
gatedClock | 0:fcca4db7b32a | 24 | InterruptIn iJoyStickDown (p12); // joystick down rising edge. |
gatedClock | 0:fcca4db7b32a | 25 | InterruptIn iJoyStickLeft (p13); // joystick left rising edge. |
gatedClock | 0:fcca4db7b32a | 26 | InterruptIn iJoyStickRight (p16); // joystick right rising edge. |
gatedClock | 0:fcca4db7b32a | 27 | InterruptIn iJoyStickCenter(p14); // 1 if joystick middle pressed. |
gatedClock | 0:fcca4db7b32a | 28 | |
gatedClock | 0:fcca4db7b32a | 29 | DigitalOut led3(LED1); // leftmost LED. |
gatedClock | 0:fcca4db7b32a | 30 | |
gatedClock | 9:cfdb9aa5857c | 31 | Ticker tickerMetronome; // blinking LED. |
gatedClock | 9:cfdb9aa5857c | 32 | Ticker tickerLCD; // display ticker. |
gatedClock | 9:cfdb9aa5857c | 33 | Timeout timeoutDutyCycle; // LED duty cycle delay. |
gatedClock | 9:cfdb9aa5857c | 34 | Timeout timeoutMetronome; |
gatedClock | 0:fcca4db7b32a | 35 | //-------prototypes-----------------------------//------------------------------ |
gatedClock | 9:cfdb9aa5857c | 36 | void initialization(); // initialize settings. |
gatedClock | 0:fcca4db7b32a | 37 | //==============================================//============================== |
gatedClock | 0:fcca4db7b32a | 38 | int main(void) |
gatedClock | 0:fcca4db7b32a | 39 | { |
gatedClock | 9:cfdb9aa5857c | 40 | iJoyStickUp.rise (&ISR_up); // metronome stop. |
gatedClock | 9:cfdb9aa5857c | 41 | iJoyStickDown.rise (&ISR_down); // metronome start. |
gatedClock | 9:cfdb9aa5857c | 42 | |
gatedClock | 9:cfdb9aa5857c | 43 | iJoyStickLeft.rise (&ISR_left_rising); // increase BPM. |
gatedClock | 9:cfdb9aa5857c | 44 | iJoyStickLeft.fall (&ISR_left_falling); // anti-bounce. |
gatedClock | 9:cfdb9aa5857c | 45 | |
gatedClock | 9:cfdb9aa5857c | 46 | iJoyStickRight.rise(&ISR_right_rising); // decrease BPM. |
gatedClock | 9:cfdb9aa5857c | 47 | iJoyStickRight.fall(&ISR_right_falling); // anti-bounce. |
gatedClock | 7:9fbd1d540863 | 48 | |
gatedClock | 9:cfdb9aa5857c | 49 | iJoyStickCenter.rise(&ISR_center); // 60BPM. |
gatedClock | 9:cfdb9aa5857c | 50 | |
gatedClock | 9:cfdb9aa5857c | 51 | initialization(); // initialize variables. |
gatedClock | 0:fcca4db7b32a | 52 | |
gatedClock | 9:cfdb9aa5857c | 53 | // metronome ticker. |
gatedClock | 9:cfdb9aa5857c | 54 | tickerMetronome.attach(&interrupt_service_M,fMetroDelay); |
gatedClock | 9:cfdb9aa5857c | 55 | |
gatedClock | 9:cfdb9aa5857c | 56 | // LCD ticker. |
gatedClock | 9:cfdb9aa5857c | 57 | tickerLCD.attach(&lcd_display,LCDSAMPLERATE); |
gatedClock | 0:fcca4db7b32a | 58 | |
gatedClock | 0:fcca4db7b32a | 59 | while(1) // all timer/interrupt driven. |
gatedClock | 0:fcca4db7b32a | 60 | { |
gatedClock | 9:cfdb9aa5857c | 61 | wait(10.0); |
gatedClock | 0:fcca4db7b32a | 62 | } |
gatedClock | 0:fcca4db7b32a | 63 | } |
gatedClock | 0:fcca4db7b32a | 64 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 0:fcca4db7b32a | 65 | void initialization(void) // program initializations. |
gatedClock | 0:fcca4db7b32a | 66 | { |
gatedClock | 10:2b0a9fc39109 | 67 | |
gatedClock | 0:fcca4db7b32a | 68 | } |
gatedClock | 0:fcca4db7b32a | 69 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 11:9cae003da12b | 70 | void ISRleftButtonRising |
gatedClock | 1:9188d4668a88 | 71 | { |
gatedClock | 11:9cae003da12b | 72 | __disable_irq(); // debounce start. |
gatedClock | 9:cfdb9aa5857c | 73 | |
gatedClock | 11:9cae003da12b | 74 | |
gatedClock | 9:cfdb9aa5857c | 75 | |
gatedClock | 9:cfdb9aa5857c | 76 | wait(DEBOUNCE); // debounce time. |
gatedClock | 9:cfdb9aa5857c | 77 | |
gatedClock | 11:9cae003da12b | 78 | __enable_irq(); // debounce done. |
gatedClock | 11:9cae003da12b | 79 | } |
gatedClock | 1:9188d4668a88 | 80 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 11:9cae003da12b | 81 | void ISRleftButtonFalling // button-release debounce. |
gatedClock | 1:9188d4668a88 | 82 | { |
gatedClock | 11:9cae003da12b | 83 | __disable_irq(); // debounce start. |
gatedClock | 9:cfdb9aa5857c | 84 | |
gatedClock | 11:9cae003da12b | 85 | |
gatedClock | 9:cfdb9aa5857c | 86 | |
gatedClock | 9:cfdb9aa5857c | 87 | wait(DEBOUNCE); // debounce time. |
gatedClock | 9:cfdb9aa5857c | 88 | |
gatedClock | 11:9cae003da12b | 89 | __enable_irq(); // debounce done. |
gatedClock | 11:9cae003da12b | 90 | } |
gatedClock | 2:665ffa57031f | 91 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 10:2b0a9fc39109 | 92 |