Hi all
I have got an ultrasonic distance measuring project to do for one of my varsity subjects and have hit a snag or three. (Im using a PIC16F628A, PBP version 2.45 and microcode studio plus version 2.1.0.7)
basically the program after turn on waits for a button (RB5) to be pressed which starts the measurement process, after that HPWM on RB3 sends out a 40kHz signal for 2ms then stops, after that timer1 starts at a preset value of 1000 and a prescaler value of 1:2, then it must wait for an external interrupt on RB0 (a change in digital value i.e. 0 to 1 or 1 to 0) and as soon as that interrupt is detected timer1 must stop and a speaker must sound for 1 second (RB4). after that the temperature measurement must take place (using OWIN & OWOUT, DS1820) then the distance can be calculated and then displayed on an LCD.
First question: how do I setup Timer1 to start at a preset value of 1000 and a prescaler value of 1:2
Second question: how do i setup the PIC16F628A? i have found the "@ DEVICE" stuff but it wont work in microcode studio.
Third question: How to get the interrupt working as the interrupt must be enabled immediately after timer1 starts and disabled immediately after timer1 stops, the time frame could be anywhere from 2.5ms to 120ms
thought of using this:
T1CON.0 = 1 'start timer1
tmp:
if (PORTB.0 = 1) then goto tmp 'check for port change low to high
T1CON.0 = 0 'stop timer1
SOUND PORTB.4, [128,84] 'sound buzzer at about 10kHz for about 1 second
the problem is what if portb.0 already is high? hence the need for a change type of interrupt but again the interrupt must only be active during that particular point in the code
so it would need to go something like this:
T1CON.0 = 1
enable interrupt
PAUSE 150
disable interrupt
if interrupt is triggered then
disable interrupt
T1CON.0 = 0
SOUND PORTB.4, [128,84]
return to the end of the pause
any help would be greatly appreciated as I'm a bit of a novice with this and this is my first time using PBP and Microcode Studio Plus
Cheers
Guy
Bookmarks