Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use the Tx and Rx pins on PIC18F4553

Status
Not open for further replies.

polarsnake

Newbie level 4
Joined
Jun 26, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
I have already done an analog to digital conversion on my PIC18f4553, and now I will have to transmit the digital signals over to MCP2200. Does anybody have any idea how do I write the coding for transmitting signals out through the Tx pin?
 

You'll need to covert each digit of the numerical values into ASCII (text) and then transmit them via serial connection to the MCP2200. Most C compilers for the PIC 18F have library functions for serial communications.

What C Compiler are you using?
 

You'll need to covert each digit of the numerical values into ASCII (text) and then transmit them via serial connection to the MCP2200. Most C compilers for the PIC 18F have library functions for serial communications.

What C Compiler are you using?

Erm.. didnt quite understand that. I'm using C18 compiler.
 

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
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Hi, download the datasheet of the MCP2200. And connect the controller to the TX and RX pins. The data that you would like to send depends on the application. if it is a universal usb to serial converter for embedded applications, I would recommend just sending normal Hex data.

MN
 

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.
 

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.

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.

It looks like you've got a fairly good start. Does your program compile and run as expected?

Why do you want to incorporate a MCP2200 into your design? The PIC18F4553 already has an USB interface available as one of its peripherals?

An educational experience?

Anyway, you may want to write a simply program which transmits a text message and the your voltage values via a RS-232 serial connection to a PC running a terminal emulation program, before attempting to utilize the MCP2200 in your design.

Doing so would give you valuable experience communicating numerical values and text under a simplified scenario and would easy the task of incorporating the MCP2200 at a later date.

BigDog
 
It looks like you've got a fairly good start. Does your program compile and run as expected?

Why do you want to incorporate a MCP2200 into your design? The PIC18F4553 already has an USB interface available as one of its peripherals?

An educational experience?

Anyway, you may want to write a simply program which transmits a text message and the your voltage values via a RS-232 serial connection to a PC running a terminal emulation program, before attempting to utilize the MCP2200 in your design.

Doing so would give you valuable experience communicating numerical values and text under a simplified scenario and would easy the task of incorporating the MCP2200 at a later date.

BigDog

I've tried compiling it and the build has succeeded but when I tried to read the values through a hyperterminal, I am not able to get the results (It does not even run). And the use of an MCP2200 is to make USB interfacing less of a hassle for me.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top