; ; Project name: thermostat ; Description: Electronic thermostat on AVR Microcontroller ; Source code: https://github.com/sergeyyarkov/attiny2313a_thermostat ; Device: ATtiny2313A ; Device Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/doc8246.pdf ; Package: SOIC-20W_7.5x12.8mm_P1.27mm ; Assembler: AVR macro assembler 2.2.7 ; Clock frequency: 8 MHz External Crystal Oscillator ; Fuses: lfuse: 0xCF, hfuse: 0x9F, efuse: 0xFF, lock: 0xFF ; ; Written by Sergey Yarkov 22.01.2023 .INCLUDE "tn2313Adef.inc" .LIST .DEF TEMP_REG_A = r16 .DEF TEMP_REG_B = r17 ;========================================; ; LABELS ; ;========================================; .EQU DIGIT_1_PIN = PD2 .EQU DIGIT_2_PIN = PD3 .EQU DIGIT_3_PIN = PD4 .EQU DIGIT_4_PIN = PD5 .EQU LED_POWER_PIN = PD6 .EQU USI_LATCH_PIN = PB0 ; ST_CP on 74HC595 .EQU USI_DO_PIN = PB6 ; DS on 74HC595 .EQU USI_CLK_PIN = PB7 ; SH_CP on 74HC595 .EQU MCU_STATE_DEFAULT = 0x01 ; Temperature measurement and threshold comparison .EQU MCU_STATE_PROGRAM = 0x02 ; Write settings of hysteresis into EEPROM .EQU MCU_STATE_ERROR = 0x03 ; Cannot read data from temp sensor or something else ;========================================; ; DATA SEGMENT ; ;========================================; .DSEG .ORG SRAM_START MCU_STATE: .BYTE 1 DISPLAY_DIGIT: .BYTE 4 ;========================================; ; CODE SEGMENT ; ;========================================; .CSEG .ORG 0x00 ;========================================; ; VECTORS ; ;========================================; rjmp RESET_vect ; Program start at RESET vector ;reti ; External Interrupt Request 0 / inactive ;reti ; External Interrupt Request 1 / inactive ;reti ; Timer/Counter1 Capture Event / inactive ;reti ; Timer/Counter1 Compare Match A / inactive ;reti ; Timer/Counter1 Overflow / inactive ;reti ; Timer/Counter0 Overflow / inactive ;reti ; USART0, Rx Complete / inactive ;reti ; USART0 Data Register Empty / inactive ;reti ; USART0, Tx Complete / inactive ;reti ; Analog Comparator / inactive ;reti ; Pin Change Interrupt Request 0/ inactive ;reti ; Timer/Counter1 Compare Match B / inactive ;reti ; Timer/Counter0 Compare Match A / inactive ;reti ; Timer/Counter0 Compare Match B / inactive ;reti ; USI Start Condition/ inactive ;reti ; USI Overflow / inactive ;reti ; EEPROM Ready/ inactive ;reti ; Watchdog Timer Overflow / inactive ;reti ; Pin Change Interrupt Request 1 / inactive ;reti ; Pin Change Interrupt Request 2 / inactive RESET_vect: ;========================================; ; INITIALIZE STACK POINTER ; ;========================================; ldi TEMP_REG_A, LOW(RAMEND) out SPL, TEMP_REG_A MCU_INIT: ;=======================================================; ; INITIALIZE PORTS ; ; ; ; POWER LED <-------------> OUT PD6 ; ; - This LED is used to indicate that device ; ; is working correctly ; ; 7SEG DIGIT 1 <-------------> OUT PD2 ; ; 7SEG DIGIT 2 <-------------> OUT PD3 ; ; 7SEG DIGIT 3 <-------------> OUT PD4 ; ; 7SEG DIGIT 4 <-------------> OUT PD5 ; ; ; ; USI CLOCK PIN <-------------> OUT PB0 ; ; USI DATA OUT PIN <-------------> OUT PB6 ; ; USI LATCH PIN <-------------> OUT PB7 ; ;=======================================================; ldi r16, (1< USI Wire Mode ; USICS1 <--------------> USI Clock Source Select ; USICLK <--------------> USI Clock Strobe ; USITC <--------------> USI Toggle Clock (Enable clock generation) ldi TEMP_REG_A, (1<