C51 COMPILER V6.00 SONAR 05/30/2001 17:04:13 PAGE 1 C51 COMPILER 6.00, COMPILATION OF MODULE SONAR OBJECT MODULE PLACED IN .\sonar.OBJ COMPILER INVOKED BY: d:\app\keil\eval\C51\BIN\C51.EXE .\sonar.c BROWSE OBJECTEXTEND DEBUG stmt level source 1 /* sonar.c */ 2 #include "door.h" 3 #include "sonar.h" 4 #include "rf.h" 5 6 /* states and flags */ 7 static unsigned char dist = 0; // count the cycle before echo comes back 8 static unsigned int count = 0; // counter 9 static bit run = 1; 10 static bit echo = 0; 11 char xdata *leda = 0x0f000; // the FPGA is configured to memory map led to this address 12 13 /* fire sonar and do distance calculations; 14 signals serialTask to do RF stuff when user 15 is near by 16 */ 17 void Sonar_Task() { 18 1 /* interrupt settings */ 19 1 EA = 1; 20 1 ET1 = 0; 21 1 ES = 0; 22 1 23 1 /* set timer */ 24 1 TMOD = 0x21; 25 1 PCON = PCON | 0x80; 26 1 TH1 = 249; 27 1 TR1 = 1; 28 1 29 1 /* Set up and enable Timer0 for a 1 millisecond timer */ 30 1 TL0 = RELOAD_LO; /* Load the timer high and low bytes */ 31 1 TH0 = RELOAD_HI; 32 1 TMOD = 0x21; /* Timer1 & Timer0 as 16-bit timers */ 33 1 TR0 = 1; /* Start the timer 0 */ 34 1 ET0 = 1; /* Enable the timer interrupt 0 (Page 55) */ 35 1 EX0 = 0; /* Enable the external interrupt 0 */ 36 1 EA = 1; /* Enable the global interrupt */ 37 1 IT0 = 1; /* Enable the TCON for falling edge trigger */ 38 1 T0 = 0; /* T0 = P3.4 is connected to sonar INIT, pin 68 on the XS40 */ 39 1 count = 0; 40 1 echo = 0; 41 1 PT0 = 1; 42 1 run = 1; 43 1 while (run) { 44 2 } 45 1 }/* end Sonar_Task */ 46 47 48 /* called by Ext0 ISR in DETECTING_USER state */ 49 void Sonar_Ext0_Handler() { // pin 12 50 1 echo = 1; 51 1 }/* end Sonar_Ext0_Handler() */ 52 53 54 /* called by Timer0 ISR in DETECTING_USER state */ 55 void Sonar_Timer0_Handler() { C51 COMPILER V6.00 SONAR 05/30/2001 17:04:13 PAGE 2 56 1 TL0 = TL0 + RELOAD_LO ; // Load the timer high and low bytes 57 1 TH0 = RELOAD_HI; 58 1 count = count + 1; 59 1 if((count >=0) && (count < 60)) // RESET 60 1 { 61 2 EX0 = 0; 62 2 T0 = 0; // init = 0 63 2 dist = 0; 64 2 echo = 0; 65 2 } 66 1 else if((count >= 60) && (count < 1060)) // logic high 67 1 { 68 2 *leda = 0x12; // 1 69 2 T0 = 1; // init = 1 70 2 71 2 if(echo == 0) 72 2 dist = dist + 1; 73 2 else 74 2 { 75 3 ET0 = 0; // disable timer0 interrupt 76 3 EX0 = 0; // disable external interrupt 77 3 IE = 0; /***** Check here later ****/ 78 3 state = REQUESTING_ID; // echo comes back, switch state 79 3 run = 0; 80 3 return; 81 3 } 82 2 if((dist < L_THERSHOLD) || (dist > H_THERSHOLD)) 83 2 { 84 3 IE0 = 0; 85 3 EX0 = 0; 86 3 } 87 2 else 88 2 EX0 = 1; 89 2 } 90 1 else if((count >= 1060) && (count < 11060)) //logic low 91 1 { 92 2 *leda = 0x5D; // 2 93 2 T0 = 0; 94 2 } 95 1 else 96 1 { 97 2 count = 0; 98 2 } 99 1 } /* end Sonar_Timer0_Handler() */ 100 101 /* 102 void print(char c) 103 { 104 SBUF = c; 105 while(TI == 0); 106 TI = 0; 107 } 108 109 void putChar(unsigned char c) { 110 unsigned char a = c/100; 111 unsigned char b = c%100; 112 unsigned char d = b/10; 113 unsigned char e = b%10; 114 print(a+48); 115 print(d+48); 116 print(e+48); 117 } C51 COMPILER V6.00 SONAR 05/30/2001 17:04:13 PAGE 3 118 */ MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 213 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 5 ---- IDATA SIZE = ---- ---- BIT SIZE = 2 ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)