Hsing-Hung Lai
/
Nucleo_LED
homework_1
main.cpp@0:5e39cd6c5291, 2016-03-10 (annotated)
- Committer:
- tim65132006
- Date:
- Thu Mar 10 14:05:44 2016 +0000
- Revision:
- 0:5e39cd6c5291
03101005;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim65132006 | 0:5e39cd6c5291 | 1 | /*LAB_LED*/ |
tim65132006 | 0:5e39cd6c5291 | 2 | #include "mbed.h" |
tim65132006 | 0:5e39cd6c5291 | 3 | |
tim65132006 | 0:5e39cd6c5291 | 4 | //LED1 = D13 = PA_5 (LED on Nucleo board) |
tim65132006 | 0:5e39cd6c5291 | 5 | |
tim65132006 | 0:5e39cd6c5291 | 6 | DigitalOut led1(LED1); |
tim65132006 | 0:5e39cd6c5291 | 7 | Ticker timer1; |
tim65132006 | 0:5e39cd6c5291 | 8 | |
tim65132006 | 0:5e39cd6c5291 | 9 | int a; |
tim65132006 | 0:5e39cd6c5291 | 10 | |
tim65132006 | 0:5e39cd6c5291 | 11 | void init_IO(void) |
tim65132006 | 0:5e39cd6c5291 | 12 | { |
tim65132006 | 0:5e39cd6c5291 | 13 | a = 0; |
tim65132006 | 0:5e39cd6c5291 | 14 | led1 = 0; |
tim65132006 | 0:5e39cd6c5291 | 15 | } |
tim65132006 | 0:5e39cd6c5291 | 16 | |
tim65132006 | 0:5e39cd6c5291 | 17 | void timer1_interrupt(void) |
tim65132006 | 0:5e39cd6c5291 | 18 | { |
tim65132006 | 0:5e39cd6c5291 | 19 | a = a+1; |
tim65132006 | 0:5e39cd6c5291 | 20 | } |
tim65132006 | 0:5e39cd6c5291 | 21 | |
tim65132006 | 0:5e39cd6c5291 | 22 | void init_TIMER(void) |
tim65132006 | 0:5e39cd6c5291 | 23 | { |
tim65132006 | 0:5e39cd6c5291 | 24 | timer1.attach_us(&timer1_interrupt, 1000.0);//1ms interrupt period (1 KHz) |
tim65132006 | 0:5e39cd6c5291 | 25 | } |
tim65132006 | 0:5e39cd6c5291 | 26 | |
tim65132006 | 0:5e39cd6c5291 | 27 | int main() |
tim65132006 | 0:5e39cd6c5291 | 28 | { |
tim65132006 | 0:5e39cd6c5291 | 29 | |
tim65132006 | 0:5e39cd6c5291 | 30 | init_IO(); |
tim65132006 | 0:5e39cd6c5291 | 31 | init_TIMER(); |
tim65132006 | 0:5e39cd6c5291 | 32 | |
tim65132006 | 0:5e39cd6c5291 | 33 | while(1) { |
tim65132006 | 0:5e39cd6c5291 | 34 | |
tim65132006 | 0:5e39cd6c5291 | 35 | if (a==500) { |
tim65132006 | 0:5e39cd6c5291 | 36 | led1 = 1; |
tim65132006 | 0:5e39cd6c5291 | 37 | } |
tim65132006 | 0:5e39cd6c5291 | 38 | |
tim65132006 | 0:5e39cd6c5291 | 39 | if(a==1000) { |
tim65132006 | 0:5e39cd6c5291 | 40 | led1 = 0; |
tim65132006 | 0:5e39cd6c5291 | 41 | a = 0; |
tim65132006 | 0:5e39cd6c5291 | 42 | } |
tim65132006 | 0:5e39cd6c5291 | 43 | } |
tim65132006 | 0:5e39cd6c5291 | 44 | } |