In: Electrical Engineering
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality:
Configures pin RA2 of the PIC24to be an output to control an attached LED.
Configures pin RB13 of the PIC24 to be an input to read the value on an attached switch (this switch will connect to ground when pressed).
Configures pin RB13 to use the internal pull-up resistor.
After configuration, the LED will be "off" when the push-button is pressed, and "on" when it is released.
Remember, since this is an assembly language program you cannot
use the C-language macros. Also, that in an assembly language
program the name of a register is a reference to its memory
location.
Start bank1 ;Go to bank 1 movlw b'1111111111111011' ;Set the port pin types of RA movwf TRISA ;RA2 port is set as output movlw b'0010000000000000' ;Set the port pin types of RB movwf TRISB ;RB13 is the input bank0 ;Go to bank 0 MainLoop btfss PORTB,13 ;Read RB13 pin goto Button_Is_Off ;If RB13 is '0', then goto Button_Is_Off Button_Is_On bsf PORTA,2 ;Set RA2 output goto MainLoop ;And go back to the Main Loop Button_Is_Off bcf PORTB,13 ;Clear RB13 input goto MainLoop ;And go back to the Main Loop