Write ASSEMBLY code to implement the following Initialize PORTB for.docx
1. Write ASSEMBLY code to implement the following: Initialize
PORTB for using the LED's by calling the led-enable function
(in the library). Also call TermInit. Prompt the user to set the
data switches at Port H (PTH). [Prompt means print a prompt
string.] The program now waits until a Space key (ascii $20)
press is detected and then stores the value that is now on Port H
(PTH) at memory location $1000. The program waits for the
Space key press by calling a subroutine called Wait4SP. Then
the program writes the value that is now in location $1000 to
the LED display on (PORTB) The program returns to Step 2, if
the value in location $1000 (which is also on the LED display)
is a two's complement negative number; otherwise waits (doing
nothing) for the reset button to be pressed.
Solution
ORG 0x000 ; Program starts at 0x000
;
CLRF PORTB ; Initialize port B
;
BSF STATUS,RP0 ; RAM bank 1
;
CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
CLRF TRISC ; All pins port C output
;
2. ; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 6
MOVWF ADCON1 ; All pins digital I/O
;
BCF STATUS,RP0 ; RAM bank 0
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,0 ; Turn on LED connected to RA0
CALL delay
BCF PORTA,0 ; Turn off LED connected to RA0
CALL delay
GOTO Main
;
; ---------------
; DELAY 250 MSEC
; ---------------
;
delay MOVLW 250
MOVWF Loop1