deepgfishing
- 22nd June 2007, 18:20
Hello.
I am new to this as I explained in previous thread.
i am creating a tilt sensor as a project.
I have a board that has two accelerometers on it. The accelerometers are fed into my pic18F242 microcontroller. I want the microcontroller to spit out what the accelerometer reading is in digital format so i can read it via hyperterminal on my computer.
If that works i will feed the accelerometer data to an RF device and do it remotely but i have to see if i get data from microcontroller first.
Does this program look like it will work?
************************************************** *****
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 15 ' Set sampling time in uS
tx var portB.0
rx var portA.0
n9600 con 16468
adcVar VAR word[4] ' Create variable to store results
channel var byte
byteVar var byte[4]
inByte var byte
' set Sleep pin high:
''HIGH PORTD.0
' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1:
' All are analog inputs
ADCON1 = %10000000
main:
' read all channels of the accelerometer:
for channel = 0 to 3 ' read the two accelerometers from pin 0 - 3
ADCIN channel, adcVar[channel]
' convert to a byte:
byteVar[channel] = adcVar[channel] /4
pause 1
next
' send results out the serial port:
serout2 tx, n9600, [byteVar[0],byteVar[1],byteVar[2], byteVar[3]]
GoTo main
************************************************** *****
I am new to this as I explained in previous thread.
i am creating a tilt sensor as a project.
I have a board that has two accelerometers on it. The accelerometers are fed into my pic18F242 microcontroller. I want the microcontroller to spit out what the accelerometer reading is in digital format so i can read it via hyperterminal on my computer.
If that works i will feed the accelerometer data to an RF device and do it remotely but i have to see if i get data from microcontroller first.
Does this program look like it will work?
************************************************** *****
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 15 ' Set sampling time in uS
tx var portB.0
rx var portA.0
n9600 con 16468
adcVar VAR word[4] ' Create variable to store results
channel var byte
byteVar var byte[4]
inByte var byte
' set Sleep pin high:
''HIGH PORTD.0
' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1:
' All are analog inputs
ADCON1 = %10000000
main:
' read all channels of the accelerometer:
for channel = 0 to 3 ' read the two accelerometers from pin 0 - 3
ADCIN channel, adcVar[channel]
' convert to a byte:
byteVar[channel] = adcVar[channel] /4
pause 1
next
' send results out the serial port:
serout2 tx, n9600, [byteVar[0],byteVar[1],byteVar[2], byteVar[3]]
GoTo main
************************************************** *****