In: Electrical Engineering
Create an assembly language program on the 9S12 CPU to read switches and drive LED's
1-Configure all bits of Port U for output using address DDRU. There are 8 LEDs
connected to those pins. When you output a 1 to a bit, that bit will be enabled for
output, so when you later write a 1 to a bit in port U (PTU) that LED will turn ON.
2. Switches are attached to Port T. They work by grounding the bit when switched
on, (negative logic): ON = 0, OFF = 1. The PCB supplies pull-up resistors.
3. Read the switches, and configure your program so that if switch 1 is on, you
send out a data pattern which will make the even LEDs turn ON, others OFF.
4. If switch 2 is on, make the lower 4 LEDs ON and the higher 4 LEDs OFF
5. If switch 3 is ON, start out lighting the LED for bit 0, then move the light left until
the LED for bit 7 is ON. After that, turn OFF all LEDs, then turn on the LED for a bit
7 again and move the light back towards the LED for bit 0. After it gets there, turns all the LEDs OFF again, then repeat the cycle until the switch changes).
Note: for all of the above you will have to keep going back afterward and reading the switch to see if it has changed.
6. Add a delay to your program so the human eye can see the operation!
Answer :- The code has been written below-
ldaa #$FF ;load value 1111_1111 into register A
staa DDRU ;make port U pins as output
ldaa #$00 ;load value 0000_0000 into register A
staa DDRT ;make port T pins as input
Loop1: ;label name Loop1
ldaa PTT ;read port T pins and keep in A
cmpa #$FE ;check if switch 1 is pressed
beq Case1 ;if yes then goto label named as Case1
cmpa #$FD ;check if switch 2 is pressed
beq Case1 ;if yes then goto label named as Case1
cmpa #$FB ;check if switch 3 is pressed
beq Case1 ;if yes then goto label named as Case1
bra Loop1 ;goto label Loop1, infinite loop
Case1:
ldaa #$55 ;register A = 0101_0101
staa PTU ;make even leds on
bra Loop1 ;go back to loop1
Case2:
ldaa #$0F ;register A = 0000_1111
staa PTU ;make lower 4 leds on, higher 4 off
bra Loop1 ;go back to loop1
Case3:
ldaa #$01 ;register A = 0000_0001
staa PTU ;led 0 is on
call delay1
lsla
staa PTU ;led 1 is on
call delay1
lsla
staa PTU ;led 2 is on
call delay1
lsla
staa PTU ;led 3 is on
call delay1
lsla
staa PTU ;led 4 is on
call delay1
lsla
staa PTU ;led 5 is on
call delay1
lsla
staa PTU ;led 6 is on
call delay1
lsla
staa PTU ;led 7 is on
call delay1
lsla
staa PTU ;all leds off
call delay1
ldaa #$80 ;register A = 1000_0000
staa PTU ;led 7 is on
call delay1
lsra
staa PTU ;led 6 is on
call delay1
lsra
staa PTU ;led 5 is on
call delay1
lsra
staa PTU ;led 4 is on
call delay1
lsra
staa PTU ;led 3 is on
call delay1
lsra
staa PTU ;led 2 is on
call delay1
lsra
staa PTU ;led 1 is on
call delay1
lsra
staa PTU ;led 0 is on
call delay1
lsra
staa PTU ;turn off all led
call delay1
bra Loop1 ;go back to loop1
delay1:
ldaa #$FF ;A = 255
loop2:
deca
cmpa #$00
bne loop2
rts ;return from subroutine