biboymusic
Member
I just finished coding and I can't seem to get RB0 interrupt to work. Can anyone test this code for me and verify if it is my board that's faulty. Thanks.
Code:
program Speedometer
' Declarations section
Dim cntr as integer
Dim ovrflw as integer
Dim speed as integer
Dim spddisp as string[3]
Sub procedure interrupt
if INTCON.INTF = 1 then
cntr = cntr + 1
INTCON.INTF = 0
end if
if INTCON.T0IF = 1 then
ovrflw = ovrflw + 1
INTCON.T0IF = 0
end if
end sub
sub function Mask(dim num as byte) as byte 'Chnge values to suit your 7 seg conf
select case num
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
main:
' Main program
' Main program
TRISB = %00000001
TRISA = 0
OPTION_REG = %11011000
'Test
PORTA = 0
PORTB = Mask(8)
Delay_ms(1000)
PORTA = 1
speed = 123
'End Test
while TRUE
cntr = 0
ovrflw = 0
INTCON = %10110000
while (ovrflw < 3906) 'Wait 1 sec: 3906 = 4000000 / 4 / 256
'Display speed here 'Test Formula: (1 Rotation x 60 x 60) / 1000
PORTA.1 = 0
PORTB = Mask(spddisp[0])
delay_ms(5)
PORTA.1 = 1
PORTA.2 = 0
PORTB = Mask(spddisp[1])
delay_ms(5)
PORTA.2 = 1
PORTA.3 = 0
PORTB = Mask(spddisp[2])
delay_ms(5)
PORTA.3 = 1
wend
INTCON.GIE = 0
speed = (cntr * 60 * 60) div 1000
IntToStr(speed, spddisp)
wend
end.
Last edited: