Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program (in assembly language) that will do the following. Provides cont

ID: 3557146 • Letter: W

Question

Write a program (in assembly language) that will do the following.

Provides control of 8 LEDS split into three groups.

Green : RA1, RB1

Yellow : RA2, RB0, RB2, RB3

Red : RA0, RA3

Upon energizing, it performs a brief test of all 8 lights (5 seconds off and 5 seconds on)

After the test, the lights are controlled by three switches.

If all switches are off, all lights are extinguished.

If switch 1 is on, regardless of other switch's positions, all lights will blink.

If switch 2 is on and switch 1 off, the green and red lights will alternate.

Explanation / Answer


#include <GENERAL.H> ;This is the header file you created for this lab#1
COUNT1          EQU            0X20                                      ; Counter for the inner loop
COUNT2          EQU            0X21                                      ; Counter for the middle loop
COUNT3          EQU            0X22                                      ; Counter for the outer loop
    __CONFIG          0X3FF6 ;This is the control bits for CONFIG register

   ORG    0X0000                  ;RESET or WDT reset vector
   GOTO   START

   ORG    0X0004                  ;Regular INT vector
;This is the area where your interrupt service routine goes
    RETFIE

START                          ;The starting place of the user codes
   ; The I/O must be set up. Pins 7,8,9,10 (PORTB) and 17,18,1,2 (PORTA)
   ; All other pins are inputs. This allows both port latches to use the same literal
   CLRF     PORTA                 ; Ensure both port latches are all 0 before
   CLRF     PORTB                 ; setting up I/O

   BSF      STATUS,RP0            ; Shift to bank 1 to change TRIS registers
   MOVLW    0XF0                  ; TRISA and TRISB both use F0 to have pins 0 - 3
   MOVWF   TRISA                  ; as outputs
   MOVWF   TRISB
   MOVLW    0XFE
   MOVWF   OPTION_REG             ; The prescales needs to be set to 04 for the
   ; watchdog timer to time out 1.15 seconds
   BCF     STATUS,RP0             ; Shift to bank 0 for normal operation
   MOVLW    0X0F                  ; This will illuminate all lights
   MOVWF   PORTA                  ; when it is loaded in both ports
   MOVWF   PORTB
   CALL    DELAY5s                ; Provides a 5 second delay
   CLRF    PORTA                  ; This will extenguish all lights
   CLRF    PORTB                  ; when it is loaded in both ports
   CALL    DELAY5s                ; Provides a 5 second delay

SWTEST
   CLRWDT
   BTFSC   PORTB,RB5              ; This is the switch for all LEDs being lit
   CALL    ALLIGHTS               ; (Switch 3)
   CLRWDT
   BTFSC   PORTB,RB6              ; This is the switch for red LEDs beig lit
   CALL    GREENLIGHTS            ; (Switch 2)
   CLRWDT
   BTFSC   PORTB,RB7              ; This is the switch for the yellow LEDs being lit
   CALL    YELLOWLIGHTS           ; (Switch 1)
   MOVLW   0X00                   ; This will extenguish all lights
   MOVWF   PORTA                  ; when it is loaded in both ports
   MOVWF   PORTB
   GOTO    SWTEST                 ; Return to the top of the switch test loop

ALLIGHTS
   MOVLW   0X0F                   ; This will illuminate all lights on PORTA
   MOVWF   PORTA
   MOVLW   0X00                   ; and extenguish all on PORTB
   MOVWF   PORTB
   CALL    DELAY
   MOVLW   0X00                   ; This will extenguish all lights on PORTA
   MOVWF   PORTA
   MOVLW   0X0F                   ; and illuminate all lights on PORTB
   MOVWF   PORTB
   CALL    DELAY
   RETURN                         ; Return to the top of the switch test loop

GREENLIGHTS
; If switch 2 is set, only RA1 and RB1 must be illuminated, the delay called, and then
; lit, and the delay called
   MOVLW   0X04                    ; This will light the green lights only
   MOVWF   PORTA
   MOVLW   0X02
   MOVWF   PORTB
   CALL    DELAY
   MOVLW   0X09                    ; This will light the red ights only
   MOVWF   PORTA
   MOVLW   0X00
   MOVWF   PORTB
   CALL    DELAY
   RETURN

YELLOWLIGHTS
; If switch 3 is set,RA2, RB0, RB2, RB3 must be turned on, the delay called
; and then RA0 and RA1 turned on, and the delay called again.
   MOVLW    0X02                   ; This will light the yellow lights only
   MOVWF   PORTA
   MOVLW    0X0D
   MOVWF   PORTB
   CALL    DELAY
   MOVLW    0X09                   ; This will light the red lights only
   MOVWF   PORTA
   MOVLW    0X00
   MOVWF   PORTB
   CALL    DELAY
   RETURN                          ; Return to the top of the switch test loop

DELAY
; This subroutine is a fixed delay loop. It is 2,393,421 clock cycles long, for
; a wait time of .4799 seconds with a 20 MHZ resonator.
   CLRF    COUNT1
   CLRF    COUNT2
   CLRF    COUNT3
   MOVLW    0X7E                    ; (1)
   MOVWF   COUNT3                   ; (1)
LOOPOUT
   MOVLW    0X4F                    ; (1)
   MOVWF   COUNT2                   ; (1)
LOOPMID
   MOVLW    0X4F                    ; (1)
   MOVWF   COUNT1                   ; (1)
LOOPIN
   DECFSZ COUNT1,F                 ; (1 of 2) ((78*3 + 2 + 2 + 3)78 + 2 + 2 + 3)*125 + 2 + 2 + 3 + 3
   GOTO    LOOPIN                   ; (2)
   ; This will be executed 29 times
   DECFSZ COUNT2,F                 ; (1 of 2)
   GOTO    LOOPMID                  ; (2)
   ; This loop will be executed 29 times
   DECFSZ COUNT3,F                 ; (1 of 2)
   GOTO    LOOPOUT                  ; (2)
   ; This loop will be executed 126 times
   RETURN                           ; (2)

DELAY5s
;24999994 cycles
   MOVLW    0xE3
   MOVWF    COUNT1
   MOVLW    0x7F
   MOVWF    COUNT2
   MOVLW    0x37
   MOVWF    COUNT3
Delay_0
   DECFSZ    COUNT1, f
   GOTO    next1
   DECFSZ    COUNT2, f
next1
   GOTO    next2
   DECFSZ    COUNT3, f
next2
   GOTO    Delay_0
   ;2 cycles
   NOP
   ;4 cycles (including call)
   RETURN

   END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote