Hi everyone,
Hoping you might be able to help me with a little project I’ve been working on….
I’ve been trying to create a code that reads in a value (b0) from an
a/d converter, this then goes to a timer routine which loops ‘b0’ amount of times and then sends PORTB.3 high. I’ve programmed the following onto a pic16f628a and then added it to the circuit…. from first impressions it all looks great! However…. By watching the LED’s attached to pins 5,6,7 and 8 I can see that it’s adding up a different amount each time, even though the value from the A/D converter should be the same. Can anyone spot where I’m going wrong here as it’s left me pretty confused!
Many thanks, Alex
-----------------------------------------------
CMCON = 7
INCLUDE "modedefs.bas"
TRISB = 1
TRISA.0 = 1
ti var byte 'Initial time delay
b0 var byte 'serial value from a/d converter
timer var byte
ti = 1000 'timer value
timer = 0
b0 = 0
start:
portb = 128 'flash
pause 400
portb = 0
pause 400
IF porta.0 = 1 THEN start
Serial_in:
low 1 'bring I/O clock low
low 2
pause 1000
b0.7 = PORTB.0
pulsout 1,1
pause 500
b0.6 = PORTB.0
pulsout 1,1
pause 500
b0.5 = PORTB.0
pulsout 1,1
pause 500
B0.4 = PORTB.0
pulsout 1,1
pause 500
b0.3 = PORTB.0
pulsout 1,1
pause 500
b0.2 = PORTB.0
pulsout 1,1
pause 500
b0.1 = PORTB.0
pulsout 1,1
pause 500
b0.0 = PORTB.0
pulsout 1,1
pause 500
high 2
pause 1000
Timer_routine:
b0 = b0 * 5
if timer > b0 then Execute 'check
portb = 16
pause ti
timer = timer + 1
portb = 32
pause ti
timer = timer + 1
portb = 64
pause ti
timer = timer + 1
portb = 128
pause ti
timer = timer + 1
goto Timer_routine
Execute:
timer = 0
portb = 8 'send signal to relay
pause 4000
b0 = 0 'reset b0
goto start
Bookmarks