biboymusic
Member
Code:
program Speedometer
dim cnt as word
dim _ones as byte
dim _tens as byte
dim _hund as byte
sub function Mask(dim num as byte) as byte ' this function returns masks
select case num ' for common cathode 7-seg. display
case 0 result = 252
case 1 result = 48
case 2 result = 218
case 3 result = 122
case 4 result = 54 '00110110
case 5 result = 110 '01101110
case 6 result = 238 '11101110
case 7 result = 56 '00111000
case 8 result = 254 '11111110
case 9 result = 126 '01111110
end select 'case end
end sub
sub procedure interrupt
cnt = cnt + 1
if _hund > 0 then
PortA.1 = 0
PortB = Mask(_hund)
End if
Delay_ms(5)
PortA.1 = 1
if _tens = 0 then
if _hund > 0 then
PortA.2 = 0
PortB = Mask(_tens)
end if
else
PortA.2 = 0
PortB = Mask(_tens)
end if
Delay_ms(5)
PortA.2 = 1
if _tens = 0 then
if _ones <> 0 then
PortA.3 = 0
PortB = Mask(_ones)
end if
else
PortA.3 = 0
PortB = Mask(_ones)
end if
Delay_ms(5)
PortA.3 = 1
TMR0 = 96
INTCON = $20
INTCON.INTF = 0
end sub
main:
Option_reg = $84
'Initialize Ports
TrisB = %00000001
TrisA = 0
PortB = 254
PortA = %00000
'Flash for power check
Delay_ms(300)
PortA = %11111
'Set variables
_ones = 0
_tens = 0
_hund = 0
'Initialize Timer
TMR0 = 96
INTCON = $A0
INTCON.INTE = 1
INTCON.INTF = 0
cnt = 0
while True
If PortB.0 = 0 then
if (cnt = 1) then
_ones = _ones + 1
if (_ones) > 9 then
_tens = _tens + 1
_ones = 0
if (_tens) > 9 then
_hund = _hund + 1
_tens = 0
if (_hund) > 9 then
_hund = 0
end if
end if
end if
cnt = 0
end if
end if
wend
end.
I need help on the code above. I've configured RB0 as input but it doesn't respond if I connect it to ground (0). My sample code above starts counting while RB0 = 0 and stops when it's High. The port has a pull up resistor 4.7K.
Last edited: