From 32169dddb9987f843adf448c5aa81d832d4c3139 Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Wed, 22 May 2024 18:23:37 -0700 Subject: [PATCH] updated date, F_CPU, MAX_CHECKS and removed other code. --- main.c | 54 +++++++++++------------------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/main.c b/main.c index 2b3f5c3..d2b7b80 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ /* * FileName: *.c - * Date: 2023 + * Date: 2024 * Descripton: Program for Atiny13A controllers, controls DPDT relays and * has options to save settings in EEPROM. */ @@ -10,7 +10,7 @@ #endif #ifndef F_CPU -#define F_CPU 4800000UL +#define F_CPU 9600000UL #endif @@ -29,11 +29,7 @@ #endif #ifndef UINT8_MAX -#define UINT8_MAX 256 -#endif - -#ifndef UINT16_MAX -#define UINT16_MAX 65536 +#define UINT8_MAX 256 #endif //This is the bitpattern that should be at address 0x00 @@ -47,7 +43,7 @@ #define ROM_EP_ADR 0x3 //Debounce check number. -#define MAX_CHECKS 10 +#define MAX_CHECKS 5 // Define DISABLE_TEMPORARY_SWITCH to turn off the ability to hold // the switch to temporarily engage/bypass. @@ -66,25 +62,14 @@ -/*The timing of "ticks" is dependent on the AVR timer's counter register - * so for an 8bit register the maximum value is 256. Given we stick with - * a 1Mhz cpu frequency can use this formula to calculate the number of - * interrupts(timer overflows) per second: - * - * OVF_S = (F_CPU / DIV)/ (2^8) - * 61 = (1000000 / 64) / 256 - * - * for a 4.8MHz setup. - * OVF_S = (48000000 / 64) / 256 = 2929.6875 - * - *so 0.510S = 510ms means we need about 1493 overflows or ticks +/*Assuming default fuses are used then it's approximatly 33.4375ms per tick. * * This is important because the ATiny13/A only have a single timer built into * them. * * Ticks are used as our way of keep track of long button presses. * */ -#define LONG_PRESS_TICKS 1493 +#define LONG_PRESS_TICKS 32 /*Approximatly 510ms*/ /*A structure to hold the button info*/ @@ -93,7 +78,7 @@ typedef struct { uint8_t is_bypassed: 1; uint8_t is_long_pressed: 1; uint8_t timer_enabled: 1; - uint16_t pressed_ticks; + uint8_t pressed_ticks; uint8_t input_pin; uint8_t output_pin; }btn_state; @@ -115,8 +100,6 @@ volatile uint8_t debounced_state; volatile uint8_t db_state[MAX_CHECKS]; volatile uint8_t idx; -volatile uint16_t tick_count; - /* * ############################### * FUNCTION PROTOTYPES @@ -151,7 +134,7 @@ void init_prog() init_btn(&btn2, PIN_SW2, PIN_BYPASS2); /*Wait 5ms for pull-up resistors voltage to become stable.*/ - _delay_ms(5); + //_delay_ms(5); /*check if the eeprom has info. */ while(! eeprom_is_ready()) {} //Blocks until eeprom is ready. @@ -214,15 +197,6 @@ int main() * ############################### */ -void inf_blink_test(){ - DDRB |= (1<