1
0
mirror of https://github.com/halleysfifthinc/Toyota-AVC-LAN synced 2025-06-09 08:56:16 +00:00

Replace Timer1 with periodic interrupt timer from the RTC

This commit is contained in:
Allen Hill 2023-08-02 21:56:59 -04:00
parent 49ceb1e5e8
commit 0a9bd4d988
2 changed files with 22 additions and 27 deletions

View File

@ -33,8 +33,8 @@
//------------------------------------------------------------------------------
#include "GlobalDef.h"
#define STOPEvent cbi(TIMSK1, TOIE1); cbi(UCSR0B, RXCIE0);
#define STARTEvent sbi(TIMSK1, TOIE1); sbi(UCSR0B, RXCIE0);
#define STOPEvent cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(UCSR0B, RXCIE0);
#define STARTEvent sbi(RTC.PITINTCTRL, RTC_PI_bp); sbi(UCSR0B, RXCIE0);
#define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message();

View File

@ -223,12 +223,12 @@ void Setup()
MCUCR = 0;
// Timer 1
TIMSK1 = 0;
sbi(TIMSK1, OCIE1A); // Enable timer1 compare interrupt
TCCR1A = 0;
TCCR1B |= (1 << WGM12)|(1 << CS12); // Set CTC, prescaler at 256
OCR1A = 62499; // Compare match at 1sec intervals
loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp);
RTC.CTRLA = RTC_PRESCALER_DIV1_gc;
RTC.CLKSEL = RTC_CLKSEL_INT32K_gc;
RTC.PITINTCTRL = RTC_PI_bm;
loop_until_bit_is_clear(RTC_PITSTATUS, RTC_CTRLBUSY_bp);
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
RS232_Init();
@ -244,24 +244,19 @@ void Setup()
// -------------------------------------------------------------------------------------
byte s1=0;
//------------------------------------------------------------------------------
ISR(TIMER1_COMPA_vect) // Timer1 compare match every 1Sec
ISR(RTC_PIT_vect) // Periodic interrupt with a 1 sec period
{
s1++;
if (s1==2) {
s1=0;
if (CD_Mode==stPlay) {
cd_Time_Sec=HexInc(cd_Time_Sec);
if (CD_Mode==stPlay)
{
cd_Time_Sec=incBCD(cd_Time_Sec);
if (cd_Time_Sec==0x60) {
cd_Time_Sec = 0;
cd_Time_Min=HexInc(cd_Time_Min);
cd_Time_Min=incBCD(cd_Time_Min);
if (cd_Time_Min==0xA0) {
cd_Time_Min=0x0;
}
}
}
Event |= EV_STATUS;
RTC.PITINTFLAGS |= RTC_PI_bm;
}
}
}
//------------------------------------------------------------------------------