Hi guys!
I am very new to this PBP programming language as well as with the PIC microcontroller and would like to get as much advice as I can on to learning this new program. 
The Pic I'm using is the PIC16F88 running at 8Mhz and it will be compiled with MPELab IDE (correct me if I'm wrong, which this is using the PicBasic Pro)
What I am trying to achieve is to count the Delay between knocks (based on Steve's Secret Knock Detector system @ www.grathio.com)
So far i've read through all the clock programs that are available on this forum but i'm still confused as to how to modify the program to only count in milliseconds for the delays and then store it in an array.
I have defined an array which is set as the "main" code:
secretCode VAR word[3] 'maximum of three knock values
i var byte 'declares i as counter in bytes
'initial setup
secretCode[0] = 100 'in milliseconds
secretCode[1] = 100
secretCode[2] = 100
knockReadings VAR word[3] 'delay between knocks during input
once a knock has been detected, it goes into the loop defined:
Code:
listenToKnock:
currentKnockNumber var byte 'define new variables
startTime var byte 'define new variables
now var byte 'define new variables
myTime VAR word 'the current time
i = 0 'sets I counter as 0
for i = 0 to 2
knockReadings[i] = 0 'first value is stored for the delay
currentKnockNumber=0 'Incrementer for the array.
startTime=0 'Reference for when this knock started.
now=0 'Reference for current knock
while Knock =0 && myTime < 1200 'no knocks,
'continue counting
GoSub SetTimer 'trying to set it to end at 1200
'mS
goto EndTime
wend
knockReadings[i] = myTime 'is this correct in saving the
'delay time into this array?
next i
goto main 'returns to main loop
SetTimer:
T1CON.0 = 0 'stops Timer1
TMR1H = 0
TMR1L = 0
T1CON.0 = 1 'StartTimer
resume
EndTime:
CLEARWDT '<--- is the clearwatchdog required?
myTime.Highbyte = TMR1H 'gets high value
myTime.Lowbyte = TMR1L 'gets rest of value
If myTime < 1200 then '<--- im not sure how to define this in the
'first place so that if more than 1.2 seconds
'that the input is low, jump out of the loop
myTime = 0
endif
Resume
PS: I am not here to annoy everyone, but I am trying my best to understand how to work with PBP and the 16F88 pic. Any advice would be appreciated!
Bookmarks