Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
|
c9dc6e9948 | |
|
34778b7e04 | |
|
5da6bd3219 | |
|
32169dddb9 | |
|
29babf6c47 | |
|
cc60aa9f30 | |
|
8bbde5260e |
|
@ -1,3 +1,6 @@
|
||||||
main.o
|
main.o
|
||||||
main.map
|
main.map
|
||||||
main.elf
|
main.elf
|
||||||
|
pre_built/attiny13_9-6Mhz.hex
|
||||||
|
test_blink/waveform
|
||||||
|
test_blink/main.hex
|
||||||
|
|
47
main.c
47
main.c
|
@ -1,16 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* FileName: *.c
|
* FileName: *.c
|
||||||
* Date: 2023
|
* Date: 2024
|
||||||
* Descripton: Program for Atiny13A controllers, controls DPDT relays and
|
* Descripton: Program for Atiny13A controllers, controls DPDT relays and
|
||||||
* has options to save settings in EEPROM.
|
* has options to save settings in EEPROM.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//#define __AVR_ATtiny13A__
|
||||||
|
|
||||||
#ifndef MCU
|
#ifndef MCU
|
||||||
#define MCU atiny13a
|
#define MCU atiny13a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef F_CPU
|
#ifndef F_CPU
|
||||||
#define F_CPU 4800000UL
|
#define F_CPU 9600000UL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UINT8_MAX
|
#ifndef UINT8_MAX
|
||||||
#define UINT8_MAX 256
|
#define UINT8_MAX 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//This is the bitpattern that should be at address 0x00
|
//This is the bitpattern that should be at address 0x00
|
||||||
|
@ -43,11 +45,7 @@
|
||||||
#define ROM_EP_ADR 0x3
|
#define ROM_EP_ADR 0x3
|
||||||
|
|
||||||
//Debounce check number.
|
//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.
|
|
||||||
//#define DISABLE_TEMPORARY_SWITCH
|
|
||||||
|
|
||||||
#define PIN_SW2 PINB3
|
#define PIN_SW2 PINB3
|
||||||
#define PIN_BYPASS2 PB4
|
#define PIN_BYPASS2 PB4
|
||||||
|
@ -58,25 +56,18 @@
|
||||||
//The BLINK_QTY can be edited from 0-255 blinks
|
//The BLINK_QTY can be edited from 0-255 blinks
|
||||||
#define BLINK_QTY 2
|
#define BLINK_QTY 2
|
||||||
#define BLINK_CNT 2 * BLINK_QTY
|
#define BLINK_CNT 2 * BLINK_QTY
|
||||||
#define BLINK_DELAY 200
|
#define BLINK_DELAY 20
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*The timing of "ticks" is dependent on the AVR timer's counter register
|
/*Assuming default fuses are used then it's approximatly 33.4375ms per tick.
|
||||||
* 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
|
|
||||||
*
|
*
|
||||||
* This is important because the ATiny13/A only have a single timer built into
|
* This is important because the ATiny13/A only have a single timer built into
|
||||||
* them.
|
* them.
|
||||||
*
|
*
|
||||||
* Ticks are used as our way of keep track of long button presses.
|
* Ticks are used as our way of keep track of long button presses.
|
||||||
* */
|
* */
|
||||||
//original sent had 60
|
#define LONG_PRESS_TICKS 32 /*Approximatly 510ms*/
|
||||||
#define LONG_PRESS_TICKS 66
|
|
||||||
|
|
||||||
|
|
||||||
/*A structure to hold the button info*/
|
/*A structure to hold the button info*/
|
||||||
|
@ -107,8 +98,6 @@ volatile uint8_t debounced_state;
|
||||||
volatile uint8_t db_state[MAX_CHECKS];
|
volatile uint8_t db_state[MAX_CHECKS];
|
||||||
volatile uint8_t idx;
|
volatile uint8_t idx;
|
||||||
|
|
||||||
volatile uint16_t tick_count;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ###############################
|
* ###############################
|
||||||
* FUNCTION PROTOTYPES
|
* FUNCTION PROTOTYPES
|
||||||
|
@ -206,15 +195,6 @@ int main()
|
||||||
* ###############################
|
* ###############################
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void inf_blink_test(){
|
|
||||||
DDRB |= (1<<PB3);
|
|
||||||
while(1){
|
|
||||||
PORTB ^= (1<<PB3);
|
|
||||||
_delay_ms(250);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Made heavy use of static inline functions to improve readability.
|
//Made heavy use of static inline functions to improve readability.
|
||||||
|
|
||||||
static inline void blink_bypass1(void)
|
static inline void blink_bypass1(void)
|
||||||
|
@ -374,8 +354,6 @@ static inline void debounce_switch() {
|
||||||
|
|
||||||
/*Setup the timer0 on the AVR*/
|
/*Setup the timer0 on the AVR*/
|
||||||
static inline void init_timer0() {
|
static inline void init_timer0() {
|
||||||
/*Zero out the tick_count var*/
|
|
||||||
tick_count = 0;
|
|
||||||
|
|
||||||
/*config to normal mode.*/
|
/*config to normal mode.*/
|
||||||
TCCR0A = 0x00; //stop timer
|
TCCR0A = 0x00; //stop timer
|
||||||
|
@ -395,18 +373,14 @@ static inline void init_timer0() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//ISR(TIMER0_OVF_vect)
|
|
||||||
|
|
||||||
/*The interrupt service routine for the timer0*/
|
/*The interrupt service routine for the timer0*/
|
||||||
ISR(TIM0_OVF_vect)
|
ISR(TIM0_OVF_vect, ISR_BLOCK)
|
||||||
{
|
{
|
||||||
/*Disable global interrupts*/
|
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
/*Check the state of the switches*/
|
/*Check the state of the switches*/
|
||||||
debounce_switch();
|
debounce_switch();
|
||||||
|
|
||||||
/*Update the tick_count*/
|
|
||||||
if(btn1.timer_enabled && btn1.pressed_ticks <= UINT8_MAX){
|
if(btn1.timer_enabled && btn1.pressed_ticks <= UINT8_MAX){
|
||||||
btn1.pressed_ticks += 1;
|
btn1.pressed_ticks += 1;
|
||||||
}
|
}
|
||||||
|
@ -415,7 +389,6 @@ ISR(TIM0_OVF_vect)
|
||||||
btn2.pressed_ticks += 1;
|
btn2.pressed_ticks += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*Re-Enable global interrupts*/
|
/*Re-Enable global interrupts*/
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
6
makefile
6
makefile
|
@ -7,10 +7,10 @@
|
||||||
# Compiler
|
# Compiler
|
||||||
CC = avr-gcc
|
CC = avr-gcc
|
||||||
|
|
||||||
#Default cpu frequency is 9.8Mhz, 4.8 gives us less power consumption
|
#Default cpu frequency is 9.6Mhz, 4.8 gives us less power consumption
|
||||||
#F_CPU = 1000000UL
|
#F_CPU = 1000000UL
|
||||||
F_CPU = 4800000UL
|
#F_CPU = 4800000UL
|
||||||
#F_CPU = 9800000UL
|
F_CPU = 9600000UL
|
||||||
MCU = attiny13a
|
MCU = attiny13a
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
|
|
Loading…
Reference in New Issue