|
|
View previous topic :: View next topic |
Author |
Message |
HU Guest
|
communication between 16F877 and 16F84 |
Posted: Tue Apr 06, 2004 5:41 am |
|
|
Hiii... everybody
I am in trouble...
PLS HELP ME...
I am about to get crazy !
I have two PICs. One is PIC16F877. The other one is PIC16F84.
I am trying to use RS232 communication between to PICs.
16F84 is driving a LCD module thru PortB of 16F84
Both 16F877 and 16F84 are powered from the same power supply.
A 30K resistor is connected to the transmitting bus line as pull-up resistor.
Usually, They are communicating without any problem.
But for some startup times, (by applying the power supply) , Nothing can be seen on LCD (except some untidy lines) And LCD stays like that.
For trouble shooting, I connected the transmitter (16F877) to PC ( using hyper terminal), there was no problem. What was sent could be printed on screen.
When I connect PC to my receiver PIC (16F84) , I rarely meet a problem.
If circuits start correctly, No problems and they are working fine. After that, Whenever anyone (or both) of PICs are reset, There is no trouble as well.
Reset order of PICs does not change any thing. Communication is going on perfectly.
Why is the communication becoming bad for some startups?
What should I do?
Unfortunately, It is urgent...
Best wishes
Here is my code for 16F877:
#include <16F877.h>
#device *=16 ADC=10
#fuses XT, NOWDT, NOPROTECT, NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
void main() {
unsigned int i=0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
while(1){
delay_ms(500);
printf("%d", ++i);
putchar(13);
putchar(10);
}
}
The following is code for 16F84 :
#include<16c84.h>
#include<stdio.h>
#fuses XT,NOPROTECT,NOWDT
#use delay(clock=4000000)
#use rs232(baud=9600, rcv=PIN_A1,xmit=PIN_A0,parity=n,bits=8,invert)
//
// the following file is included with the examples that come
// with CCS. You should modify it for your type of LCD before you
// use it!
#include"lcd.c"
//
// declare the rs232 parameters. Leave off the INVERT if you are feeding
// this from a PC through a MAX232 or similar
//
main() {
//
// If you feed the buffer with more than 16 characters, it will crash
// So you might want to bullet proof this a whole lot more. I didn't
// and my prototypes work fine - because I don't send it more than
// 16 characters (grin). PS: the extra characters in the array are for
// the carriage return/null on the end of the string.
//
// The array initialization is not needed, but shown as a reminder of
// the space being used.
//
char buf[18]={32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32};
unsigned xc=0;
lcd_init();
lcd_putc("\fReady . . .\n");
delay_ms(2000);
lcd_putc("\f");
while(1)
{
gets(buf); // puts data into buf[] until it reaches a char 13 (cr)
lcd_putc("\f"); // clears screen before printing buffer - remove if more
// than one line LCD. Clear it with your input code instead.
for(xc=0;xc<16;xc++)
{
if(buf[xc]==0) buf[xc]=32; // eliminate the null character
if(buf[xc]==13) buf[xc]=32; // not needed if using gets to get string
if(buf[xc]==10) buf[xc]=32; // not needed if using more than 1X16
lcd_putc(buf[xc]); //
buf[xc]=32; // resets buffer contents to spaces
}
}
} |
|
|
djpark
Joined: 02 Mar 2004 Posts: 49
|
Re: communication between 16F877 and 16F84 |
Posted: Tue Apr 06, 2004 6:24 am |
|
|
HU wrote: | ...
But for some startup times, (by applying the power supply) , Nothing can be seen on LCD (except some untidy lines) And LCD stays like that.
...
If circuits start correctly, No problems and they are working fine. After that, Whenever anyone (or both) of PICs are reset, There is no trouble as well.
Reset order of PICs does not change any thing. Communication is going on perfectly.
Why is the communication becoming bad for some startups?
... |
I've used quite a few commercial serial driver for LCD using 16F84 having the same problem. There are few problems which may or may not contribute to your problem, but they are problems.
1) Due to lack of hardware UART receive, it has to poll the receive line and it is time critical. The highest baud rate it "may" handle is 9600.
2) LCD takes a (relatively) long time to initialize (4ms min) and write characters (160us min) compared to the speed of incoming characters. My experience shows a lot longer time is needed than the spec. Especially any characters coming in during LCD init will be lost.
3) If by any chance if the character sync is broken, it has problem of recovering (unless the software emulation is inteligent).
My suggestion:
USE 16F628A or 16F648A instead of 16F84.
They are pin compatible and also has a lot of enhancement including hardware UART.
I am using 16F628A to make serial LCD driver with serial-receive interrupt to pump received characters to 64 bytes buffer and it can handle 115200 baud quite well with 18.432MHz crystal with a simple but clever emulation. It took 99% of 2K flash.
-- dj |
|
|
|
|
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
|