Serial Communication

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Amir Khan
Posts: 2
Joined: 08 Jun 2010 05:42

Serial Communication

#1 Post by Amir Khan » 08 Jun 2010 06:02

Can any 1 help me ????

i have to send some text from computer to 16F628A PIC and then transmit that text to 18F452 PIC.

i am new so plz help me.

im trying this code.

char *text ;
char *rec;
int i=0;
void Usart_Write_Text(char*);




void main(void)
{
Soft_Uart_Init(PORTB, 1, 2, 1200, 0);

Usart_Init(1200);
TRISB.F2 = 0;
TRISB.F1 = 1;
TRISB.f4=0;
SW1=0;
SW0=1;
SW2=0;
delay_ms(1000);


while(1)
{
do
text = Soft_Uart_Read(rec);
while (!*rec);
if (data==1)

Usart_Write(text);
//i++;



Soft_Uart_Write("");

}

}

piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

Re: Serial Communication

#2 Post by piort » 08 Jun 2010 12:18

hi Amir,
try MikroC for Pic forum.... You have more chance to have help and answer there...
here is the Pascal for 8051 core mcu forum ...

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: Serial Communication

#3 Post by drdoug » 09 Jun 2010 18:46

piort wrote:hi Amir,
try MikroC for Pic forum.... You have more chance to have help and answer there...
here is the Pascal for 8051 core mcu forum ...
This is the forum for MicroC Pro so I am not sure what piort is saying. However. this is the the place where you should be able to find some help. I gather you want to use soft uart to receive from the pc and the uart module to transmit to the other pic.

I see a few problems(optimization opportunities) with your code but I would recommend a couple changes if interested.
Option 1. Change the pic so it receives on the uart module . It has a built in buffer (only 1 byte deep) that start receiving while you are doing other things in your program. With the soft-uart, you have to constantly monitor that pin for signals. Also, with the uart module, you
can can generate an interrupt to know when to service the uart.
Option 2. You may consider using an rs485 setup where one of the units is a master (maybe the middle pic).

Other things to consider:
increase the baud rate (9600 or greater). This will free up some processor overhead (waiting for bytes to be sent and received);
consider using flow control;

Upon closer look at your code, it appears to be a bit of a mess.
Where did you define "data"? Does it get a value?
I would recommend breaking this project into components. First, get the pc to pic connection working (maybe start with the mE example) to make sure you have you have all your hardware worked out. Be sure to use a 232 level converter. Once the mE example is working, start to modify that code to do what you want.

piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

Re: Serial Communication

#4 Post by piort » 09 Jun 2010 19:14

oups :oops:
my mistake...was reading the pascal 8051 just before :oops:

Amir Khan
Posts: 2
Joined: 08 Jun 2010 05:42

Re: Serial Communication

#5 Post by Amir Khan » 14 Jun 2010 18:10

drdoug Sir i cannot change PIC an Baudrate.

if i take baud rate 9600 then it send some gaurbag value on my Hardware.

and data==1 means text==1

Post Reply

Return to “mikroC PRO for PIC General”