Hello.
I want to know how to work with multiple buttons and LED's for my work. I have 4buttons and 2LED's. when I press 1st button one LED must glow. when I Press Two buttons then 2 LED's must glow and when I press 3buttons it should work in an opposite manner to 1st case.
can anyone please help me?
This is where I'm
I want to know how to work with multiple buttons and LED's for my work. I have 4buttons and 2LED's. when I press 1st button one LED must glow. when I Press Two buttons then 2 LED's must glow and when I press 3buttons it should work in an opposite manner to 1st case.
can anyone please help me?
This is where I'm
Code:
list p=p16f628A
#include <p16f628A.inc>
__CONFIG _HS_OSC & _CP_OFF & _PWRTE_OFF & _WDT_OFF & _LVP_OFF & _MCLRE_ON
#define ledBlue PORTB,0 ; RB0
#define ledGreen PORTB,1 ; RB1
#define ledYellow PORTB,2 ; RB0
#define ledRed PORTB,3 ; RB1
#define botao1 PORTA,0 ; stsrts from RA0
#define botao2 PORTA,1 ; stsrts from RA0
#define botao3 PORTA,2 ; stsrts from RA0
#define botao4 PORTA,3 ; stsrts from RA0
org 0x00
goto iniciar
iniciar
banksel TRISB ; Selecção do banco 1
bcf TRISB,0
bcf TRISB,1
bcf TRISB,2
bcf TRISB,3
banksel PORTB ; Selecção do banco 0
MOVLW 0X07 ; put 0X07(literal or constant) in w
MOVWF CMCON ; RA1 passa a ser digital em vez de analógico(move content of W to CMCON)
Main btfsc botao1 ;Port A, input bit 0 = red button pushed?
goto Main1 ;Yes
MOVLW b'00000011' ; put 0X07(literal or constant) in w
MOVWF PORTA ; RA1 passa a ser digital em vez de analógico(move content of W to CMCON)
btfsc botao2 ;Port A, input bit 0 = red button pushed?
goto Main2 ;Yes
clrf PORTB ;turn off all LEDs
goto Main
Main1
MOVLW b'00000001' ; put 0X07(literal or constant) in w
MOVWF PORTB ; RA1 passa a ser digital em vez de analógico(move content of W to CMCON)
goto Main
Main2
MOVLW b'00000011' ; put 0X07(literal or constant) in w
MOVWF PORTB ; RA1 passa a ser digital em vez de analógico(move content of W to CMCON)
goto Main
end
Last edited by a moderator: