The project is to make a seven segment display count from 9 to 0 repeatedly. I've got the counter going down, but I cannot get it to reset.
My idea to reset is to "jmp loop" when y is pointing to 0x00 and z is pointing to 0xFC. When I try to enter this in, the counter won't even count down anymore (if I wait a few seconds, the count down happens, but initially we start at some arbitrary value). Any hints in the right direction would be greatly appreciated!
delay0: nop dec r20 brne delay0 nop dec r19 brne delay1 dec r18 brne delay2 cpi r16, 0x00 ; compare r17 to 0x00 brne next ; go to next if it is anything else cpi r17, 0xFC ; check if r17 is 0xFC brne next ; go to next if it is anything else. Worth mentioning 0xFC appears twice, but the first time it appears, r16 is 0x01. jmp loop ; if we get here, r16 is 0x00 and r17 is 0xFC. We need to reset
Here is my code that works for 1 count down:
#include "avr/io.h" .data digitB: .byte 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00 digitD: .byte 0x9C, 0xFC, 0x1C, 0xF4, 0xB6, 0x98, 0x3C, 0x6C, 0x18, 0xFC ;; Only allowed to use PINS 2-13 on the Arduino Uno board. Using PORTB/PORTD .text .global setup .global loop setup: ldi r16, 0b11111100 ; Set DDRB output as needed (all but PIN 0 and 1) out 0x0A, r16 ldi r16, 0b00000011 ; Set DDRD output as needed (Only PIN 1 and 0) out 0x04, r16 ret loop: ldi r28, lo8(digitB) ; point ot the first item in the array for PORTB ldi r29, hi8(digitB) ldi r30, lo8(digitD) ; point to the first item in the array for PORTD ldi r31, hi8(digitD) next: ld r16, y+ ; load PORTB item into reg and increment the pointer ld r17, z+ ; load PORTD item into reg and icnrement the pointer out 0x05, r16 ; set PORTB bits out 0x0B, r17 ; set PORTD bits jmp delay_sec ; wait a sec nZero: jmp next ; go to next label nZero isn't used at the moment delay_sec: ldi r18, 100 delay2: ldi r19, 200 delay1: ldi r20, 200 delay0: nop dec r20 brne delay0 nop dec r19 brne delay1 dec r18 brne delay2 jmp next