Quote:Which button was pressed first? – Program in Assembly Two players, A and B have a push button in front of them. After a signal from the referee, both players try to push their button first. The system should record the first button push and display the player's number. Subsequent button pushes should be ignored. The controller needs to be connected to two input buttons (A and B), as well as a two LEDs (X1, X0) for output. Use the controller’s reset button for resetting the application. If input A goes from 0 to 1 first, then X is set to 012 (and stays there). If input B goes from 0 to 1 first, then X is set to 102 (and stays there) Note: You will not need any gates, flip-flops or a display-decoder, but you will need resistors for inputs and outputs.
; PORTB 6th and 7th pin are used to connect two LEDs. ; LED1 - PB6 ; LED2 - PB7 ; PORTD 2nd and 3rd pin are used to connect two input buttons. Which are used as interrupts and it generates interrupt during the rising edge of INT pin. That is from 0 to 1 ; ButtonA - PD2 - INT0 ; ButtonB - PD3 - INT1 .cseg .org 0x00 rjmp reset .org 0x01 rjmp INT0_VECT .org 0x02 rjmp INT1_VECT .org 0x34 reset: ldi r16,(1<<ISC00) | (1<<ISC01) | (1<<ISC10) |(1<<ISC11) out EICRA, r16 ;the rising edge of INT1 generates an interrupt. ldi r16, (1<<INT0) | (1<<INT1) out EIMSK, r16 ;enables external interrupts ldi r16, (1<<INTF0) | (1<<INTF1) out EIFR, r16 ;external interrupt flags are made high, when interrupt occurs it becomes low. ser r16 out DDRB, r16 ;PORTB as output clr r18 ;clears r18 register out DDRD, r18 ;PORTD as input out PORTB, r18 ;both LEDs are in off state sei ;enables global interrupt here: rjmp here INT0_VECT: cpi r18, 0x02 breq last ldi r18, 0x01 ldi r16, (1<<PB6) ;LED1 glows out PORTB, r16 last ldi r16, (1<<INTF0) out EIFR, r16 reti INT1_VECT: cpi r18, 0x01 breq last1 ldi r18, 0x02 ldi r16, (1<<PB7) ;LED2 glows out PORTB last1 ldi r16, (1<<INTF1) out EIFR, r16 reti
Quote:+------------------------------------------------------------+ | gavrasm gerd's AVR assembler Version 5.4 (C)2022 by DG4FAC | +------------------------------------------------------------+ Compiling Source file: exp1.asm ------- Pass: 1 Error ==> last ldi r16, (1<<intf0) [exp1.asm,44] 070:="" unknown="" instruction="" or="" macro! error="="> out PORTB [exp1.asm,56] 091: Missing or unknown parameter(s)! Error ==> last1 ldi r16, (1<<intf1) [exp1.asm,57] 070:="" unknown="" instruction="" or="" macro! 59="" lines="" done. compilation="" aborted,="" 3="" errors!<="" blockquote="">
last ldi r16, (1<<INTF0) ... last1 ldi r16, (1<<INTF1)
last: ldi r16, (1<<INTF0) ; add the colon label terminator ... last1: ldi r16, (1<<INTF1) ; add the colon label terminator
out
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)