implement a scoreboard for a stadium, such that it shows the HOME and VISIT counter. The counter of each team always goes ascending from 0 to 9, initially both counters are at zero (Local 0 - 0 Visit), to increase the value of the counter of each team a button will be used for each one independently.
The pin assignment in the connection is as follows:
PIN I/O Description RA0 input GOL_LOCAL, button to increase the home score RA1 Input GOAL_VISITA, button to increase the visit marker RB0 Output LOCAL_A, Digit A of the local marker binary code RB1 Output LOCAL_B, Digit B of the local marker binary code RB2 Output LOCAL_C, Digit C of the local marker binary code RB3 Output LOCAL_D, Digit D of the local marker binary code RB4 Output VISIT_A, Digit A of the binary code of the visit marker RB5 Output VISIT_B, Digit B of the binary code of the visit marker RB6 Output VISIT_C, Digit C of the binary code of the visit marker RB7 Output VISIT_D, Digit D of the binary code of the visit marker
To show a digit on the display using binary code and the 7447 decoder, you must Use the following table as a reference.
Decimal D C B A 0 0 0 0 0 1 0 0 0 1 2 0 0 1 0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1 1 0 7 0 1 1 1 8 1 0 0 0 9 1 0 0 1
SUGGESTED LOGIC FOR SENDING DATA TO THE 7-SEGMENT DISPLAYS:
For example, if you want to show the marker LOCAL 2 – VISIT 1, through port B you must send the following BCD combination for LOCAL and VISIT
| VISIT_D | VISIT_C | VISIT_B | VISIT_A | LOCAL_D | LOCAL_C | LOCAL_B | LOCAL_A |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
To achieve this you may consider using 2 counters separately, one for the HOME goal count and another for the Away goal count.
local_counter
| Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
Visit_Counter
| Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
To get the BCD combination needed to display LOCAL 2 – VISIT 1 we need to move the Visit_Counter 4 positions to the left, which would give usa new value for Visit_Counter.
Visit_Counter
| Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
Finally we can perform the OR operation between the values of the variables Local_counter and Visit_counter, obtaining the desired result that must be send through port B.
| VISIT_D | VISIT_C | VISIT_B | VISIT_A | LOCAL_D | LOCAL_C | LOCAL_B | LOCAL_A |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |

This is as far as I could go on my part.
LIST P=16F84A
INCLUDE <P16F84A.INC>
CBLOCK 0X0C
Counter
ENDC
ORG 0
bsf STATUS,RP0
movlw 0x00
movwf TRISB
bsf TRISA,RA0
bcf STATUS,RP0
clrf Counter
clrf PORTB
Loop
btfsc PORTA,RA0
goto $-.1
btfss PORTA,RA0
goto $-.1
movf Counter,W
call TABLE
movwf PORTB
incf Counter,F
movlw .10
subwf Counter,W
btfsc STATUS,Z
clrf Counter
goto Loop
BOARD
addwf PCL,F
DT 1,2,3,4,5,6,7,8,9,0
END
I tried this code in the proteus simulator but it doesn't generate what I need completely. What am I missing in my code?
Ready to go. I've made some fixes in your code to make it comply the requirements. As you will see in the code, I used 2 variables named
scoreOfLocalTeamandscoreOfVisitorTeaminstead of the former singleCountervariable. This way scores for each team is saved its own variable.Although the code is self explanatory, here is how it works briefly:
RA0andRA1is pressed, 1 score is added to the corresponding team.PORTBaccording to the tables in your question.PS: The code is not tested since it is microcontroller specific. So I'd like to hear from your feedback whether it worked.