A quad DIPS and a common cathode 7SD are interfaced to the HCS12 via PORTA and P
ID: 2085923 • Letter: A
Question
- A quad DIPS and a common cathode 7SD are interfaced to the HCS12 via PORTA and PORTB respectively. Write a program that will read the DIP switches and convert their settings to hex digit then display that digit on the 7SD. Assume that the 7SD is grounded. Draw the diagram for the circuit and explain where all pins are connected.
- A quad DIPS and a common cathode 7SD are interfaced to the HCS12 via PORTA and PORTB respectively. Write a program that will read the DIP switches and convert their settings to hex digit then display that digit on the 7SD. Assume that the 7SD is grounded. Draw the diagram for the circuit and explain where all pins are connected.
Explanation / Answer
Answer:- Common Cathode seven segment display requires Vcc on it's pin to show the number. Quad DIP switches are simple ON/OFF switch to control power flow.
Let's assume four switches are connected to portA at pin 0, 1, 2, and 3(rest are grounded). The 7SD LEDs(a, b, c, d, e, f and g) to portB pin 0, 1, 2, 3, 4, 5 and 6. So when we read portA pin as zero(0x00) then except LED "g" all should glow i.e at portB we need to write 00_1111_11 means 0x3F in hex. Similarly for rest values of switch combination the portB values are shown below-
assembly code for HCS12-
ORG $4000 ; starting code address
STAA $00 ; store value 0x00 in A
LDAA DDRA ; load value in A to DDRA, all pins of portA are now input
STAA $FF ; load value 0xFF in A
LDAA DDRB ; all portB pins are output pins
Loop1: ; label anme Loop1 starts here onwards
LDAA PORTA ; read portA pins and load to A
CMPA #$00 ; compare with given immediate data
LBEQ Display_1 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$01 ; compare with given immediate data
LBEQ Display_1 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$02 ; compare with given immediate data
LBEQ Display_2 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$03 ; compare with given immediate data
LBEQ Display_3 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$04 ; compare with given immediate data
LBEQ Display_4 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$05 ; compare with given immediate data
LBEQ Display_5 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$06 ; compare with given immediate data
LBEQ Display_6 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$07 ; compare with given immediate data
LBEQ Display_7 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$08 ; compare with given immediate data
LBEQ Display_8 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$09 ; compare with given immediate data
LBEQ Display_9 ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$0A ; compare with given immediate data
LBEQ Display_A ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$0b ; compare with given immediate data
LBEQ Display_b ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$0C ; compare with given immediate data
LBEQ Display_C ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$0d ; compare with given immediate data
LBEQ Display_d ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$0E ; compare with given immediate data
LBEQ Display_E ; if equal, goto label name given
LDAA PORTA ; read portA pins and load to A
CMPA #$0F ; compare with given immediate data
LBEQ Display_F ; if equal, goto label name given
BRA Loop1 ; go to label name Loop1
Display_0: ; Label Display_0 starts here
LDAA #$3F ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_1: ; Label Display_0 starts here
LDAA #$06 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_2: ; Label Display_0 starts here
LDAA #$5B ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_3: ; Label Display_0 starts here
LDAA #$4F ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_4: ; Label Display_0 starts here
LDAA #$66 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_5: ; Label Display_0 starts here
LDAA #$6D ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_6: ; Label Display_0 starts here
LDAA #$7D ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_7: ; Label Display_0 starts here
LDAA #$07 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_8: ; Label Display_0 starts here
LDAA #$7F ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_9: ; Label Display_0 starts here
LDAA #$6F ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_A: ; Label Display_0 starts here
LDAA #$77 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_b: ; Label Display_0 starts here
LDAA #$7C ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_C: ; Label Display_0 starts here
LDAA #$39 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_d: ; Label Display_0 starts here
LDAA #$5E ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_E: ; Label Display_0 starts here
LDAA #$79 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
Display_F: ; Label Display_0 starts here
LDAA #$71 ; load value 0x3F in A
STAA PORTB ; load value in A to portB
RTS ; go back from where controller has come to this sub-routine
END ; End of the program
PORT A PORT B 0x00 0x3F 0x01 0x06 0x02 0x5B 0x03 0x4F 0x04 0x66 0x05 0x6D 0x06 0x7D 0x07 0x07 0x08 0x7F 0x09 0x6F 0x0A 0x77 0x0b 0x7C 0x0C 0x39 0x0d 0x5E 0x0E 0x79 0x0F 0x71