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
;
; ------------------------
; 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
Outer MOVLW 200
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN
END

Write ASSEMBLY code to implement the following Initialize PORTB for.docx

  • 1.
    Write ASSEMBLY codeto 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.
    ; ------------------------ ; FUNCTIONOF 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
  • 3.
    Outer MOVLW 200 MOVWFLoop2 Inner NOP NOP DECFSZ Loop2,F GOTO Inner ; Inner loop = 5 usec. DECFSZ Loop1,F GOTO Outer RETURN END