//EE 202 hm2 //This is a program built for the mbed1(master mbed) in generation mode //This code has been tested and should be function, if you has any problem, //please mail me.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
allonq
Date:
Sun Mar 16 08:06:07 2014 +0000
Parent:
2:1c7e1110ac61
Commit message:
//EE 202 hm2; //This is a program built for the mbed1(master mbed) in generation mode; //This code has been tested and should be function, if you has any problem,; //please mail me.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Mar 16 07:17:21 2014 +0000
+++ b/main.cpp	Sun Mar 16 08:06:07 2014 +0000
@@ -1,6 +1,10 @@
-//this is a program built for the master mbed(bed1)
+//EE 202 hm2
+//This is a program built for the mbed1(master mbed) in generation mode
+//This code has been tested and should be function, if you has any problem,
+//please mail me.
+//Author: Yujing Qian
+//y.qian42@gmail.com
 #include "mbed.h"
-//#include "MKL46Z4.h"
 
 #define mod 0x0000bb80 
 #define duty_cycle 0.5
@@ -37,9 +41,9 @@
 uint32_t TIME(){return per_num*Period*48000+loop_num*48000+(TPM0->CNT);}
 
 void receive_handler(){
-    while( uart_bbb.readable() && BBBbuff<BBBbuff_size){
-        BBBbuffer[BBBbuff] =uart_bbb.getc();
-        uart_bbb.putc(BBBbuffer[BBBbuff]);
+    while( pc.readable() && BBBbuff<BBBbuff_size){
+        BBBbuffer[BBBbuff] =pc.getc();
+        pc.putc(BBBbuffer[BBBbuff]);
         //pc.printf(& rx_buffer[buff]);
         if (BBBbuffer[BBBbuff] == '#'){
             BBBbuffer[BBBbuff] = '\0';
@@ -72,7 +76,6 @@
             NVIC_EnableIRQ(TPM1_IRQn);
             // open tpm1           
             uart.putc(0);//send signal to slave
-            //pc.printf("done\n");
     }
 void synchronize(uint32_t Cmd_per){
        
@@ -87,46 +90,23 @@
         uart.putc((*(tmp+2)));//pc.printf("2=%d\n",(*(tmp+2)));
         uart.getc();  
         uart.putc((*(tmp+3)));//pc.printf("3=%d\n",(*(tmp+3)));
-        uart.getc();//clear the buffer
-        // pc.printf("T1.5=%d",TIME()); 
-            
+        uart.getc();//clear the buffer          
             Period=Cmd_per;
-
-            //uart.getc();
-            //int t5=TIME();
-            Syc(calculate_delay());
-            //int t6=TIME();
-            //pc.printf("NOTICE,TIME=%d\n",t6-t5);            
-            loop_num=0;//clear clock 
-                    
+            Syc(calculate_delay());           
+            loop_num=0;//clear clock                    
     }
 
 void TPM0_IRQHandler(void){
-            //syc_cnt++;
+
             loop_num++;
-            //pc.printf("ln=%d",loop_num);
+
             if(loop_num==Period){
                 out=!out;
                 LED=!LED;
                 per_num++;
                 loop_num=0;
-                //syc_cnt=0;
-        //if((TPM0->SC & 0x0080)==0x0080){
-            
-            //pc.printf("MOD=%d",TPM0->MOD);
-            //pc.printf("SC=%d",TPM0->SC);
-            //pc.printf("Global_time=%d\n",TIME());
-            //pc.printf("Global_time=%f\n",(float)(TIME()%48000));
-            //pc.printf("out=%d\n",out);
-            //pc.printf(": %d\n",TPM0->CNT);
             }
-            //else if(flag&&(syc_cnt>=syc_interval)){
-                //Syc(calculate_delay());syc_cnt=0;  
-                //}
             TPM0->SC|= 0x000000c8;
-            //NVIC_ClearPendingIRQ(TPM0_IRQn); 
-            //pc.printf("SC_after=%d\n",TPM0->SC);
-            //}//pc.printf("count=%d",TPM0->CNT);
             
             return;               
     }
@@ -134,11 +114,7 @@
 void TPM1_IRQHandler(void){// time to restart the system           
             LED=1;
             //TPM0->SC= 0x000000c8;        
-            TPM0->CNT=0x0;
-            //TPM0->SC=0x00000048;
-            //NVIC_EnableIRQ(TPM0_IRQn);
-            //pc.printf("AfterMOD=%d\n",TPM0->MOD);
-            //LED=1;           
+            TPM0->CNT=0x0;           
             TPM1->CNT=0x0;
             //pc.printf("SC=%d",TPM1->SC);
             TPM1->SC= 0x00000080;  
@@ -175,12 +151,12 @@
 int main() {
     loop_num=0;
     cmd_received=false;
-    uart_bbb.attach(&receive_handler);    
+    pc.attach(&receive_handler);    
     int CMD_Per=0;
     Initial();
     
-    uart_bbb.baud(9600);
-    uart_bbb.attach(&receive_handler);
+    pc.baud(9600);
+    pc.attach(&receive_handler);
     
     uart.baud(9600);
     pc.baud(9600);
@@ -211,8 +187,6 @@
             cmd_received=false;
             BBBbuff=0;
             Period=CMD_Per;
-            //pc.printf("before_syc");
-                //pc.printf("set=%d\n",state);
             uart.putc('#');     
             synchronize(CMD_Per);
             CMD_Per=0;