PIC JAL IO Routine

Counter

by M. Yalin Duyur

With help from Rob Curtis

it is a good way to count pin_b7s but when you forget your finger on it 8)) it counts by it self I don't want it (when you count a wheels spin it is slow. ok decreasing debounce_delay works but when wheel stops on the button you couldn't see the spins count ) for my job my code is better than yours 8))

-- name    : counter.jal
-- authors : M.YALIN DUYUR & ROB CURTIS
-- date    : August 2000

include 16f84_4
include jlib
include jseven

port_b_direction = all_output
port_a_direction = all_output

var byte a, b, c, d, x
var byte pincount
var byte debounce_delay
pincount = 0
debounce_delay = 5
a = 0
b = 0
c = 0
d = 0

procedure display (byte in d4, byte in d3, byte in d2, byte in d1) is
port_a = 0b_0111
port_b = seven_from_digit (d4)
delay_1ms (5)
port_a = 0b_1011
port_b = seven_from_digit (d3)
delay_1ms (5)
port_a = 0b_1101
port_b = seven_from_digit (d2)
delay_1ms (5)
port_a = 0b_1110
port_b = seven_from_digit (d1)
delay_1ms (5)
end procedure

procedure count is
a = a + 1
if a == 10 then
a = 0
b = b + 1
end if
if b == 10 then
b = 0
c = c + 1
end if
if c == 10 then
c = 0
d = d + 1
end if
if d == 10 then
d = 0
end if
end procedure

-- Thanks ROB
procedure TestPort is
   pin_b7_direction = input
  if pin_b7 & pincount < debounce_delay  then 
    pincount = pincount + 1
    if pincount == debounce_delay  then Count end if
  else
  pincount = 0
end if

end procedure

forever loop
TestPort
display (d, c, b, a)
end loop

Questions:

Interested: