0
votes

I have an Arduino Uno Rev3 and I'm calling the following assembly function from the main code in C.

#
# Global data (val1)
#
.extern delay
.data

.comm val1,1
.global val1

#
# Program code (compute function)
#
.text
.global compute
compute:  
    lds r22, val1  ;value of input 
    ldi r23, 0x00  ;0 value
    ldi r24, 0x0D  ;value to flash led

flash:
    # flash LED
    call SDelay    ;Short Delay
    out  0x04, r24  ;LED On
    out  0x05, r24
    call SDelay    ;Delay
    out  0x04, r23  ;LED Off
    out  0x05, r23
    dec  r22
    brne flash;
finish:
    rjmp finish    ;keep looping once finished

SDelay:
    # Push registers onto stack
    push r22 
    push r23 
    push r24 
    push r25 
    #Delay
    ldi r22, 0xa0
    ldi r23, 0x00
    ldi r24, 0x00 
    ldi r25, 0x00
    call delay
    #Pop registers on stack
    pop r25
    pop r24
    pop r23
    pop r22 
    ret

This is supposed to flash an LED (I'm unsure which one I am flashing here) the number of times inputed. This number of times should be stored in val1 (calculated in C). However, I don't know what I'm doing wrong.

And can someone quickly explain how to flash the specific LEDs in the arduino board? I know I have to set a pin to high or low, but I don't know which pin will do that for the specific LED.

I know these are noob questions, but I'm new to AVR assembly and really suck at it. I wouldn't do it this way but the CS department at our school deems it necessary for us to understand this.

Thanks!

1

1 Answers

1
votes

1) which LED to flash

As per schematic of the Arduino Uno R3 board there are 2 LED's you can control via code, connected to PD4 and PD5 (serving a dual purpose as serial RX and TX); configuring these pins as output and writing 0 to them will light them.

Work out

  • an ASM routine that blinks one of these LEDs in isolation at first (blink = 0.5 sec on, 0.5 sec off)
  • an ASM routine that does the same repetitive for "x" times ... "x" stored in R24 (see below why R24)
  • and use symbolic notation whereever possible

Alternatively you may want to

  • connect an extra LED
  • stay in C, using Arduino routines like pinMode(), digitalWrite(), delay()

2) C and assembler

You are calling an ASM routine from C ... this requires some extra thoughts, in particular when you hand over parameters from C to ASM ... in essence param's are passed from R25 downwards - 2 bytes per each param, so a single char is handed over as R25 (MSB) and R24 (LSB) ... read through this