/******************************************************************* * FileName: (change filename of template).c * Processor: PIC18F4520 * Compiler: MPLAB C18 v.3.06 * * This file does the following.... * * Creation and Revisions: * Author Date Comments * (Your name here) ********************************************************************/ /** Header Files ***************************************************/ #include #include #include "LCD Module.h" /** Configuration Bits *********************************************/ #pragma config OSC = EC // EC = External 4MHz Crystal for PICDEM board only #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF #pragma config XINST = OFF /** Global Variables ***********************************************/ int RA0result; int Nstars; int i; /******************************************************************* * Function: void main(void) ********************************************************************/ #pragma code void main (void) { ADCON1=0x0E; TRISAbits.RA0=1; OpenADC( ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS, 0x0E ); XLCDInit(); XLCDClear(); while (1) { ConvertADC(); // Start conversion while( BusyADC() ); // Wait for completion RA0result = ReadADC(); // Read result Nstars=RA0result/103; XLCDL1home(); for (i=1; i<=10 ; i++) { if (i <= Nstars) XLCDPut(42); else XLCDPut(32); } } } /* Alternate to for-loop for printing stars to LCD display if ( RA0result <= 1023/10 ) XLCDPutRomString(" "); else if ( RA0result <= 1023/5 ) XLCDPutRomString("* "); else if ( RA0result <= 1023*3/10 ) XLCDPutRomString("** "); else if ( RA0result <= 1023*2/5 ) XLCDPutRomString("*** "); else if ( RA0result <= 1023/2 ) XLCDPutRomString("**** "); else if ( RA0result <= 1023*3/5 ) XLCDPutRomString("***** "); else if ( RA0result <= 1023*7/10 ) XLCDPutRomString("****** "); else if ( RA0result <= 1023*4/5 ) XLCDPutRomString("******* "); else if ( RA0result <= 1023*9/10 ) XLCDPutRomString("******** "); else XLCDPutRomString("*********"); */