简体   繁体   中英

Button check AVR

I need to check which button has been pressed and compare it with a function. For example if button 0($01) is pressed, the program will compare it with the OP, 3, and if both conditions are true, the program will start again (init), otherwise if one of the conditions is false the program will loop through the subroutine again. At the moment It doesn't do anything, it should compare the button press, but it seems not to. So far I have done this:

 ;$01 == XOR button, $02 == NOR button, $04 == OR button, $08 == NAND button, $10 == AND button
button_pressed:
                in temp2, PIND
 xor_pressed:       
        cpi OP,3
        cpi temp2, $01
        brne button_pressed
        rjmp init

 nor_pressed:
        cpi OP,4
        cpi temp2,$02
        brne button_pressed
        rjmp init

 or_pressed:
        cpi OP,0
        ;cpi temp2,$04
        brne button_pressed
        rjmp init

 nand_pressed:
        cpi OP,2
        cpi temp2,$08
        brne button_pressed
        rjmp init

 and_pressed:
        cpi OP,1
        cpi temp2,$10
        brne button_pressed
        rjmp init

I do not know if you really need to use assembly instructions. May I recommend using atmel studio which is a free for personal/commercial use IDE cross compiler which work for all Atmel microcontrollers?

Install Atmel studio and goto create new executable project and it will allow you to select the target controller.

I am sure you can finish your coding in C or C++ at fraction of the time you will spend debugging assembly code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM