Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 146 → Rev 147

/PIC Stuff/PIC_27J13/timers.c
1,57 → 1,35
/* The processor calls these handlers when an interrupt is triggered */
#include "maindefs.h"
#include <timers.h>
#include "defines.h"
#include "timers.h"
 
void timers_init() {
/*--------------------Timer Delay Formulas-------------------- */
/* InitTMR0 = 256 - ( Delay * Frequency ) / ( 4* Prescaler) */
/* Delay = (256 - InitTMR0 * Prescaler) / (Frequency / 4) */
/* ----------------------------------------------------------- */
void Timer1_Init(void) {
T1CONbits.TMR1CS = 0x2; // Clock source using T1OSC and T1CLK pins
T1CONbits.RD16 = 0x1; // Configure for 16-bit read/writes
T1CONbits.T1OSCEN = 0x1; // Enable crystal driver
PIE1bits.TMR1IE = 0x1; // Enable interrupt
 
OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_16);
T0CONbits.TMR0ON = 0; // Timer 0 initially off
 
// // Set timer 1 to overflow every two seconds
// OpenTimer1(TIMER_INT_ON & T1_16BIT_RW &
// T1_SOURCE_PINOSC & T1_PS_1_1 &
// T1_OSC1EN_ON & T1_SYNC_EXT_OFF,
// TIMER_GATE_OFF & TIMER_GATE_INT_OFF);
// Open timer 2 for ECCP1 (PWM)
OpenTimer2(TIMER_INT_OFF & T2_PS_1_4 & T2_POST_1_1);
 
// Open timer 3 for PWM IR signaling
OpenTimer3(TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_FOSC_4 &
T3_OSC1EN_OFF & T3_PS_1_1 & T3_SYNC_EXT_OFF, TIMER_GATE_OFF);
T3CONbits.TMR3ON = 0; // Timer 3 initially off
// Non-applicable settings
T1CONbits.T1CKPS = 0x0; // 1:1 prescale value
T1CONbits.NOT_T1SYNC = 0x1; // No external sync
T1GCONbits.TMR1GE = 0x0; // Disable gate control
}
 
// Interrupt handler for timer 0
void timer0_interrupt_handler() {
void Timer1_Enable(void) {
T1CONbits.TMR1ON = 1;
}
 
void timer0_enable() {
T0CONbits.TMR0ON = 1;
void Timer1_Disable(void) {
T1CONbits.TMR1ON = 0;
}
void timer0_disable() {
T0CONbits.TMR0ON = 0;
}
 
// Interrupt handler for timer 1
void timer1_interrupt_handler() {
}
 
void timer3_interrupt_handler() {
 
}
 
void timer3_enable() {
T3CONbits.TMR3ON = 1;
}
void timer3_disable() {
T3CONbits.TMR3ON = 0;
}
void Timer1_Interrupt_Handler(void) {
#ifdef _TEST_TIMER1_RTC
TMR1H = 0x7F;
TMR1L = 0xFF;
LED_BLUE_LAT = 1;
LED_RED_LAT = 1;
Delay10KTCYx(255);
LED_BLUE_LAT = 0;
LED_RED_LAT = 0;
#endif
}