00001
00016 #include "pic_utils.h"
00017
00019 #define TIMER_16BIT_MODE 0
00020
00021 #define TIMER_8BIT_MODE 1
00022
00023 #define TIMER_PRESCALER_OFF 0xff
00024 #define TIMER_PRESCALER_1_TO_2 0x00
00025 #define TIMER_PRESCALER_1_TO_4 0x01
00026 #define TIMER_PRESCALER_1_TO_8 0x02
00027 #define TIMER_PRESCALER_1_TO_16 0x03
00028 #define TIMER_PRESCALER_1_TO_32 0x04
00029 #define TIMER_PRESCALER_1_TO_64 0x05
00030 #define TIMER_PRESCALER_1_TO_128 0x06
00031 #define TIMER_PRESCALER_1_TO_256 0x07
00032
00033
00034 #ifdef _PIC18
00035 extern uns16 timer_0_start_value;
00036 #endif
00037
00038 #ifdef _PIC16
00039 extern uns8 timer_0_start_value;
00040 #endif
00041
00048 void timer_setup_0(bit mode_16_bit, uns8 prescaler_setting, uns16 timer_start_value);
00049
00056 void timer_start_0();
00057
00064 void timer_stop_0();
00065
00074 extern void timer_0_callback();
00075
00083 #ifdef _PIC18
00084 inline void timer_handle_0_isr() {
00085 uns16 start_value;
00086 if (test_bit(intcon, TMR0IF)) {
00087 start_value = + tmr0l + timer_0_start_value + 1;
00088 tmr0h = start_value >> 8;
00089 tmr0l = start_value & 0xff;
00090 clear_bit( intcon, TMR0IF );
00091 timer_0_callback();
00092 }
00093 }
00094 #endif
00095
00096 #ifdef _PIC16
00097 inline void timer_handle_0_isr() {
00098 uns8 start_value;
00099 if (test_bit(intcon, TMR0IF)) {
00100 start_value = + tmr0 + timer_0_start_value + 1;
00101 tmr0 = start_value;
00102 clear_bit( intcon, TMR0IF );
00103 timer_0_callback();
00104 }
00105 }
00106 #endif
00107
00108
00109