'Using PIC16F88
'Identify and set the internal oscillator clock speed (required for the PIC16F88)
'Using configuration bits of the following
'Oscillator: INTRC-OSC2 as RA6
'Watchdog Timer: ON
'Power Up Timer: ON
'Code Protect: Off
'RA5/MCLR pin function select: RA5 (to use this pin as extra I/O instead of MCLR)
DEFINE OSC8
OSCCON.4=1
OSCCON.5=1
OSCCON.6=1
'Turn on and configure AN4 (A/D convertor on pin 3)
ANSEL.4=1 : TRISA.4=1 'sets up the A/D conerter on RA4/AN4 (pin3) and sets it to an input
ADCON1.4=1 'have 10 bits be right justified
DEFINE ADC_BITS 10 'AN4 is a 10-bit AD conversion
DEFINE ADC_CLOCK 3 'Sets clock to internal oscillator
DEFINE ADC_SAMPLEUS 10 'Pause for sampling, I don't actual use this anywhere in the program
'Initialize I/O pins
TRISB=0 'Set PORT B pins to all outputs
TRISA=%00010000 'Set PORT A pins to output except for RA4/AN4(pin 3), it will be set as an input
'Declare variables
ad_word Var Word 'Word from the A/D converter (10 bits padded with 6 0's)
P Var Word 'P is the calculated pressure variable from the reading of the pressure sensor
V Var Word 'V is the calculated airspeed from the pressure value
X Var Word 'X is a variable taking place of the calculation 2*9/1.2
maxp Con 60 'Max pressure reading of 60 Pa, random max pressure that can be changed
'main loop
main:
ADCIN 4, ad_word 'read value from voltage input on AN4, pin 3 and then store as ad_word
Pauseus 100 'check sampling time for that of the sensor and the pic to see if this value is correct
P = maxp * ad_word / 1023 'equation to calculate pressure using the variables and constants defined earlier
'Also contains 10 bit results
'Hopefully will output whole value without truncation, if it does find value to multiple by
X = 2 * P / 1.2
V = SQR X 'calculating velocity with the sqaure root of 2 times pressure (p) divide by density (1.2)
LCDOUT $FE, 1, "V"
Pause 100 'unsure of the pause and if this will show the dynamic change in airspeed
Goto main
End
Bookmarks