@@ -349,6 +349,11 @@ SIGHANDLERNAKED(_tmr0_handler)
349349}
350350// clang-format on
351351
352+ /// Interval (in seconds) that separates two LM35 samples.
353+ #define TEMPERATURE_INTERVAL 4
354+ /// Last LM35 measurement, in Celsius degrees.
355+ static int _temperature = 0 ;
356+
352357/* PWM 2.44khz@50 (Fosc=8mhz) */
353358#define CCP1_PR2 0xcb
354359#define CCP1_R 0x066
@@ -391,6 +396,8 @@ void uc_init(void) {
391396
392397 INTCON2bits .INTEDG0 = 0 ; // INT0 triggered on falling edge
393398 INTCONbits .INT0IE = 1 ;
399+
400+ _temperature = lm35_get ();
394401}
395402
396403/// Return the day of the week for the given date, i.e. 0 - Sunday, 1 - Monday,
@@ -581,7 +588,7 @@ void S_temp(char arg, __data char *input) /* __wparam */
581588 (void )arg ;
582589 if (input == (__data char * )NULL ) {
583590 LEDMTX_HOME ();
584- printf (STR_FMT_TEMP , lm35_get () );
591+ printf (STR_FMT_TEMP , _temperature );
585592 } else if (* input == B_MODE ) {
586593 _state = STATE_ALARM ;
587594
@@ -811,6 +818,7 @@ static state_func_t __code _state_fn[] = {
811818void main (void ) {
812819 static char c ;
813820 static unsigned char rcounter = 0xff ;
821+ static unsigned char temp_measurement_sched_sec = 0 ;
814822
815823 /* initialisation */
816824 uc_init ();
@@ -824,11 +832,16 @@ void main(void) {
824832
825833 /* main loop */
826834 while (1 ) {
835+ if (_time .sec >= temp_measurement_sched_sec ) {
836+ _temperature = lm35_get ();
837+ temp_measurement_sched_sec =
838+ (temp_measurement_sched_sec + TEMPERATURE_INTERVAL ) % 60 ;
839+ }
840+
827841 if (++ rcounter == 0 ) {
828842 rcounter = 0x51 ; // Should overflow in roughly 0.5s
829843 _state_fn [_state ](MESSAGE_CLASS (c ), NULL );
830844 }
831-
832845 c = rbuf_get (_mbuf );
833846 if (c != -1 ) {
834847 switch (c ) {
0 commit comments