FT232R RS232 to USB Converter

Finally decided to make a PCB for this. I had the IC since last year heh… Installs fine an i see the LED light up on Sending data from PC to it… not tested yet. Once tested ill post schematic and code used to test it…

Here is some code that seems to be working so far….

/* *****************************************************************************
;                                                                             *
;    Filename:                                                                   *
;    Date:                                                                       *
;    File Version: 001                                                        *
;                                                                             *
;    Author:   Jason Lopez                                                    *
;    Company:  AtomSoft                                                       *
;                                                                             *
;***************************************************************************** */

#include <p18f2525.h>
#include <delays.h>
#include <string.h>

#pragma config OSC = INTIO67,PWRT = OFF,BOREN = OFF,WDT = OFF,PBADEN = OFF

/************************************
Prototypes
*************************************/
void main(void);
void USART_Init(void);
void USART_vSendByte( unsigned char u8Data);
unsigned char USART_vReceiveByte(void);
void delayms( unsigned char t);

/************************************
Definitions and Variables
*************************************/
#define LEDON 0x11//switch led on command
#define LEDOFF 0x22//switch led off command

/************************************
Main
*************************************/
void main(void){
unsigned char x;
OSCCON = 0x72;                  //8MHz clock
while(!OSCCONbits.IOFS);        //wait for osc stable

USART_Init();

while(1){
for(x=0;x<10;x++){
USART_vSendByte(0x30+x);
delayms(100);
}
x = USART_vReceiveByte();
USART_vSendByte(x);
}
}

void USART_Init(void)
{
TRISCbits.TRISC7 = 1;    //SETUP UART
TXSTA = 0;
SPBRG = 103;     //1200bps

RCONbits.IPEN = 1;
IPR1bits.RCIP = 1; //PRIORITY

TXSTAbits.TXEN = 1;  //ENABLE TX
RCSTAbits.CREN = 1;  //ENABLE RX
RCSTAbits.SPEN = 1;  //ENABLE SERIAL PORT and PIN Config

PIR1   = 0b00000000;
PIE1   = 0b00101000;
IPR1   = 0b00101000;
}

void USART_vSendByte( unsigned char u8Data)
{
// Wait if a byte is being transmitted
while(!TXSTAbits.TRMT);
// Transmit data
TXREG = u8Data;
}
unsigned char USART_vReceiveByte(void)
{
// Wait until a byte has been received
while(!PIR1bits.RCIF);
// Return received data
return RCREG;
}
void delayms( unsigned char t)
{
unsigned char i;
for(i=0;i<t;i++)
Delay1KTCYx(2);
}

Advertisements

About atomsoft

Starting a small company. Trying to build it from ground up. Only 2 employees so far. Nothing serious yet but soon!

2 responses to “FT232R RS232 to USB Converter”

  1. pasanlaksiri says :

    Wow thats a lovely and very very useful experiment.

  2. atomsoft says :

    Yeah i plan to use it on a SD project i will be working on.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: