Click here to Skip to main content
15,393,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm writing assembly code for the ATMEGA328P (arduino uno). i have a example from a book.

'Adjust the previous assignment so that the LED stays on even when you release the button. The LED must remain lit until the other button is pressed'

the previous assignment was:

'Create a program that lights an LED when a button is pressed. When button 0 is pressed, LED 0 must light up. When button 1 is pressed, LED 1 must light up.'

for this i have write some code( maybe not the best, but it works )

 .include "m328Pdef.inc"
    .def temp=r16 
    .def temp1=r18
    .cseg
    .org 0x0000


init:
    ldi temp, 0xff
    ldi temp1, 0x00
    out DDRD, temp
    out DDRB,temp1
    out PORTB,temp1

loop: 
    in temp,PINB
    out PORTD, temp
    rjmp loop

so my question is how can i do the second assignment?

What I have tried:

i have tried to add this:
delay:
    ldi temp, 0xFF
delay_loop_1:
    dec temp
    cpi temp, 0x00
    jmp delay_loop_1
ret
Posted
Updated 1-Nov-19 4:45am
Comments
Richard MacCutchan 3-Oct-19 14:10pm
   
In future when asked for further information please edit your original question rather than posting a new one.
Member 14611851 3-Oct-19 14:15pm
   
this is another question
Mike Hankey 3-Oct-19 14:22pm
   
You must keep track of the LED status, i.e. whether it is lit or not.

Why are you using a delay loop since the LED must remain lit until the other button is pressed?

If you're using Atmel Studio then use the simulator to debug your program and it will save you a lot of head aches.
Member 14611851 3-Oct-19 14:36pm
   
i dont need a delay loop?

You can find many samples at Tinkercad | From mind to design in minutes[^]
   
Comments
Member 14611851 4-Oct-19 10:21am
   
i know, but 90% of this samples is written in C
Write you assignment in C and then look at the .lss file for the assembler code the compiler outputs.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900