//EE 202 hm2 //This is a program built for the mbed3 in monitor mode //This code has been tested and should be function, if you has any problem, //please mail me.
main.cpp@0:d18f267c677d, 2014-03-16 (annotated)
- Committer:
- allonq
- Date:
- Sun Mar 16 07:58:01 2014 +0000
- Revision:
- 0:d18f267c677d
//EE 202 hm2; //This is a program built for the mbed3 in generation mode; //This code has been tested and should be function, if you has any problem,; //please mail me.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
allonq | 0:d18f267c677d | 1 | //EE 202 hm2 |
allonq | 0:d18f267c677d | 2 | //This is a program built for the mbed3 in monitoring mode |
allonq | 0:d18f267c677d | 3 | //This code has been tested and should be function, if you has any problem, |
allonq | 0:d18f267c677d | 4 | //please mail me. |
allonq | 0:d18f267c677d | 5 | //Author: Yujing Qian |
allonq | 0:d18f267c677d | 6 | //y.qian42@gmail.com |
allonq | 0:d18f267c677d | 7 | #include "mbed.h" |
allonq | 0:d18f267c677d | 8 | #include "MKL46Z4.h" |
allonq | 0:d18f267c677d | 9 | |
allonq | 0:d18f267c677d | 10 | DigitalOut LED(LED_RED); |
allonq | 0:d18f267c677d | 11 | DigitalOut mbed1(PTD2); |
allonq | 0:d18f267c677d | 12 | DigitalOut mbed2(PTD4); |
allonq | 0:d18f267c677d | 13 | Serial pc(USBTX,USBRX); |
allonq | 0:d18f267c677d | 14 | |
allonq | 0:d18f267c677d | 15 | int loop_num=0; |
allonq | 0:d18f267c677d | 16 | int per_num=0; |
allonq | 0:d18f267c677d | 17 | int Period=0; |
allonq | 0:d18f267c677d | 18 | int t1=0; |
allonq | 0:d18f267c677d | 19 | int t2=0; |
allonq | 0:d18f267c677d | 20 | |
allonq | 0:d18f267c677d | 21 | void TPM0_IRQHandler(void){ |
allonq | 0:d18f267c677d | 22 | loop_num++; |
allonq | 0:d18f267c677d | 23 | if(loop_num==Period){ |
allonq | 0:d18f267c677d | 24 | mbed1=!mbed1; |
allonq | 0:d18f267c677d | 25 | mbed2=!mbed2; |
allonq | 0:d18f267c677d | 26 | LED=!LED; |
allonq | 0:d18f267c677d | 27 | per_num++; |
allonq | 0:d18f267c677d | 28 | loop_num=0; |
allonq | 0:d18f267c677d | 29 | } |
allonq | 0:d18f267c677d | 30 | TPM0->SC|= 0x000000c8; |
allonq | 0:d18f267c677d | 31 | return; |
allonq | 0:d18f267c677d | 32 | } |
allonq | 0:d18f267c677d | 33 | |
allonq | 0:d18f267c677d | 34 | void Initial(){ |
allonq | 0:d18f267c677d | 35 | NVIC_SetVector(TPM0_IRQn, (uint32_t)&TPM0_IRQHandler); |
allonq | 0:d18f267c677d | 36 | NVIC_SetPriority(TPM0_IRQn, 0); |
allonq | 0:d18f267c677d | 37 | loop_num=0; |
allonq | 0:d18f267c677d | 38 | per_num=0; |
allonq | 0:d18f267c677d | 39 | Period=500; |
allonq | 0:d18f267c677d | 40 | LED=1; |
allonq | 0:d18f267c677d | 41 | mbed1=0; |
allonq | 0:d18f267c677d | 42 | mbed2=0; |
allonq | 0:d18f267c677d | 43 | SIM->SOPT2=0x05000000; |
allonq | 0:d18f267c677d | 44 | SIM->SCGC6=0x01000000;//enable TPM 0 |
allonq | 0:d18f267c677d | 45 | |
allonq | 0:d18f267c677d | 46 | TPM0->CNT=0x0; |
allonq | 0:d18f267c677d | 47 | TPM0->SC=0x00000040; |
allonq | 0:d18f267c677d | 48 | TPM0->MOD=0x0000bb80; |
allonq | 0:d18f267c677d | 49 | NVIC_EnableIRQ(TPM0_IRQn); |
allonq | 0:d18f267c677d | 50 | TPM0->SC=0x00000048;//0008 |
allonq | 0:d18f267c677d | 51 | } |
allonq | 0:d18f267c677d | 52 | |
allonq | 0:d18f267c677d | 53 | int main() { |
allonq | 0:d18f267c677d | 54 | Initial(); |
allonq | 0:d18f267c677d | 55 | pc.baud(9600); |
allonq | 0:d18f267c677d | 56 | |
allonq | 0:d18f267c677d | 57 | } |