This is my code, does this make any sense to u all? Sorry if it does not cuz I'm really a newbie with adc and serial transmission.
#include <p18f4553.h>
#include <delays.h>
#include <adc.h>
#include <stdlib.h>
int result1, result2;
int convertpin1(void);
int convertpin2(void);
void main()
{
ADCON1=0x0D; //RA0 and RA1 is configured as analog input
ADCON2=0x84; //Right justification and manual acquisition
TRISA=0xFF; //RA0 is configured as input, the rest of the pins are unused
TRISB=0xFF; //Port B all unused
TRISC=0b10111111; //RC6 is an output (Tx)
TRISD=0xFF; //Port D all unused
TRISE=0xFF; //Port E all unused
TXSTA=0b10111110;
while(1)
{
result1 = convertpin1();
result2 = convertpin2();
TXREG = result1 + result2;
}
} //end of main
int convertpin1()
{
ADCON0=0x00; //select channel AN0
Delay10TCYx(3); // Wait for required acquisition time (6us)
ConvertADC(); //start A/D conversion
while(BusyADC()); //wait for completion
result1 = ReadADC(); //read result
CloseADC();
return(result1);
}
int convertpin2()
{
ADCON0=0x01; //select channel AN1
Delay10TCYx(3); // Wait for required acquisition time (6us)
ConvertADC(); //start A/D conversion
while(BusyADC()); //wait for completion
result2 = ReadADC(); //read result
CloseADC();
return(result2);
}
---------- Post added at 14:49 ---------- Previous post was at 14:47 ----------
For example:
3.34v converted to the character string "3.34" or {'3','.','3','4'}, you then send each character of the string to the MCP2200 from the PIC18F via the serial connection. The C18 has libraries to control and utilize the USART, review the C18 documentation concerning these library functions. The MCP2200 also supports a VCP (virtual communications port) mode. Therefore with the correct driver load on your PC, the USB connection will be seen as a serial port which you could communicate with via a terminal program or program of your own using standard serial port methods.
There are other USB modes supported by the MCP2200, however they require considerably more coding and knowledge of USB to implement.
Review the documentation of the MCP2200:
MCP2200 Product Page with Documentation and Drivers
MCP2200 USB to RS-232 Demo Board User's Guide
The User Guide above should give you an example of a similar implementation, however you will not need the MAX3232 transceiver, just connect the PIC directly to the MCP2200's appropriate pins.
Does the info help answer your questions?
BigDog
Thanks for the info, I will look up for more info on the compiler with regards to UART. I
ll update my status here as my project progresses.