1
0
mirror of https://github.com/halleysfifthinc/Toyota-AVC-LAN synced 2025-06-09 17:06:26 +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" #include "GlobalDef.h"
#define STOPEvent cbi(TIMSK1, TOIE1); cbi(UCSR0B, RXCIE0); #define STOPEvent cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(UCSR0B, RXCIE0);
#define STARTEvent sbi(TIMSK1, TOIE1); sbi(UCSR0B, RXCIE0); #define STARTEvent sbi(RTC.PITINTCTRL, RTC_PI_bp); sbi(UCSR0B, RXCIE0);
#define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message(); #define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message();

View File

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