![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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) 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;
*/
} | |
| |
| | (permalink) |
| Your problem is due to pointer differences. PutMessage expects a pointer to a rom string and you are passing it a ram variable. You can get it working by doing, Code: while (1){
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
read = 523;ReadADC();
itoa(read,adc_ret);
pos=0;
while(adc_ret[pos])
PutChar(adc_ret[pos++]);
Delay10KTCYx(250);
SetPos(0,0);
} Mike. Last edited by Pommie; 28th March 2008 at 12:59 AM. | |
| |
| | (permalink) |
| It works! Thanks again. Now I just have to figure out how to get the numbers on the display to be right justified. | |
| |
| | (permalink) |
| How about, Code: while (1){
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
read = 523;ReadADC();
itoa(read,adc_ret);
SetPos(0,16-strlen(adc_ret));
pos=0;
while(adc_ret[pos])
PutChar(adc_ret[pos++]);
Delay10KTCYx(250);
SetPos(0,0);
} Edit, forgot this was for a GLCD. The above is for a 16 character LCD. The principle is the same but it will be 128-strlen(adc_ret)*charwidth. Last edited by Pommie; 28th March 2008 at 04:15 AM. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| MPLABs C18 Compile Error | yngndrw | Micro Controllers | 7 | 18th March 2008 12:44 PM |
| ADC troubles | andy257 | General Electronics Chat | 4 | 2nd December 2007 06:49 PM |
| Help! Adc On A Pic12f675 | UrabnBadger | Micro Controllers | 13 | 25th November 2007 09:36 PM |
| Please help!! program not working | vinke | Micro Controllers | 3 | 5th October 2007 05:59 AM |
| 16F877 Timer0 Interrupt Affecting ADC | sebana | Micro Controllers | 13 | 12th September 2007 10:43 AM |