00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "pic_timer.h"
00038
00039 #ifdef _PIC18
00040 uns16 timer_0_start_value = 0;
00041 #endif
00042 #ifdef _PIC16
00043 uns8 timer_0_start_value = 0;
00044 #endif;
00045
00046 #ifdef _PIC18
00047 void timer_setup_0(bit mode_8_bit, uns8 prescaler_setting, uns16 timer_start_value) {
00048
00049 clear_bit(t0con, TMR0ON);
00050 if (mode_8_bit) {
00051 set_bit(t0con, T08BIT);
00052 } else {
00053 clear_bit(t0con, T08BIT);
00054 }
00055 clear_bit(t0con, T0CS);
00056
00057 if (prescaler_setting == TIMER_PRESCALER_OFF) {
00058 set_bit(t0con, PSA);
00059 } else {
00060 clear_bit(t0con, PSA);
00061 t0con &= 0b11111000;
00062 t0con |= prescaler_setting;
00063 }
00064 timer_0_start_value = timer_start_value;
00065 set_bit(intcon, TMR0IE);
00066 }
00067 #endif
00068
00069 #ifdef _PIC16
00070
00071 void timer_setup_0(bit mode_8_bit, uns8 prescaler_setting, uns16 timer_start_value) {
00072
00073 clear_bit( option_reg, T0CS );
00074
00075 if (prescaler_setting == TIMER_PRESCALER_OFF) {
00076 set_bit(option_reg, PSA);
00077 } else {
00078 clear_bit(option_reg, PSA);
00079 option_reg &= 0b11111000;
00080 option_reg |= prescaler_setting;
00081 }
00082 timer_0_start_value = timer_start_value;
00083 }
00084 #endif
00085
00086 #ifdef _PIC18
00087 void timer_start_0() {
00088 tmr0h = timer_0_start_value >> 8;
00089 tmr0l = timer_0_start_value & 0xff;
00090 set_bit(t0con, TMR0ON);
00091 }
00092 #endif
00093
00094 #ifdef _PIC16
00095 void timer_start_0() {
00096 tmr0 = timer_0_start_value;
00097
00098 set_bit(intcon, TMR0IE);
00099 }
00100 #endif
00101
00102 #ifdef _PIC18
00103 void timer_stop_0() {
00104 clear_bit(t0con, TMR0ON);
00105 }
00106 #endif
00107 #ifdef _PIC16
00108 void timer_stop_0() {
00109 clear_bit(intcon, TMR0IE);
00110 }
00111 #endif
00112