From 2b1f5bb754a23063e23ba875cb433164def59716 Mon Sep 17 00:00:00 2001 From: sergeyyarkov Date: Thu, 20 Apr 2023 00:26:54 +0300 Subject: [PATCH] dynamic indication --- .vscode/tasks.json | 28 ++ div16u.asm | 50 ++++ firmware.asm | 324 +++++++++++----------- firmware.eep | 5 - firmware.hex | 36 ++- firmware.lss | 544 +++++++++++++++++++------------------ firmware.lst | 652 +++++++++++++++++++++++++++------------------ firmware.pro | 10 +- usi.asm | 28 ++ 9 files changed, 959 insertions(+), 718 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 div16u.asm delete mode 100644 firmware.eep create mode 100644 usi.asm diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c12ef37 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "label": "Compile", + "type": "shell", + "group": "build", + "command": "make", + "problemMatcher": [] + }, + { + "label": "Clean", + "type": "shell", + "group": "build", + "command": "make", + "args": ["clean"], + "problemMatcher": [] + }, + { + "label": "Flash", + "type": "shell", + "group": "build", + "command": "make", + "args": ["flash"], + "problemMatcher": [] + } + ], + "version": "2.0.0" +} diff --git a/div16u.asm b/div16u.asm new file mode 100644 index 0000000..545085e --- /dev/null +++ b/div16u.asm @@ -0,0 +1,50 @@ +;*************************************************************************** +;* +;* "div16u" - 16/16 Bit Unsigned Division +;* +;* This subroutine divides the two 16-bit numbers +;* "dd8uH:dd8uL" (dividend) and "dv16uH:dv16uL" (divisor). +;* The result is placed in "dres16uH:dres16uL" and the remainder in +;* "drem16uH:drem16uL". +;* +;* Number of words :19 +;* Number of cycles :235/251 (Min/Max) +;* Low registers used :2 (drem16uL,drem16uH) +;* High registers used :5 (dres16uL/dd16uL,dres16uH/dd16uH,dv16uL,dv16uH, +;* dcnt16u) +;* +;*************************************************************************** + +;***** Subroutine Register Variables + +.def drem16uL=r14 +.def drem16uH=r15 +.def dres16uL=r16 +.def dres16uH=r17 +.def dd16uL =r16 +.def dd16uH =r17 +.def dv16uL =r18 +.def dv16uH =r19 +.def dcnt16u =r20 + +;***** Code + +div16u: clr drem16uL ;clear remainder Low byte + sub drem16uH,drem16uH;clear remainder High byte and carry + ldi dcnt16u,17 ;init loop counter +d16u_1: rol dd16uL ;shift left dividend + rol dd16uH + dec dcnt16u ;decrement counter + brne d16u_2 ;if done + ret ; return +d16u_2: rol drem16uL ;shift dividend into remainder + rol drem16uH + sub drem16uL,dv16uL ;remainder = remainder - divisor + sbc drem16uH,dv16uH ; + brcc d16u_3 ;if result negative + add drem16uL,dv16uL ; restore remainder + adc drem16uH,dv16uH + clc ; clear carry to be shifted into result + rjmp d16u_1 ;else +d16u_3: sec ; set carry to be shifted into result + rjmp d16u_1 \ No newline at end of file diff --git a/firmware.asm b/firmware.asm index 7ce3651..14d0ab6 100644 --- a/firmware.asm +++ b/firmware.asm @@ -17,10 +17,6 @@ .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 @@ -32,200 +28,181 @@ .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 +.EQU MCU_STATE_DEFAULT = 0x01 ; Режим измерения температуры и сравнения с заданными параметрами +.EQU MCU_STATE_PROGRAM = 0x02 ; Режим настройки параметров в EEPROM +.EQU MCU_STATE_ERROR = 0x03 ; Режим ошибки, например когда не подключен датчик -;========================================; -; DATA SEGMENT ; -;========================================; +; **** СЕГМЕНТ ДАННЫХ ******************************************** .DSEG .ORG SRAM_START -MCU_STATE: .BYTE 1 -DISPLAY_DIGIT: .BYTE 4 - -;========================================; -; CODE SEGMENT ; -;========================================; +MCU_STATE: .BYTE 1 ; Текущее состояние МК +NUMBER: .BYTE 2 +DIGITS: .BYTE 4 ; Ячейки, где хранятся символы, для вывода на индикатор +CURRENT_DIGIT: .BYTE 1 ; Номер разряда индикатора, который сейчас горит +; **** СЕГМЕНТ КОДА ********************************************** .CSEG -.ORG 0x00 -;========================================; -; VECTORS ; -;========================================; +.ORG 0x00 + rjmp RESET_vect -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 +.ORG 0x000D + rjmp TIMER0_COMPA_vect + +; **** ДИНАМИЧЕСКАЯ ИНДИКАЦИЯ ************************************ +TIMER0_COMPA_vect: + lds r20, CURRENT_DIGIT + cpi r20, 5 + brge reset_digit_idx + rjmp _indicate_1 + + reset_digit_idx: + clr r20 + sts CURRENT_DIGIT, r20 + + _indicate_1: + cpi r20, 0 + brne _indicate_2 + + cbi PORTD, DIGIT_2_PIN + cbi PORTD, DIGIT_3_PIN + cbi PORTD, DIGIT_4_PIN + sbi PORTD, DIGIT_1_PIN + lds TEMP_REG_A, DIGITS+3 + rcall DISPLAY_DECODER + rcall USI_TRANSMIT + + _indicate_2: + cpi r20, 1 + brne _indicate_3 + + cbi PORTD, DIGIT_1_PIN + cbi PORTD, DIGIT_3_PIN + cbi PORTD, DIGIT_4_PIN + sbi PORTD, DIGIT_2_PIN + lds TEMP_REG_A, DIGITS+2 + rcall DISPLAY_DECODER + rcall USI_TRANSMIT + + _indicate_3: + cpi r20, 2 + brne _indicate_4 + + cbi PORTD, DIGIT_1_PIN + cbi PORTD, DIGIT_2_PIN + cbi PORTD, DIGIT_4_PIN + sbi PORTD, DIGIT_3_PIN + lds TEMP_REG_A, DIGITS+1 + rcall DISPLAY_DECODER + rcall USI_TRANSMIT + + _indicate_4: + cpi r20, 3 + brne _indicate_exit + + cbi PORTD, DIGIT_1_PIN + cbi PORTD, DIGIT_2_PIN + cbi PORTD, DIGIT_3_PIN + sbi PORTD, DIGIT_4_PIN + lds TEMP_REG_A, DIGITS + rcall DISPLAY_DECODER + rcall USI_TRANSMIT + + _indicate_exit: + inc r20 + sts CURRENT_DIGIT, r20 +reti 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< 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 ; - ;=======================================================; -000003 e70c ldi r16, (1< USI Clock Source Select ; USICLK <--------------> USI Clock Strobe ; USITC <--------------> USI Toggle Clock (Enable clock generation) -00001a e10b ldi TEMP_REG_A, (1< Warning 009: Include defs not necessary, using internal values! - File: /home/sergeyyarkov/Documents/Applications/attiny2313a_thermostat/firmware.asm, Line: 14 + File: /home/sergeyyarkov/Documents/Projects/Firmwares/AVR/attiny2313a_thermostat/firmware.asm, Line: 14 Source line: .INCLUDE "tn2313Adef.inc" 15: .LIST 16: 17: .DEF TEMP_REG_A = r16 18: .DEF TEMP_REG_B = r17 19: - 20: ;========================================; - 21: ; LABELS ; - 22: ;========================================; - 23: - 24: .EQU DISPLAY_1_PIN = PD2 - 25: .EQU DISPLAY_2_PIN = PD3 - 26: .EQU DISPLAY_3_PIN = PD4 - 27: .EQU DISPLAY_4_PIN = PD5 - 28: - 29: .EQU LED_POWER_PIN = PD6 + 20: .EQU DIGIT_1_PIN = PD2 + 21: .EQU DIGIT_2_PIN = PD3 + 22: .EQU DIGIT_3_PIN = PD4 + 23: .EQU DIGIT_4_PIN = PD5 + 24: + 25: .EQU LED_POWER_PIN = PD6 + 26: + 27: .EQU USI_LATCH_PIN = PB0 ; ST_CP on 74HC595 + 28: .EQU USI_DO_PIN = PB6 ; DS on 74HC595 + 29: .EQU USI_CLK_PIN = PB7 ; SH_CP on 74HC595 30: - 31: .EQU USI_LATCH_PIN = PB0 ; ST_CP on 74HC595 - 32: .EQU USI_DO_PIN = PB6 ; DS on 74HC595 - 33: .EQU USI_CLK_PIN = PB7 ; SH_CP on 74HC595 + 31: .EQU MCU_STATE_DEFAULT = 0x01 ; Режим измерения температуры и сравнения с заданными параметрами + 32: .EQU MCU_STATE_PROGRAM = 0x02 ; Режим настройки параметров в EEPROM + 33: .EQU MCU_STATE_ERROR = 0x03 ; Режим ошибки, например когда не подключен датчик 34: - 35: ;========================================; - 36: ; DATA SEGMENT ; - 37: ;========================================; - 38: .DSEG - 39: .ORG SRAM_START - 40: - 41: DISPLAY_DIGIT: .BYTE 4 - 42: - 43: ;========================================; - 44: ; CODE SEGMENT ; - 45: ;========================================; + 35: ; **** СЕГМЕНТ ДАННЫХ ******************************************** + 36: .DSEG + 37: .ORG SRAM_START + 38: + 39: MCU_STATE: .BYTE 1 ; Текущее состояние МК + 40: NUMBER: .BYTE 2 + 41: DIGITS: .BYTE 4 ; Ячейки, где хранятся символы, для вывода на индикатор + 42: CURRENT_DIGIT: .BYTE 1 ; Номер разряда индикатора, который сейчас горит + 43: + 44: ; **** СЕГМЕНТ КОДА ********************************************** + 45: .CSEG 46: - 47: .CSEG - 48: .ORG 0x00 + 47: .ORG 0x00 + 48: 000000 C040 rjmp RESET_vect 49: - 50: ;========================================; - 51: ; VECTORS ; - 52: ;========================================; - 53: - 54: 000000 C000 rjmp RESET_vect ; Program start at RESET vector - 55: ;reti ; External Interrupt Request 0 / inactive - 56: ;reti ; External Interrupt Request 1 / inactive - 57: ;reti ; Timer/Counter1 Capture Event / inactive - 58: ;reti ; Timer/Counter1 Compare Match A / inactive - 59: ;reti ; Timer/Counter1 Overflow / inactive - 60: ;reti ; Timer/Counter0 Overflow / inactive - 61: ;reti ; USART0, Rx Complete / inactive - 62: ;reti ; USART0 Data Register Empty / inactive - 63: ;reti ; USART0, Tx Complete / inactive - 64: ;reti ; Analog Comparator / inactive - 65: ;reti ; Pin Change Interrupt Request 0/ inactive - 66: ;reti ; Timer/Counter1 Compare Match B / inactive - 67: ;reti ; Timer/Counter0 Compare Match A / inactive - 68: ;reti ; Timer/Counter0 Compare Match B / inactive - 69: ;reti ; USI Start Condition/ inactive - 70: ;reti ; USI Overflow / inactive - 71: ;reti ; EEPROM Ready/ inactive - 72: ;reti ; Watchdog Timer Overflow / inactive - 73: ;reti ; Pin Change Interrupt Request 1 / inactive - 74: ;reti ; Pin Change Interrupt Request 2 / inactive - 75: - 76: RESET_vect: - 77: ;========================================; - 78: ; INITIALIZE STACK POINTER ; - 79: ;========================================; - 80: 000001 ED0F ldi TEMP_REG_A, LOW(RAMEND) - 81: 000002 BF0D out SPL, TEMP_REG_A - 82: - 83: MCU_INIT: - 84: ;=======================================================; - 85: ; INITIALIZE PORTS ; - 86: ; ; - 87: ; POWER LED <-------------> OUT PD6 ; - 88: ; - This LED is used to indicate that device ; - 89: ; is working correctly ; - 90: ; 7SEG DIGIT 1 <-------------> OUT PD2 ; - 91: ; 7SEG DIGIT 2 <-------------> OUT PD3 ; - 92: ; 7SEG DIGIT 3 <-------------> OUT PD4 ; - 93: ; 7SEG DIGIT 4 <-------------> OUT PD5 ; - 94: ; ; - 95: ; USI CLOCK PIN <-------------> OUT PB0 ; - 96: ; USI DATA OUT PIN <-------------> OUT PB6 ; - 97: ; USI LATCH PIN <-------------> OUT PB7 ; - 98: ;=======================================================; - 99: 000003 E70C ldi r16, (1< USI Wire Mode - 141: ; USICS1 <--------------> USI Clock Source Select - 142: ; USICLK <--------------> USI Clock Strobe - 143: ; USITC <--------------> USI Toggle Clock (Enable clock generation) - 144: 00001E E10B ldi TEMP_REG_A, (1< USI Wire Mode + 14: ; USICS1 <--------------> USI Clock Source Select + 15: ; USICLK <--------------> USI Clock Strobe + 16: ; USITC <--------------> USI Toggle Clock (Enable clock generation) + 17: 00006E E10B ldi TEMP_REG_A, (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<