View previous topic :: View next topic |
Author |
Message |
bharatwalia
Joined: 04 May 2009 Posts: 35 Location: India
|
how to convert rs232 to usb |
Posted: Wed Jul 01, 2009 10:55 am |
|
|
Hi, I wrote the following voltmeter program to measure the input voltage on AN0 pin of "pic18f2550" using "max232" between (0 to 5V) and display onto rs232 channel.
Can anybody tell me how to convert this program to USB. I want to write a application in VC.net or any other platform and integrate this program to it so that I can connect my program to PC via "USB"
Code: |
//This program is designed to measure input voltage on AN0 pin between 0 to 5V and
//display it on rs232 channel on PC.
//input voltage "PIN-2" on MCU (0 to 5V)
//Transmit "PIN-17" on MCU
//Use of MAX232 for rs232 channel
//Input pin on max232 from MCU "PIN-10"
//Output pin from max232 to PC "PIN-7"
#include <18f2550.h>
#device adc=10
#USE DELAY( CLOCK=4000000 ) /* Using a 4 Mhz clock */
#use RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
#FUSES XT,NOWDT,NOPROTECT,NOPUT
/* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */
unsigned int16 adc_value;
unsigned int32 volts;
void live()//flashes led with a delay of 200 ms on pin 7 or port B
{
output_toggle(PIN_B7);
delay_ms(200);
}
void get_voltage() //This function reads the voltage present at AN0,calculates it and stores it into volts
{
adc_value=read_adc();
volts=(unsigned int32)adc_value*5000;
volts=volts/1024;
}
void to_rs232( ) {
printf("Measured Voltage = %LumV\n\r",volts); //Transmits the voltage to rs232 terminal.
}
void main()
{
setup_adc_ports(ALL_ANALOG);//setting ADC for analog inputs.
setup_adc(ADC_CLOCK_DIV_32);//setting the A/D clock
set_adc_channel(0);//ANO channel of adc
delay_ms(10);
while(1)
{
live();
get_voltage();
delay_ms(1000);
to_rs232();
delay_ms(1000);
}
} |
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 01, 2009 12:20 pm |
|
|
Look in the CCS example directory on your hard drive.
That's where you will find USB examples:
Quote: | c:\program files\picc\examples\ex_usb_serial.c
c:\program files\picc\examples\ex_usb_serial2.c |
|
|
|
dprocter
Joined: 01 Jul 2009 Posts: 5
|
|
|
karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
CP2102 |
Posted: Sun Jul 05, 2009 11:30 pm |
|
|
using this CP2102 IC to convert RS232 to usb and usb to rs232 |
|
|
|