View previous topic :: View next topic |
Author |
Message |
aruna1
Joined: 14 Oct 2008 Posts: 103
|
RS232 between 16F877A and 16F628A |
Posted: Thu Nov 25, 2010 8:17 pm |
|
|
Hi
I'm trying to send a string from 16F877A and capture it using a 16F628A and display it on an LCD via RS232. My problem is its not working. However I can communicate with PC using both PICs. Following are my codes. What I do is:
- Press button on 16F877A to generate string
- Send it via rs232
- Capture it with 16F628A
- Print it on lcd using 16F628A
For 16F877A
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_D6,rcv=PIN_D7,bits=8)
char string[30];
void main()
{
setup_adc_ports (NO_ANALOGS) ;
setup_adc (ADC_OFF) ;
setup_psp (PSP_DISABLED) ;
setup_spi (SPI_SS_DISABLED) ;
setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_1) ;
setup_timer_1 (T1_DISABLED) ;
setup_timer_2 (T2_DISABLED, 0, 1) ;
setup_comparator (NC_NC_NC_NC) ;
setup_vref (FALSE) ;
//lcd_init () ;
WHILE (1)
{
IF (!input (PIN_D1) )
{
printf ("test\n") ;
delay_ms (500) ;
}
}
//TODO: USER CODE!!
}
|
For 16F628A
Code: |
#include <16F628A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B1,rcv=PIN_B2,bits=8)
#include <flex_lcd_628A.C>
char string[50];
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
//printf(lcd_putc,"aruna");
while(1)
{
gets(string);
printf(lcd_putc,string);
}
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
}
|
Can someone help me with this please? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Nov 25, 2010 9:10 pm |
|
|
You say it doesn't work. Exactly what does it do? Does the receiver print ANYTHING to the LCD? Does it print the WRONG thing?
I would replace gets(string) with getc(string) and see it the first character gets through OK, or if it is inverted or bit shifted. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
REE |
Posted: Thu Nov 25, 2010 11:11 pm |
|
|
are the both the PICs able to send and receive data independently with the PC ??
You need to first determine if the transmit and receive functions are working in each of the PICs.
thanks
a |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
|
Posted: Thu Nov 25, 2010 11:33 pm |
|
|
SherpaDoug wrote: | You say it doesn't work. Exactly what does it do? Does the receiver print ANYTHING to the LCD? Does it print the WRONG thing?
I would replace gets(string) with getc(string) and see it the first character gets through OK, or if it is inverted or bit shifted. |
it doesnt print anything on lcd-with gets function
it prints lot of garbage with getc function |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
Re: REE |
Posted: Thu Nov 25, 2010 11:34 pm |
|
|
arunb wrote: | are the both the PICs able to send and receive data independently with the PC ??
You need to first determine if the transmit and receive functions are working in each of the PICs.
thanks
a |
both PICs can communicate with PC without any trouble |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
|
Posted: Thu Nov 25, 2010 11:35 pm |
|
|
By the way,
16F628A works with 4MHz internal oscillator and 16F877A works with 20MHz crystal oscillator.
And do I need max232 to connect 2 pics? I simply connected rx-tx pins oe each other:
PIC 1 RX- PIC2 TX
PIC 1 TX- PIC2 RX |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Nov 26, 2010 4:02 am |
|
|
One very obvious error with the code.
What character does 'gets' look for as the end of line?.
Hint it is _not_ '\n'......
Best Wishes |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
|
Posted: Fri Nov 26, 2010 4:14 am |
|
|
Ttelmah wrote: | One very obvious error with the code.
What character does 'gets' look for as the end of line?.
Hint it is _not_ '\n'......
Best Wishes |
oh i get it its \r
it seems working now
I will play more and let you know
thanks |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
solved |
Posted: Fri Nov 26, 2010 5:31 am |
|
|
Finally got it working.
Thank you all for your help and time.
|
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
new problem |
Posted: Fri Nov 26, 2010 9:52 am |
|
|
Well I found that it takes too long to process printf command.
I tried to measure the time for printf and found its 4258uS.
Any idea why?
Here is my new code:
Code: |
#include <16F628A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B1,rcv=PIN_B2,bits=8)
#include <flex_lcd_628A.C>
char string[50];
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1((T1_INTERNAL|T1_DIV_BY_1));
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
//printf(lcd_putc,"aruna");
while(1)
{
gets(string);
set_timer1(0);
printf(lcd_putc,string);
printf(lcd_putc,"\n%Ld",get_timer1());
}
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Nov 26, 2010 10:07 am |
|
|
Time for printf, depends on what is being printed, and to what.
Start with 'what is being printed'. Every digit, involves a /10. Table in the 'help', giving 'how much time do maths operations take'. Then the 'to what'. If you send characters over serial at 9600bps, basically 1mSec/character. To the LCD, will depend on your hardware. If you have the code setup to not use 'busy', then the code delays for the 'worst case' character time for each character. If you are using the 'busy', then depends on your display. Typically about 50uSec/byte for one character of basic text, up to 1.7mSec, for a form feed.
Best Wishes |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
|
Posted: Fri Nov 26, 2010 7:51 pm |
|
|
Ttelmah wrote: | Time for printf, depends on what is being printed, and to what.
Start with 'what is being printed'. Every digit, involves a /10. Table in the 'help', giving 'how much time do maths operations take'. Then the 'to what'. If you send characters over serial at 9600bps, basically 1mSec/character. To the LCD, will depend on your hardware. If you have the code setup to not use 'busy', then the code delays for the 'worst case' character time for each character. If you are using the 'busy', then depends on your display. Typically about 50uSec/byte for one character of basic text, up to 1.7mSec, for a form feed.
Best Wishes |
I didnt understand what you said.can you please explain little clear?
thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Nov 26, 2010 8:08 pm |
|
|
In simpler terms...
printf(...) is a HUGE function that take a LOT of time to send your data to where to want it to go. It has to be able to accept data of different types, figure out where to send them AND reformat that data into a type that you specify.
Just think of the time you'ld spend if you had to listen to several foreign words..look them up a translation book,translate them into your language,then write them down on a special piece of paper, in a specific sequence !
Now, make the task MORE generic, ie: ANY incoming language...to ANY piece of paper..in ANY language....
it takes TIME!
AND...
when you write out those words you use old style quill and ink..a very slow process, which takes even more time.....
printf(...) is a generic task built to be 'all purpose' , it is NOT designed for SPEED. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 26, 2010 9:04 pm |
|
|
Quote: |
printf(...) is a HUGE function that take a LOT of time to send your data to
where to want it to go. It has to be able to accept data of different types,
figure out where to send them AND reformat that data into a type that
you specify.
|
CCS is different. See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=34513&start=9 |
|
|
aruna1
Joined: 14 Oct 2008 Posts: 103
|
|
Posted: Sun Nov 28, 2010 5:22 am |
|
|
thanks guys |
|
|
|