Example Code
Coded for the CCS PCM C-Compiler and used in the PIC16F877
//////////////////////////////////////////////////////////////////////////////////////////////////////
////
////
////
AIRSDEM.C for the PIC16F877
////
////
////
///
Analog Infra-Red Range-finding System (AIRRS)
////
////
Demo Program
////
////
////
////
HVW Technologies, March 2000
////
///
http://www.HVWTech.com
////
////
////
//// Program uses A/D Channel 1 (pin 3) to read the AIRRS
////
//// module output(blue wire). Sends analog value to Matrix
////
//// Orbital LCD module on port b5 (pin 38) at 19200 baud.
////
////
////
////
Coded for the CCS PCM C-Compiler
////
////
////
/////////////////////////////////////////////////////////////////////////////////////////////////////
#include <1 6 F877.h>
//Include Standard CCS header file
#fuses xt,nowdt,noprotect
//Configuration bits specific to demo board used
#use delay(clock=4000000)
//Oscillator = 4 MHZ
#use rs232(baud=19200, xmit=pin_b5, rcv=pin_b4,invert)
//Remove 'invert' option if using MAX232 or similar
//When communicating to the Matrix Orbital LCD
long value;
//Define variable Long integer
Main()
{
setup_ADC_ports(ALL_Analog);
//Setup all analog pins as only analog
setup_ADC(ADC_CLOCK_INTERNAL); //Configure D converter to use internal oscillator
set_ADC_CHANNEL(1);
//Set pin_A1 to measure analog voltage
While(TRUE)
{
delay_ms(500);
//Pause for 0.5 seconds for LCD to update
value=READ_ADC();
//Take analog and wait for conversion
putc(0xfe);
//Command Prefix
putc('X');
//Clear Screen Command
printf("Analog= %Lu",value);
//Formatted printing of Analog result
}
}
Technical Support
Technical support is available if you are having problems. If you need help,
please provide as much detailed information as possible.
Phone: (403) 730-8603 (Monday - Friday 9am – 5pm Mountain time)
E-mail: [email protected]