1

I am working on a program that is suppose to create a certain blink sequence on my arduino board (atmega328p). The pattern that I am trying to create is, ON for 1/2 second OFF for 1/2 second ON for 1/2 second Off for one full second Repeat this sequence.

I approached the problem by creating two different delays one for the 1/2 sec and other for the 1 sec, and then I call them.

If I only have one delay the light will work with that pattern but once I put both delays in the loop together the light does not even follow the pattern. I apologize if this is a easy question, I don't know if I am approaching this right.

Here is my code:

#include "config.h"

    .section .data
dummy:  .byte 0     ; dummy global variable

        .section .text
        .global     main
        .extern     delay          
        .org        0x0000

main:
    ; clear the SREG register
        eor     r1, r1                  ; cheap zero
        out     _(SREG), r1                ; clear flag register


        ; set up the stack
        ldi         r28, (RAMEND & 0x00ff)
        ldi         r29, (RAMEND >> 8)
        out         _(SPH), r29
        out         _(SPL), r28

    ; initialize the CPU clock to run at full speed
    ldi         r24, 0x80
        sts         CLKPR, r24              ; allow access to clock setup
        sts         CLKPR, r1               ; run at full speed

        ; set up the LED port
        sbi         LED_DIR, LED_PIN        ; set LED pin to output
        cbi         LED_PORT, LED_PIN       ; start with the LED off


        ; enter the blink loop
1:      rcall       toggle
        rcall       delay
        rcall       delay2
        rjmp        1b

toggle:
        in          r24, LED_PORT           ; get current bits
        ldi         r25, (1 << LED_PIN)     ; LED is pin 5
        eor         r24, r25                ; flip the bit
        out         LED_PORT, r24           ; write the bits back
        ret

delay:                      ; 1/2 sec delay loop
        ldi         r21, 41
        ldi         r22, 150
        ldi         r23, 127
1:      dec         r23
        brne        1b
        dec         r22
        brne        1b
        dec         r21
        brne        1b
        ret

delay2:                     ; 1 sec delay loop
        ldi         r18, 82
        ldi         r19, 43
        ldi         r20, 0
2:      dec         r20
        brne        2b
        dec         r19
        brne        2b
        dec         r18
        brne        2b
        ret
VAM7965
  • 41
  • 3
  • There is no "call delay2" in your code – AterLux Apr 24 '19 at 08:10
  • I apologize I forgot to add it but on the version I am working on in my virtual machine I did have delay2 in the loop and it would not run either delay rate how it was suppose to run. – VAM7965 Apr 25 '19 at 14:53
  • 1
    Put the whole code which is suggested to express the pattern. This one just call "toggle" and then 2 delays. I.e. it will toggle led each 1.5 seconds. – AterLux Apr 25 '19 at 14:57

0 Answers0