Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "timer.h"
00022
00023 void T0Init(int ms)
00024 {
00025 T0TCR = 0;
00026 T0TCR = 2;
00027 T0PR = (CPU_CLOCK_HZ*ms/4000) - 1;
00028 T0TCR = 0;
00029 }
00030
00031 void T0Stop()
00032 {
00033 T0TCR = 0;
00034 }
00035 void T0Start()
00036 {
00037 T0TCR = 1;
00038 }
00039
00040 int T0Get()
00041 {
00042 return T0TC;
00043 }
00044
00045 void delayMs(unsigned int delayInMs)
00046 {
00047
00048
00049
00050 T1TCR = 0x02;
00051 T1PR = (CPU_CLOCK_HZ/4000 -1);
00052 T1MR0 = delayInMs;
00053 T1IR = 0xff;
00054 T1MCR = 0x04;
00055 T1TCR = 0x01;
00056
00057
00058 while (T1TCR & 0x01);
00059 return;
00060 }
00061
00062 void delayUs(unsigned int delayInUs)
00063 {
00064
00065
00066
00067 T2TCR = 0x02;
00068 T2PR = (CPU_CLOCK_HZ/4000000 -1);
00069 T2MR0 = delayInUs;
00070 T2IR = 0xff;
00071 T2MCR = 0x04;
00072 T2TCR = 0x01;
00073
00074
00075 while (T2TCR & 0x01);
00076 return;
00077 }
00078
00079 int timeoutMs(unsigned int delayInMs, unsigned int condition)
00080 {
00081 switch(condition)
00082 {
00083 case START:
00084 T1TCR = 0x02;
00085 T1PR = (CPU_CLOCK_HZ/4000 -1);
00086 T1MR0 = delayInMs;
00087 T1IR = 0xff;
00088 T1MCR = 0x04;
00089 T1TCR = 0x01;
00090 break;
00091
00092 case CHECK_IF_MATCH:
00093 if (T1TCR&0x01) return NOT_MATCH;
00094 else return MATCH;
00095
00096 }
00097
00098 return 1;
00099 }
00100
00101 void delay_1us(int t)
00102 {
00103 unsigned int tf;
00104 tf = T0TC + t;
00105 while(tf != T0TC);
00106 }
00107
00108
00109
00110