Question
Write code on PIC16F877A microcontroller The MELabs X1 board contains an array of 16 button switches. These buttons are connected to the PORTB pins. B.0
Write code on PIC16F877A microcontroller
The MELabs X1 board contains an array of 16 button switches. These buttons are connected to the PORTB pins. B.0 to B.3 determine the row of the button and B.4 to B.7 determine the column. For example, if pins B.2 and B.6 have been cleared, then button SW11 (as painted on the X1 board) has been pushed.
1) Internal pull-up resisters are optionally connected to the PORTB pins within the PIC. We must enable these pull-ups by clearing OPTION_REG.7. We must also set PORTB pins to all be inputs with TRISB.
2) Write a program to poll the PORTB pins to determine if a button has been pushed, then determine which button.
3) Call a subroutine for each button which lights the LED's to a bit pattern to match the switch number of the button which was pushed.
The following code segment will turn on LED 0 if button SW 1 is pushed
banksel BANK1 movlw b'01111111' movwf (OPTION_REG ^ BANK1) ; enable pull-ups for PORTB main_loop: banksel BANK1 movlw b'11110000' movwf (TRISB ^ BANK1) ; enable PORTB column pins for input banksel BANK0 movlw b'00001110' ; clear pin for first row movwf PORTB btfss PORTB,4 ; test first column for SW 1 pressed bsf PORTD,0 ; light LED if SW 1 is pressed movlw .10 call delay10ms ; wait 100ms goto main_loop ; repeat polling forever
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started