superbrew
Member
Hello, I would like to display the result of an ADC conversion on my GLCD, but all I am getting is about 2.5 lines of garbage. Here is the code that I am using:
(GLCD functions created by Pommie and modified for my use)
Stepping through using MPLAB simulator, it seems to get hung up at the itoa function. Thanks
(GLCD functions created by Pommie and modified for my use)
Code:
#include <p18f2520.h>
#include <GLCD.h>
#include <adc.h>
#include <delays.h>
#include <stdlib.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67
void main (void){
int read;
char adc_ret[10];
ADCON1 = 0x0d;
CMCON = 0x07; // no comparators
OSCCON = 0x70;
TRISA = 0XFF;
TRISC = 0x00;
//Setup
Init_GLCD();
OpenADC(ADC_FOSC_RC & ADC_LEFT_JUST & ADC_12_TAD,
ADC_CH1 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 13);
SetChanADC( ADC_CH1 );
PutMessage((rom char*)"test");
Delay10KTCYx(200);
while (1){
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
read = 523;ReadADC();
itoa(read,adc_ret);
PutMessage((rom char*)adc_ret);
Delay10KTCYx(250);
SetPos(0,0);
}
//This section of code works, I used it check ADC function
/*ConvertADC();
while(BusyADC());
i = ReadADC();
if(i<125)PORTC = 0b00000001;
else if(i>126 && i<250)PORTC = 0b00000011;
else if(i>251 && i<375)PORTC = 0b00000011;
else if(i>376 && i<400)PORTC = 0b00000111;
else if(i>401 && i<525)PORTC = 0b00001111;
else if(i>526 && i<650)PORTC = 0b00011111;
else if(i>651 && i<750)PORTC = 0b00111111;
else if(i>751 && i<875)PORTC = 0b01111111;
else if(i>876 && i<1023)PORTC = 0b11111111;
*/
}
Stepping through using MPLAB simulator, it seems to get hung up at the itoa function. Thanks