I need some help here, i'm getting crazy
i want to read 2 adc channels and sent the data serial out,
if it moves uit of center ( >140 or <115) of any of 2 channels it should sent the data out
But when channel X goes out of center up over 140 and it returns to center within 0,5 second (very fast center => Up => center), it should sent a "short"signal once .
but somehow i can't seem to get it work al the time
Here's what comes closes en work 80%, because after a up over 140 longer than 0,5 seconds it does not reset after it reaches center again, then i first got to move X under 115 for it actually resets the tip1 counter.
what am i doing wrong, or who has a simpler solution, because i want it to work on 4 different directions with different short out commands
My try so far:
pic16F876 at 8 mhz:
clear
define osc 8
include "modedefs.bas"
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 51
DEFINE ADC_BITS 8
TRISA = 255
ADCON1 = 0
trisb=%11000000
trisc=%00000001
portb=0
joy_x var byte
joy_y var byte
uit_x var byte
uit_y var byte
tip1 var word
tip2 var word
tip1=0
tip2=0
main:
ADCIN 2, uit_x
adcin 3, uit_y
if (uit_x > 145) then 'x out of center going up
pause 100
tip1=tip1+1
if tip1 < 10 then tip2=1 'shorter than 0,5 second
endif
if (uit_x < 140) and tip2=1 then 'x is back to center
hserout ["short"]
pause 10
portb.1=1
pause 100
portb.1=0
tip2=0
endif
if (uit_x > 140) or (uit_x < 115)or (uit_y > 140) or (uit_y < 115) then
portb.0=1
hserout ["data",uit_x,uit_y]
portb.0=0
if (uit_x < 140) and (uit_x > 110) and (tip1 > 11) then tip1=0
endif
Bookmarks