CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to convert rs232 to usb

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

how to convert rs232 to usb
PostPosted: Wed Jul 01, 2009 10:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 01, 2009 12:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 2:19 am     Reply with quote

You could always add an FTDI chip to that board, something like the FT232R would be perfect for you.

Serial to USB:
http://www.ftdichip.com/Products/FT232R.htm
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

CP2102
PostPosted: Sun Jul 05, 2009 11:30 pm     Reply with quote

using this CP2102 IC to convert RS232 to usb and usb to rs232
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group