00001
00016 #include "pic_timer.h"
00017
00018 #ifdef _PIC18
00019 uns16 timer_0_start_value = 0;
00020 #endif
00021 #ifdef _PIC16
00022 uns8 timer_0_start_value = 0;
00023 #endif;
00024
00025 #ifdef _PIC18
00026 void timer_setup_0(bit mode_8_bit, uns8 prescaler_setting, uns16 timer_start_value) {
00027
00028 clear_bit(t0con, TMR0ON);
00029 if (mode_8_bit) {
00030 set_bit(t0con, T08BIT);
00031 } else {
00032 clear_bit(t0con, T08BIT);
00033 }
00034 clear_bit(t0con, T0CS);
00035
00036 if (prescaler_setting == TIMER_PRESCALER_OFF) {
00037 set_bit(t0con, PSA);
00038 } else {
00039 clear_bit(t0con, PSA);
00040 t0con &= 0b11111000;
00041 t0con |= prescaler_setting;
00042 }
00043 timer_0_start_value = timer_start_value;
00044 set_bit(intcon, TMR0IE);
00045 }
00046 #endif
00047
00048 #ifdef _PIC16
00049
00050 void timer_setup_0(bit mode_8_bit, uns8 prescaler_setting, uns16 timer_start_value) {
00051
00052 clear_bit( option_reg, T0CS );
00053
00054 if (prescaler_setting == TIMER_PRESCALER_OFF) {
00055 set_bit(option_reg, PSA);
00056 } else {
00057 clear_bit(option_reg, PSA);
00058 option_reg &= 0b11111000;
00059 option_reg |= prescaler_setting;
00060 }
00061 timer_0_start_value = timer_start_value;
00062 }
00063 #endif
00064
00065 #ifdef _PIC18
00066 void timer_start_0() {
00067 tmr0h = timer_0_start_value >> 8;
00068 tmr0l = timer_0_start_value & 0xff;
00069 set_bit(t0con, TMR0ON);
00070 }
00071 #endif
00072
00073 #ifdef _PIC16
00074 void timer_start_0() {
00075 tmr0 = timer_0_start_value;
00076
00077 set_bit(intcon, TMR0IE);
00078 }
00079 #endif
00080
00081 #ifdef _PIC18
00082 void timer_stop_0() {
00083 clear_bit(t0con, TMR0ON);
00084 }
00085 #endif
00086 #ifdef _PIC16
00087 void timer_stop_0() {
00088 clear_bit(intcon, TMR0IE);
00089 }
00090 #endif
00091