Page 1 of 1

Serial Communication

Posted: 08 Jun 2010 06:02
by Amir Khan
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("");

}

}

Re: Serial Communication

Posted: 08 Jun 2010 12:18
by piort
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 ...

Re: Serial Communication

Posted: 09 Jun 2010 18:46
by drdoug
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.

Re: Serial Communication

Posted: 09 Jun 2010 19:14
by piort
oups :oops:
my mistake...was reading the pascal 8051 just before :oops:

Re: Serial Communication

Posted: 14 Jun 2010 18:10
by Amir Khan
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