shift register

This commit is contained in:
Sergey Yarkov 2023-01-28 03:36:06 +03:00
parent 0f4110bfd4
commit 108f5dbdba
No known key found for this signature in database
GPG Key ID: E91CE1FABC619B6F
6 changed files with 514 additions and 288 deletions

View File

@ -15,13 +15,16 @@
.LIST .LIST
.DEF tmp_r_a = r16 .DEF tmp_r_a = r16
.DEF COUNTER = r20
;========================================; ;========================================;
; LABELS ; ; LABELS ;
;========================================; ;========================================;
.EQU LED_POWER_PORT = PD6 .EQU LED_POWER_PORT = PD6
.EQU CLOCK_PIN = PB0 ; ST_CP on 74HC595
.EQU DATA_PIN = PB1 ; DS on 74HC595
.EQU LATCH_PIN = PB2 ; SH_CP on 74HC595
;========================================; ;========================================;
; CODE SEGMENT ; ; CODE SEGMENT ;
@ -35,41 +38,95 @@
;========================================; ;========================================;
rjmp RESET_vect ; Program start at RESET vector rjmp RESET_vect ; Program start at RESET vector
reti ; External Interrupt Request 0 / inactive ;reti ; External Interrupt Request 0 / inactive
reti ; External Interrupt Request 1 / inactive ;reti ; External Interrupt Request 1 / inactive
reti ; Timer/Counter1 Capture Event / inactive ;reti ; Timer/Counter1 Capture Event / inactive
reti ; Timer/Counter1 Compare Match A / inactive ;reti ; Timer/Counter1 Compare Match A / inactive
reti ; Timer/Counter1 Overflow / inactive ;reti ; Timer/Counter1 Overflow / inactive
reti ; Timer/Counter0 Overflow / inactive ;reti ; Timer/Counter0 Overflow / inactive
reti ; USART0, Rx Complete / inactive ;reti ; USART0, Rx Complete / inactive
reti ; USART0 Data Register Empty / inactive ;reti ; USART0 Data Register Empty / inactive
reti ; USART0, Tx Complete / inactive ;reti ; USART0, Tx Complete / inactive
reti ; Analog Comparator / inactive ;reti ; Analog Comparator / inactive
reti ; Pin Change Interrupt Request 0/ inactive ;reti ; Pin Change Interrupt Request 0/ inactive
reti ; Timer/Counter1 Compare Match B / inactive ;reti ; Timer/Counter1 Compare Match B / inactive
reti ; Timer/Counter0 Compare Match A / inactive ;reti ; Timer/Counter0 Compare Match A / inactive
reti ; Timer/Counter0 Compare Match B / inactive ;reti ; Timer/Counter0 Compare Match B / inactive
reti ; USI Start Condition/ inactive ;reti ; USI Start Condition/ inactive
reti ; USI Overflow / inactive ;reti ; USI Overflow / inactive
reti ; EEPROM Ready/ inactive ;reti ; EEPROM Ready/ inactive
reti ; Watchdog Timer Overflow / inactive ;reti ; Watchdog Timer Overflow / inactive
reti ; Pin Change Interrupt Request 1 / inactive ;reti ; Pin Change Interrupt Request 1 / inactive
reti ; Pin Change Interrupt Request 2 / inactive ;reti ; Pin Change Interrupt Request 2 / inactive
RESET_vect: RESET_vect:
; ;========================================;
; INIT STACK POINTER ; INITIALIZE STACK POINTER ;
ldi tmp_r_a, low(RAMEND) ;========================================;
out SPL, tmp_r_a ldi tmp_r_a, low(RAMEND)
out SPL, tmp_r_a
MCU_INIT: MCU_INIT:
rcall INIT_PORTS ;=======================================================
rjmp LOOP ; POWER LED <------------> PD6 ;
; - This LED is used to indicate that device ;
; is working correctly ;
; ;
;=======================================================
rcall INIT_PORTS
;========================================;
; USI IS USED TO COMMUNICATE ;
; WITH SHIFT REGISTER (74HC595N) ;
;========================================;
rcall INIT_USI
ldi COUNTER, 0
rjmp LOOP
INIT_PORTS: INIT_PORTS:
ldi r16, (1<<LED_POWER_PORT) ldi r16, (1<<LED_POWER_PORT)
out DDRD, r16 out DDRD, r16
out PORTD, r16 ldi r16, (1<<CLOCK_PIN) | (1<<LATCH_PIN) | (1<<DATA_PIN)
out DDRB, r16
ret
INIT_USI:
ret
;========================================;
; SEND BYTE TO 74HC595 ;
;========================================;
TRANSMIT_595:
push r19
mov r19, COUNTER
ldi r16, 8
_TRANSMIT_595_LOOP:
lsl r19
brcc _TRANSMIT_595_SEND_LOW
brcs _TRANSMIT_595_SEND_HIGH
_TRANSMIT_595_SEND_HIGH:
sbi PORTB, DATA_PIN
rjmp _TRANSMIT_595_COMMIT
_TRANSMIT_595_SEND_LOW:
cbi PORTB, DATA_PIN
_TRANSMIT_595_COMMIT:
sbi PORTB, CLOCK_PIN
cbi PORTB, CLOCK_PIN
sbi PORTB, LATCH_PIN
cbi PORTB, LATCH_PIN
dec r16
brne _TRANSMIT_595_LOOP
pop r19
ret
SUBPROGRAM_LED_SHIFTING:
rcall TRANSMIT_595
inc COUNTER
ret ret
;========================================; ;========================================;
@ -77,37 +134,44 @@ ret
;========================================; ;========================================;
LOOP: LOOP:
ldi r16, (1<<LED_POWER_PORT) rcall TOGGLE_POWER_LED
out PORTD, r16 rcall SUBPROGRAM_LED_SHIFTING
rcall DELAY
rcall DELAY rjmp LOOP
rcall DELAY
ldi r16, (0<<LED_POWER_PORT)
out PORTD, r16
rcall DELAY
rcall DELAY
rjmp LOOP
DELAY: DELAY:
ldi r16, 255 ; 1 clock cycle push r16
_DEL_1: push r17
ldi r17, 255 ; 1 clock cycle cli
_DEL_2: ldi r16, 20 ; 1
dec r17 ; 1 clock cycle _DELAY_1:
nop ; 1 clock cycle ldi r17, 255
brne _DEL_2 ; 2 clock cycle when jumping / 1 when continue _DELAY_2:
dec r17
nop
nop
nop
brne _DELAY_2
dec r16 ; 1 clock cycle dec r16
brne _DEL_1 ; 2 clock cycle when jumping / 1 when continue brne _DELAY_1
sei
pop r17
pop r16
ret
TOGGLE_POWER_LED:
ldi r16, (1<<LED_POWER_PORT)
in r17, PORTD
eor r17, r16
out PORTD, r17
ret ret
INFO: .DB "AVR Thermostat. Written by Sergey Yarkov 22.01.2023"
;========================================; ;========================================;
; EEPROM SEGMENT ; ; EEPROM SEGMENT ;
;========================================; ;========================================;
.ESEG .ESEG
INFO: .DB "AVR Thermostat. Written by Sergey Yarkov 22.01.2023"

5
firmware.eep Normal file
View File

@ -0,0 +1,5 @@
:1000000041565220544845524D4F535441542E208E
:100010005752495454454E20425920534552474562
:1000200059205941524B4F562032322E30312E3208
:0300300030323338
:00000001FF

View File

@ -1,11 +1,10 @@
:020000020000FC :020000020000FC
:1000000014C0189518951895189518951895189561 :1000000000C00FED0DBF03D007D040E01AC000E4E0
:100010001895189518951895189518951895189578 :1000100001BB07E007BB089508953F93342F08E024
:10002000189518951895189518950FED0DBF01D0D6 :10002000330F18F400F0C19A01C0C198C09AC0986B
:1000300004C000E401BB02BB089500E402BB06D08B :10003000C29AC2980A95A1F73F910895EEDF4395C1
:1000400005D000E002BB02D001D0F7CF0FEF1FEFC9 :10004000089513D0FBDF01D0FCCF0F931F93F894DA
:100050001A950000E9F70A95D1F708954156522004 :1000500004E11FEF1A95000000000000D9F70A958F
:10006000546865726D6F737461742E205772697471 :10006000C1F778941F910F91089500E412B31027FF
:1000700074656E20627920536572676579205961D5 :0400700012BB089522
:10008000726B6F762032322E30312E3230323300A6
:00000001FF :00000001FF

View File

@ -1,5 +1,5 @@
AVRASM ver. 2.2.7 firmware.asm Tue Jan 24 01:18:37 2023 AVRASM ver. 2.2.7 firmware.asm Sat Jan 28 03:33:17 2023
firmware.asm(14): Including file 'tn2313Adef.inc' firmware.asm(14): Including file 'tn2313Adef.inc'
firmware.asm(14): Including file 'tn2313Adef.inc' firmware.asm(14): Including file 'tn2313Adef.inc'
@ -719,13 +719,16 @@ firmware.asm(14): Including file 'tn2313Adef.inc'
.LIST .LIST
.DEF tmp_r_a = r16 .DEF tmp_r_a = r16
.DEF COUNTER = r20
;========================================; ;========================================;
; LABELS ; ; LABELS ;
;========================================; ;========================================;
.EQU LED_POWER_PORT = PD6 .EQU LED_POWER_PORT = PD6
.EQU CLOCK_PIN = PB0 ; ST_CP on 74HC595
.EQU DATA_PIN = PB1 ; DS on 74HC595
.EQU LATCH_PIN = PB2 ; SH_CP on 74HC595
;========================================; ;========================================;
; CODE SEGMENT ; ; CODE SEGMENT ;
@ -738,108 +741,193 @@ firmware.asm(14): Including file 'tn2313Adef.inc'
; VECTORS ; ; VECTORS ;
;========================================; ;========================================;
000000 c014 rjmp RESET_vect ; Program start at RESET vector 000000 c000 rjmp RESET_vect ; Program start at RESET vector
000001 9518 reti ; External Interrupt Request 0 / inactive ;reti ; External Interrupt Request 0 / inactive
000002 9518 reti ; External Interrupt Request 1 / inactive ;reti ; External Interrupt Request 1 / inactive
000003 9518 reti ; Timer/Counter1 Capture Event / inactive ;reti ; Timer/Counter1 Capture Event / inactive
000004 9518 reti ; Timer/Counter1 Compare Match A / inactive ;reti ; Timer/Counter1 Compare Match A / inactive
000005 9518 reti ; Timer/Counter1 Overflow / inactive ;reti ; Timer/Counter1 Overflow / inactive
000006 9518 reti ; Timer/Counter0 Overflow / inactive ;reti ; Timer/Counter0 Overflow / inactive
000007 9518 reti ; USART0, Rx Complete / inactive ;reti ; USART0, Rx Complete / inactive
000008 9518 reti ; USART0 Data Register Empty / inactive ;reti ; USART0 Data Register Empty / inactive
000009 9518 reti ; USART0, Tx Complete / inactive ;reti ; USART0, Tx Complete / inactive
00000a 9518 reti ; Analog Comparator / inactive ;reti ; Analog Comparator / inactive
00000b 9518 reti ; Pin Change Interrupt Request 0/ inactive ;reti ; Pin Change Interrupt Request 0/ inactive
00000c 9518 reti ; Timer/Counter1 Compare Match B / inactive ;reti ; Timer/Counter1 Compare Match B / inactive
00000d 9518 reti ; Timer/Counter0 Compare Match A / inactive ;reti ; Timer/Counter0 Compare Match A / inactive
00000e 9518 reti ; Timer/Counter0 Compare Match B / inactive ;reti ; Timer/Counter0 Compare Match B / inactive
00000f 9518 reti ; USI Start Condition/ inactive ;reti ; USI Start Condition/ inactive
000010 9518 reti ; USI Overflow / inactive ;reti ; USI Overflow / inactive
000011 9518 reti ; EEPROM Ready/ inactive ;reti ; EEPROM Ready/ inactive
000012 9518 reti ; Watchdog Timer Overflow / inactive ;reti ; Watchdog Timer Overflow / inactive
000013 9518 reti ; Pin Change Interrupt Request 1 / inactive ;reti ; Pin Change Interrupt Request 1 / inactive
000014 9518 reti ; Pin Change Interrupt Request 2 / inactive ;reti ; Pin Change Interrupt Request 2 / inactive
RESET_vect: RESET_vect:
; ;========================================;
; INIT STACK POINTER ; INITIALIZE STACK POINTER ;
000015 ed0f ldi tmp_r_a, low(RAMEND) ;========================================;
000016 bf0d out SPL, tmp_r_a 000001 ed0f ldi tmp_r_a, low(RAMEND)
000002 bf0d out SPL, tmp_r_a
MCU_INIT: MCU_INIT:
000017 d001 rcall INIT_PORTS ;=======================================================
000018 c004 rjmp LOOP ; POWER LED <------------> PD6 ;
; - This LED is used to indicate that device ;
; is working correctly ;
; ;
;=======================================================
000003 d003 rcall INIT_PORTS
;========================================;
; USI IS USED TO COMMUNICATE ;
; WITH SHIFT REGISTER (74HC595N) ;
;========================================;
000004 d007 rcall INIT_USI
000005 e040 ldi COUNTER, 0
000006 c01a rjmp LOOP
INIT_PORTS: INIT_PORTS:
000019 e400 ldi r16, (1<<LED_POWER_PORT) 000007 e400 ldi r16, (1<<LED_POWER_PORT)
00001a bb01 out DDRD, r16 000008 bb01 out DDRD, r16
00001b bb02 out PORTD, r16 000009 e007 ldi r16, (1<<CLOCK_PIN) | (1<<LATCH_PIN) | (1<<DATA_PIN)
00001c 9508 ret 00000a bb07 out DDRB, r16
00000b 9508 ret
INIT_USI:
00000c 9508 ret
;========================================;
; SEND BYTE TO 74HC595 ;
;========================================;
TRANSMIT_595:
00000d 933f push r19
00000e 2f34 mov r19, COUNTER
00000f e008 ldi r16, 8
_TRANSMIT_595_LOOP:
000010 0f33 lsl r19
000011 f418 brcc _TRANSMIT_595_SEND_LOW
000012 f000 brcs _TRANSMIT_595_SEND_HIGH
_TRANSMIT_595_SEND_HIGH:
000013 9ac1 sbi PORTB, DATA_PIN
000014 c001 rjmp _TRANSMIT_595_COMMIT
_TRANSMIT_595_SEND_LOW:
000015 98c1 cbi PORTB, DATA_PIN
_TRANSMIT_595_COMMIT:
000016 9ac0 sbi PORTB, CLOCK_PIN
000017 98c0 cbi PORTB, CLOCK_PIN
000018 9ac2 sbi PORTB, LATCH_PIN
000019 98c2 cbi PORTB, LATCH_PIN
00001a 950a dec r16
00001b f7a1 brne _TRANSMIT_595_LOOP
00001c 913f pop r19
00001d 9508 ret
SUBPROGRAM_LED_SHIFTING:
00001e dfee rcall TRANSMIT_595
00001f 9543 inc COUNTER
000020 9508 ret
;========================================; ;========================================;
; MAIN PROGRAM LOOP ; ; MAIN PROGRAM LOOP ;
;========================================; ;========================================;
LOOP: LOOP:
00001d e400 ldi r16, (1<<LED_POWER_PORT) 000021 d013 rcall TOGGLE_POWER_LED
00001e bb02 out PORTD, r16 000022 dffb rcall SUBPROGRAM_LED_SHIFTING
000023 d001 rcall DELAY
00001f d006 rcall DELAY 000024 cffc rjmp LOOP
000020 d005 rcall DELAY
000021 e000 ldi r16, (0<<LED_POWER_PORT)
000022 bb02 out PORTD, r16
000023 d002 rcall DELAY
000024 d001 rcall DELAY
000025 cff7 rjmp LOOP
DELAY: DELAY:
000026 ef0f ldi r16, 255 ; 1 clock cycle 000025 930f push r16
_DEL_1: 000026 931f push r17
000027 ef1f ldi r17, 255 ; 1 clock cycle 000027 94f8 cli
_DEL_2: 000028 e104 ldi r16, 20 ; 1
000028 951a dec r17 ; 1 clock cycle _DELAY_1:
000029 0000 nop ; 1 clock cycle 000029 ef1f ldi r17, 255
00002a f7e9 brne _DEL_2 ; 2 clock cycle when jumping / 1 when continue _DELAY_2:
00002a 951a dec r17
00002b 0000 nop
00002c 0000 nop
00002d 0000 nop
00002e f7d9 brne _DELAY_2
00002b 950a dec r16 ; 1 clock cycle 00002f 950a dec r16
00002c f7d1 brne _DEL_1 ; 2 clock cycle when jumping / 1 when continue 000030 f7c1 brne _DELAY_1
00002d 9508 ret 000031 9478 sei
000032 911f pop r17
000033 910f pop r16
000034 9508 ret
TOGGLE_POWER_LED:
000035 e400 ldi r16, (1<<LED_POWER_PORT)
000036 b312 in r17, PORTD
000037 2710 eor r17, r16
000038 bb12 out PORTD, r17
000039 9508 ret
00002e 5641
00002f 2052
000030 6854
000031 7265
000032 6f6d
000033 7473
000034 7461
000035 202e
000036 7257
000037 7469
000038 6574
000039 206e
00003a 7962
00003b 5320
00003c 7265
00003d 6567
00003e 2079
00003f 6159
000040 6b72
000041 766f
000042 3220
000043 2e32
000044 3130
000045 322e
000046 3230
firmware.asm(107): warning: .cseg .db misalignment - padding zero byte
000047 0033 INFO: .DB "AVR Thermostat. Written by Sergey Yarkov 22.01.2023"
;========================================; ;========================================;
; EEPROM SEGMENT ; ; EEPROM SEGMENT ;
;========================================; ;========================================;
.ESEG
000000 41
000001 56
000002 52
000003 20
000004 54
000005 68
000006 65
000007 72
000008 6d
000009 6f
00000a 73
00000b 74
00000c 61
00000d 74
00000e 2e
00000f 20
000010 57
000011 72
000012 69
000013 74
000014 74
000015 65
000016 6e
000017 20
000018 62
000019 79
00001a 20
00001b 53
00001c 65
00001d 72
00001e 67
00001f 65
000020 79
000021 20
000022 59
000023 61
000024 72
000025 6b
000026 6f
000027 76
000028 20
000029 32
00002a 32
00002b 2e
00002c 30
00002d 31
00002e 2e
00002f 32
000030 30
000031 32
RESOURCE USE INFORMATION RESOURCE USE INFORMATION
@ -859,37 +947,37 @@ counted separately from r26..r31 here.
"ATtiny2313A" register use summary: "ATtiny2313A" register use summary:
x : 0 y : 0 z : 0 r0 : 0 r1 : 0 r2 : 0 r3 : 0 r4 : 0 x : 0 y : 0 z : 0 r0 : 0 r1 : 0 r2 : 0 r3 : 0 r4 : 0
r5 : 0 r6 : 0 r7 : 0 r8 : 0 r9 : 0 r10: 0 r11: 0 r12: 0 r5 : 0 r6 : 0 r7 : 0 r8 : 0 r9 : 0 r10: 0 r11: 0 r12: 0
r13: 0 r14: 0 r15: 0 r16: 11 r17: 2 r18: 0 r19: 0 r20: 0 r13: 0 r14: 0 r15: 0 r16: 14 r17: 7 r18: 0 r19: 4 r20: 3
r21: 0 r22: 0 r23: 0 r24: 0 r25: 0 r26: 0 r27: 0 r28: 0 r21: 0 r22: 0 r23: 0 r24: 0 r25: 0 r26: 0 r27: 0 r28: 0
r29: 0 r30: 0 r31: 0 r29: 0 r30: 0 r31: 0
Registers used: 2 out of 35 (5.7%) Registers used: 4 out of 35 (11.4%)
"ATtiny2313A" instruction use summary: "ATtiny2313A" instruction use summary:
.lds : 0 .sts : 0 adc : 0 add : 0 adiw : 0 and : 0 .lds : 0 .sts : 0 adc : 0 add : 0 adiw : 0 and : 0
andi : 0 asr : 0 bclr : 0 bld : 0 brbc : 0 brbs : 0 andi : 0 asr : 0 bclr : 0 bld : 0 brbc : 0 brbs : 0
brcc : 0 brcs : 0 break : 0 breq : 0 brge : 0 brhc : 0 brcc : 1 brcs : 1 break : 0 breq : 0 brge : 0 brhc : 0
brhs : 0 brid : 0 brie : 0 brlo : 0 brlt : 0 brmi : 0 brhs : 0 brid : 0 brie : 0 brlo : 0 brlt : 0 brmi : 0
brne : 2 brpl : 0 brsh : 0 brtc : 0 brts : 0 brvc : 0 brne : 3 brpl : 0 brsh : 0 brtc : 0 brts : 0 brvc : 0
brvs : 0 bset : 0 bst : 0 cbi : 0 cbr : 0 clc : 0 brvs : 0 bset : 0 bst : 0 cbi : 3 cbr : 0 clc : 0
clh : 0 cli : 0 cln : 0 clr : 0 cls : 0 clt : 0 clh : 0 cli : 1 cln : 0 clr : 0 cls : 0 clt : 0
clv : 0 clz : 0 com : 0 cp : 0 cpc : 0 cpi : 0 clv : 0 clz : 0 com : 0 cp : 0 cpc : 0 cpi : 0
cpse : 0 dec : 2 eor : 0 icall : 0 ijmp : 0 in : 0 cpse : 0 dec : 3 eor : 1 icall : 0 ijmp : 0 in : 1
inc : 0 ld : 0 ldd : 0 ldi : 6 lds : 0 lpm : 0 inc : 1 ld : 0 ldd : 0 ldi : 8 lds : 0 lpm : 0
lsl : 0 lsr : 0 mov : 0 movw : 0 neg : 0 nop : 1 lsl : 1 lsr : 0 mov : 1 movw : 0 neg : 0 nop : 3
or : 0 ori : 0 out : 5 pop : 0 push : 0 rcall : 5 or : 0 ori : 0 out : 4 pop : 3 push : 3 rcall : 6
ret : 2 reti : 20 rjmp : 3 rol : 0 ror : 0 sbc : 0 ret : 6 reti : 0 rjmp : 4 rol : 0 ror : 0 sbc : 0
sbci : 0 sbi : 0 sbic : 0 sbis : 0 sbiw : 0 sbr : 0 sbci : 0 sbi : 3 sbic : 0 sbis : 0 sbiw : 0 sbr : 0
sbrc : 0 sbrs : 0 sec : 0 seh : 0 sei : 0 sen : 0 sbrc : 0 sbrs : 0 sec : 0 seh : 0 sei : 1 sen : 0
ser : 0 ses : 0 set : 0 sev : 0 sez : 0 sleep : 0 ser : 0 ses : 0 set : 0 sev : 0 sez : 0 sleep : 0
spm : 0 st : 0 std : 0 sts : 0 sub : 0 subi : 0 spm : 0 st : 0 std : 0 sts : 0 sub : 0 subi : 0
swap : 0 tst : 0 wdr : 0 swap : 0 tst : 0 wdr : 0
Instructions used: 9 out of 105 (8.6%) Instructions used: 21 out of 105 (20.0%)
"ATtiny2313A" memory use summary [bytes]: "ATtiny2313A" memory use summary [bytes]:
Segment Begin End Code Data Used Size Use% Segment Begin End Code Data Used Size Use%
--------------------------------------------------------------- ---------------------------------------------------------------
[.cseg] 0x000000 0x000090 92 52 144 2048 7.0% [.cseg] 0x000000 0x000074 116 0 116 2048 5.7%
[.dseg] 0x000060 0x000060 0 0 0 128 0.0% [.dseg] 0x000060 0x000060 0 0 0 128 0.0%
[.eseg] 0x000000 0x000000 0 0 0 128 0.0% [.eseg] 0x000000 0x000033 0 51 51 128 39.8%
Assembly complete, 0 errors, 1 warnings Assembly complete, 0 errors, 0 warnings

View File

@ -5,7 +5,7 @@ Path: /home/sergeyyarkov/Documents/Applications/attiny2313a_thermostat/
Source file: firmware.asm Source file: firmware.asm
Hex file: firmware.hex Hex file: firmware.hex
Eeprom file: firmware.eep Eeprom file: firmware.eep
Compiled: 24.01.2023, 01:15:04 Compiled: 28.01.2023, 02:47:03
Pass: 2 Pass: 2
1: ; 1: ;
@ -28,136 +28,207 @@ Pass: 2
15: .LIST 15: .LIST
16: 16:
17: .DEF tmp_r_a = r16 17: .DEF tmp_r_a = r16
18: 18: .DEF COUNTER = r20
19: ;========================================; 19:
20: ; LABELS ; 20: ;========================================;
21: ;========================================; 21: ; LABELS ;
22: 22: ;========================================;
23: .EQU LED_POWER_PORT = PD6 23:
24: 24: .EQU LED_POWER_PORT = PD6
25: 25: .EQU CLOCK_PIN = PB0 ; ST_CP on 74HC595
26: ;========================================; 26: .EQU LATCH_PIN = PB1 ; SH_CP on 74HC595
27: ; CODE SEGMENT ; 27: .EQU DATA_PIN = PB2 ; DS on 74HC595
28: ;========================================; 28:
29: 29: ;========================================;
30: .CSEG 30: ; CODE SEGMENT ;
31: .ORG 0x00 31: ;========================================;
32: 32:
33: ;========================================; 33: .CSEG
34: ; VECTORS ; 34: .ORG 0x00
35: ;========================================; 35:
36: 36: ;========================================;
37: 000000 C014 rjmp RESET_vect ; Program start at RESET vector 37: ; VECTORS ;
38: 000001 9518 reti ; External Interrupt Request 0 / inactive 38: ;========================================;
39: 000002 9518 reti ; External Interrupt Request 1 / inactive 39:
40: 000003 9518 reti ; Timer/Counter1 Capture Event / inactive 40: 000000 C000 rjmp RESET_vect ; Program start at RESET vector
41: 000004 9518 reti ; Timer/Counter1 Compare Match A / inactive 41: ;reti ; External Interrupt Request 0 / inactive
42: 000005 9518 reti ; Timer/Counter1 Overflow / inactive 42: ;reti ; External Interrupt Request 1 / inactive
43: 000006 9518 reti ; Timer/Counter0 Overflow / inactive 43: ;reti ; Timer/Counter1 Capture Event / inactive
44: 000007 9518 reti ; USART0, Rx Complete / inactive 44: ;reti ; Timer/Counter1 Compare Match A / inactive
45: 000008 9518 reti ; USART0 Data Register Empty / inactive 45: ;reti ; Timer/Counter1 Overflow / inactive
46: 000009 9518 reti ; USART0, Tx Complete / inactive 46: ;reti ; Timer/Counter0 Overflow / inactive
47: 00000A 9518 reti ; Analog Comparator / inactive 47: ;reti ; USART0, Rx Complete / inactive
48: 00000B 9518 reti ; Pin Change Interrupt Request 0/ inactive 48: ;reti ; USART0 Data Register Empty / inactive
49: 00000C 9518 reti ; Timer/Counter1 Compare Match B / inactive 49: ;reti ; USART0, Tx Complete / inactive
50: 00000D 9518 reti ; Timer/Counter0 Compare Match A / inactive 50: ;reti ; Analog Comparator / inactive
51: 00000E 9518 reti ; Timer/Counter0 Compare Match B / inactive 51: ;reti ; Pin Change Interrupt Request 0/ inactive
52: 00000F 9518 reti ; USI Start Condition/ inactive 52: ;reti ; Timer/Counter1 Compare Match B / inactive
53: 000010 9518 reti ; USI Overflow / inactive 53: ;reti ; Timer/Counter0 Compare Match A / inactive
54: 000011 9518 reti ; EEPROM Ready/ inactive 54: ;reti ; Timer/Counter0 Compare Match B / inactive
55: 000012 9518 reti ; Watchdog Timer Overflow / inactive 55: ;reti ; USI Start Condition/ inactive
56: 000013 9518 reti ; Pin Change Interrupt Request 1 / inactive 56: ;reti ; USI Overflow / inactive
57: 000014 9518 reti ; Pin Change Interrupt Request 2 / inactive 57: ;reti ; EEPROM Ready/ inactive
58: 58: ;reti ; Watchdog Timer Overflow / inactive
59: RESET_vect: 59: ;reti ; Pin Change Interrupt Request 1 / inactive
60: ; 60: ;reti ; Pin Change Interrupt Request 2 / inactive
61: ; INIT STACK POINTER 61:
62: 000015 ED0F ldi tmp_r_a, low(RAMEND) 62: RESET_vect:
63: 000016 BF0D out SPL, tmp_r_a 63: ;========================================;
64: 64: ; INITIALIZE STACK POINTER ;
65: MCU_INIT: 65: ;========================================;
66: 000017 D001 rcall INIT_PORTS 66: 000001 ED0F ldi tmp_r_a, low(RAMEND)
67: 000018 C004 rjmp LOOP 67: 000002 BF0D out SPL, tmp_r_a
68: 68:
69: INIT_PORTS: 69: MCU_INIT:
70: 000019 E400 ldi r16, (1<<LED_POWER_PORT) 70: ;=======================================================
71: 00001A BB01 out DDRD, r16 71: ; POWER LED <------------> PD6 ;
72: 00001B BB02 out PORTD, r16 72: ; - This LED is used to indicate that device ;
73: 00001C 9508 ret 73: ; is working correctly ;
74: 74: ; ;
75: ;========================================; 75: ;=======================================================
76: ; MAIN PROGRAM LOOP ; 76: 000003 D002 rcall INIT_PORTS
77: ;========================================; 77:
78: 78: ;========================================;
79: LOOP: 79: ; USI IS USED TO COMMUNICATE ;
80: 00001D E400 ldi r16, (1<<LED_POWER_PORT) 80: ; WITH SHIFT REGISTER (74HC595N) ;
81: 00001E BB02 out PORTD, r16 81: ;========================================;
82: 82: 000004 D006 rcall INIT_USI
83: 00001F D006 rcall DELAY 83:
84: 000020 D005 rcall DELAY 84: 000005 C01D rjmp LOOP
85: 85:
86: 000021 E000 ldi r16, (0<<LED_POWER_PORT) 86: INIT_PORTS:
87: 000022 BB02 out PORTD, r16 87: 000006 E400 ldi r16, (1<<LED_POWER_PORT)
88: 88: 000007 BB01 out DDRD, r16
89: 000023 D002 rcall DELAY 89: 000008 E007 ldi r16, (1<<CLOCK_PIN) | (1<<LATCH_PIN) | (1<<DATA_PIN)
90: 000024 D001 rcall DELAY 90: 000009 BB07 out DDRB, r16
91: 91: 00000A 9508 ret
92: 000025 CFF7 rjmp LOOP 92:
93: 93: INIT_USI:
94: DELAY: 94:
95: 000026 E302 ldi r16, 50 ; 1 clock cycle 95: 00000B 9508 ret
96: _DEL_1: 96:
97: 000027 EF1F ldi r17, 255 ; 1 clock cycle 97: CLOCK_595:
98: _DEL_2: 98: 00000C 930F push r16
99: 000028 951A dec r17 ; 1 clock cycle 99: 00000D E001 ldi r16, (1<<CLOCK_PIN)
100: 000029 0000 nop ; 1 clock cycle 100: 00000E B318 in r17, PORTB
101: 00002A F7E9 brne _DEL_2 ; 2 clock cycle when jumping / 1 when continue 101: 00000F 2710 eor r17, r16
102: 102: 000010 BB18 out PORTB, r17
103: 00002B 950A dec r16 ; 1 clock cycle 103: 000011 910F pop r16
104: 00002C F7D1 brne _DEL_1 ; 2 clock cycle when jumping / 1 when continue 104: 000012 9508 ret
105: 00002D 9508 ret 105:
106: 106: TRANSMIT_595:
107: INFO: .DB "AVR Thermostat. Written by Sergey Yarkov 22.01.2023" 107: 000013 933F push r19
-> Warning 004: Number of bytes on line is odd, added 00 to fit program memory! 108: 000014 E23A ldi r19, 0b00101010 ; Data to transmit
File: /home/sergeyyarkov/Documents/Applications/attiny2313a_thermostat/firmware.asm, Line: 107 109: 000015 E008 ldi r16, 8
Source line: INFO: .DB "AVR Thermostat. Written by Sergey Yarkov 22.01.2023" 110: _TRANSMIT_595_LOOP:
00002E 5641 2052 4854 5245 111: 000016 0F33 lsl r19
000032 4F4D 5453 5441 202E 112: 000017 F410 brcc _TRANSMIT_595_SEND_LOW
000036 5257 5449 4554 204E 113: 000018 F000 brcs _TRANSMIT_595_SEND_HIGH
00003A 5942 5320 5245 4547 114:
00003E 2059 4159 4B52 564F 115: _TRANSMIT_595_SEND_HIGH:
000042 3220 2E32 3130 322E 116: 000019 C000 rjmp _TRANSMIT_595_PROCEED
000046 3230 0033 117:
108: 118:
109: ;========================================; 119: _TRANSMIT_595_SEND_LOW:
110: ; EEPROM SEGMENT ; 120:
111: ;========================================; 121: _TRANSMIT_595_PROCEED:
112: 122: 00001A DFF1 rcall CLOCK_595
113: .ESEG 123: 00001B DFF0 rcall CLOCK_595
124: 00001C 950A dec r16
125: 00001D F7C1 brne _TRANSMIT_595_LOOP
126: 00001E 913F pop r19
127: 00001F 9508 ret
128:
129: SUBPROGRAM_LED_SHIFTING:
130: 000020 9543 inc COUNTER
131: 000021 DFF1 rcall TRANSMIT_595
132: 000022 9508 ret
133:
134: ;========================================;
135: ; MAIN PROGRAM LOOP ;
136: ;========================================;
137:
138: LOOP:
139: 000023 D00F rcall TOGGLE_POWER_LED
140: 000024 DFFB rcall SUBPROGRAM_LED_SHIFTING
141: 000025 D001 rcall DELAY
142: 000026 CFFC rjmp LOOP
143:
144: DELAY:
145: 000027 94F8 cli
146: 000028 E00A ldi r16, 10 ; 1
147: _DELAY_1:
148: 000029 EF1F ldi r17, 255 ; 1
149: _DELAY_2:
150: 00002A 951A dec r17 ; 1
151: 00002B 0000 nop ; 1
152: 00002C 0000 nop ; 1
153: 00002D 0000 nop ; 1
154: 00002E F7D9 brne _DELAY_2 ; 2/1
155:
156: 00002F 950A dec r16
157: 000030 F7C1 brne _DELAY_1 ; 2/1
158: 000031 9478 sei
159: 000032 9508 ret ; 4
160:
161: TOGGLE_POWER_LED:
162: 000033 E400 ldi r16, (1<<LED_POWER_PORT)
163: 000034 B312 in r17, PORTD
164: 000035 2710 eor r17, r16
165: 000036 BB12 out PORTD, r17
166: 000037 9508 ret
167:
168:
169: ;========================================;
170: ; EEPROM SEGMENT ;
171: ;========================================;
172:
173: .ESEG
174: INFO: .DB "AVR Thermostat. Written by Sergey Yarkov 22.01.2023"
000000 41 56 52 20 54 48 45 52
000008 4D 4F 53 54 41 54 2E 20
000010 57 52 49 54 54 45 4E 20
000018 42 59 20 53 45 52 47 45
000020 59 20 59 41 52 4B 4F 56
000028 20 32 32 2E 30 31 2E 32
000030 30 32 33
List of symbols: List of symbols:
Type nDef nUsed Decimalval Hexval Name Type nDef nUsed Decimalval Hexval Name
T 1 1 89 59 ATTINY2313A T 1 1 89 59 ATTINY2313A
L 1 2 21 15 RESET_VECT L 1 2 1 01 RESET_VECT
L 1 0 23 17 MCU_INIT L 1 0 3 03 MCU_INIT
L 1 2 25 19 INIT_PORTS L 1 2 6 06 INIT_PORTS
L 1 4 29 1D LOOP L 1 2 11 0B INIT_USI
L 1 8 38 26 DELAY L 1 4 12 0C CLOCK_595
L 1 2 39 27 _DEL_1 L 1 2 19 13 TRANSMIT_595
L 1 2 40 28 _DEL_2 L 1 2 22 16 _TRANSMIT_595_LOOP
L 1 0 46 2E INFO L 1 2 25 19 _TRANSMIT_595_SEND_HIGH
L 1 2 26 1A _TRANSMIT_595_SEND_LOW
L 1 2 26 1A _TRANSMIT_595_PROCEED
L 1 2 32 20 SUBPROGRAM_LED_SHIFTING
L 1 4 35 23 LOOP
L 1 2 39 27 DELAY
L 1 2 41 29 _DELAY_1
L 1 2 42 2A _DELAY_2
L 1 2 51 33 TOGGLE_POWER_LED
L 1 0 0 00 INFO
R 1 2 16 10 TMP_R_A R 1 2 16 10 TMP_R_A
R 1 1 20 14 COUNTER
C 1 0 23 17 NOW_Y C 1 0 23 17 NOW_Y
C 1 0 1 01 NOW_M C 1 0 1 01 NOW_M
C 1 0 24 18 NOW_D C 1 0 28 1C NOW_D
C 1 0 44950 AF96 NOW_I C 1 0 44954 AF9A NOW_I
C 1 3 6 06 LED_POWER_PORT C 1 2 6 06 LED_POWER_PORT
C 1 2 0 00 CLOCK_PIN
C 1 1 1 01 LATCH_PIN
C 1 1 2 02 DATA_PIN
No macros. No macros.
Program : 46 words. Program : 56 words.
Constants : 26 words. Constants : 0 words.
Total program memory: 72 words. Total program memory: 56 words.
Eeprom space : 0 bytes. Eeprom space : 51 bytes.
Data segment : 0 bytes. Data segment : 0 bytes.
Compilation completed, no errors. Compilation completed, no errors.
Compilation ended 24.01.2023, 01:15:04 Compilation ended 28.01.2023, 02:47:03

View File

@ -1,11 +1,10 @@
/avr_sim_project_file /avr_sim_project_file
/home/sergeyyarkov/Documents/Applications/attiny2313a_thermostat/firmware.asm /home/sergeyyarkov/Documents/Applications/attiny2313a_thermostat/firmware.asm
mainasm=firmware.asm mainasm=firmware.asm
file=firmware.lst,98,9,55 file=firmware.lst,120,20,63
file=firmware.asm,1,1,1 file=firmware.asm,1,1,1
clock=12000000, Div8 clock=12000000, Div8
device-type=ATtiny2313A device-type=ATtiny2313A
device-package=20-pin-PDIP_SOIC device-package=20-pin-PDIP_SOIC
include=firmware.asm B89 windows=acePStwz
windows=acepstwz
alert1=0,0,-1,-1,,0,0 alert1=0,0,-1,-1,,0,0