![](/media/cache/profiles/74961657ae02e93fc17be9d9fc864620.50x50_q85.jpg)
main.c@2:f034e862af1f, 2010-12-02 (annotated)
- Committer:
- hugozijlmans
- Date:
- Thu Dec 02 20:55:45 2010 +0000
- Revision:
- 2:f034e862af1f
- Parent:
- 1:2c52307d223f
Added UART0 support over USB mBed1768
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hugozijlmans | 1:2c52307d223f | 1 | #include "LPC17xx.h" |
hugozijlmans | 1:2c52307d223f | 2 | #include "core_cm3.h" |
hugozijlmans | 1:2c52307d223f | 3 | #include "cmsis_nvic.h" |
hugozijlmans | 1:2c52307d223f | 4 | #include "Timer0.h" |
hugozijlmans | 1:2c52307d223f | 5 | #include "main.h" |
hugozijlmans | 1:2c52307d223f | 6 | #include "LPC1768.h" |
hugozijlmans | 1:2c52307d223f | 7 | #include "MCPWM.h" |
hugozijlmans | 1:2c52307d223f | 8 | #include "RIT.h" |
hugozijlmans | 2:f034e862af1f | 9 | #include "UART0.h" |
hugozijlmans | 1:2c52307d223f | 10 | |
hugozijlmans | 1:2c52307d223f | 11 | // BSP defines see main.h |
hugozijlmans | 1:2c52307d223f | 12 | |
hugozijlmans | 1:2c52307d223f | 13 | int main(void); |
hugozijlmans | 1:2c52307d223f | 14 | void dispatcher(void); |
hugozijlmans | 1:2c52307d223f | 15 | |
hugozijlmans | 1:2c52307d223f | 16 | Tinterrupt_flags i_flags; |
hugozijlmans | 1:2c52307d223f | 17 | |
hugozijlmans | 1:2c52307d223f | 18 | int main(void) { |
hugozijlmans | 1:2c52307d223f | 19 | |
hugozijlmans | 1:2c52307d223f | 20 | // Set the correct PLL value to match CCLK |
hugozijlmans | 1:2c52307d223f | 21 | PLL0_init(); |
hugozijlmans | 1:2c52307d223f | 22 | |
hugozijlmans | 1:2c52307d223f | 23 | // Enable the driving of the onboard LEDs |
hugozijlmans | 1:2c52307d223f | 24 | LED_init(); |
hugozijlmans | 1:2c52307d223f | 25 | |
hugozijlmans | 1:2c52307d223f | 26 | // Set the timer0, enable it and connect to ISR |
hugozijlmans | 1:2c52307d223f | 27 | Timer0_init(); |
hugozijlmans | 2:f034e862af1f | 28 | |
hugozijlmans | 1:2c52307d223f | 29 | // Set the RIT, enable it and connect to ISR |
hugozijlmans | 1:2c52307d223f | 30 | RIT_init(); |
hugozijlmans | 1:2c52307d223f | 31 | |
hugozijlmans | 1:2c52307d223f | 32 | // Initialize MCPWM |
hugozijlmans | 1:2c52307d223f | 33 | //MCPWM_init(); |
hugozijlmans | 1:2c52307d223f | 34 | |
hugozijlmans | 2:f034e862af1f | 35 | // Initialize UART0 |
hugozijlmans | 2:f034e862af1f | 36 | UART0_init(); |
hugozijlmans | 2:f034e862af1f | 37 | |
hugozijlmans | 1:2c52307d223f | 38 | // Start the dispatcher |
hugozijlmans | 1:2c52307d223f | 39 | dispatcher(); |
hugozijlmans | 1:2c52307d223f | 40 | |
hugozijlmans | 1:2c52307d223f | 41 | } |
hugozijlmans | 1:2c52307d223f | 42 | |
hugozijlmans | 1:2c52307d223f | 43 | void dispatcher(void) { |
hugozijlmans | 1:2c52307d223f | 44 | |
hugozijlmans | 2:f034e862af1f | 45 | int byte; |
hugozijlmans | 2:f034e862af1f | 46 | |
hugozijlmans | 1:2c52307d223f | 47 | while (1) { |
hugozijlmans | 1:2c52307d223f | 48 | |
hugozijlmans | 1:2c52307d223f | 49 | // When the timer0 interrupt occurred |
hugozijlmans | 1:2c52307d223f | 50 | if (i_flags.Timer0_int == 1) { |
hugozijlmans | 2:f034e862af1f | 51 | i_flags.Timer0_int = 0; |
hugozijlmans | 2:f034e862af1f | 52 | } |
hugozijlmans | 1:2c52307d223f | 53 | |
hugozijlmans | 2:f034e862af1f | 54 | // When the RIT interrupt occurred |
hugozijlmans | 2:f034e862af1f | 55 | if (i_flags.RIT_int == 1) { |
hugozijlmans | 2:f034e862af1f | 56 | i_flags.RIT_int = 0; |
hugozijlmans | 2:f034e862af1f | 57 | } |
hugozijlmans | 2:f034e862af1f | 58 | |
hugozijlmans | 2:f034e862af1f | 59 | // When UART0 TX is idle |
hugozijlmans | 2:f034e862af1f | 60 | if (i_flags.UART0_tx_idle == 1) { |
hugozijlmans | 2:f034e862af1f | 61 | i_flags.UART0_tx_idle = 0; |
hugozijlmans | 1:2c52307d223f | 62 | } |
hugozijlmans | 1:2c52307d223f | 63 | |
hugozijlmans | 2:f034e862af1f | 64 | // When UART0 RX isn't idle |
hugozijlmans | 2:f034e862af1f | 65 | if (i_flags.UART0_rx_idle == 0) { |
hugozijlmans | 2:f034e862af1f | 66 | i_flags.UART0_rx_idle = 1; |
hugozijlmans | 2:f034e862af1f | 67 | byte = UART0_read(); |
hugozijlmans | 2:f034e862af1f | 68 | if(byte == 'a') |
hugozijlmans | 2:f034e862af1f | 69 | FIOSET |= LED1; |
hugozijlmans | 1:2c52307d223f | 70 | else |
hugozijlmans | 2:f034e862af1f | 71 | FIOCLR |= LED1; |
hugozijlmans | 2:f034e862af1f | 72 | UART0_write(byte); |
hugozijlmans | 2:f034e862af1f | 73 | } |
hugozijlmans | 1:2c52307d223f | 74 | } |
hugozijlmans | 1:2c52307d223f | 75 | |
hugozijlmans | 1:2c52307d223f | 76 | } |