|
|
View previous topic :: View next topic |
Author |
Message |
hhuurrkkaann
Joined: 08 Jan 2013 Posts: 14
|
|
Posted: Fri Apr 29, 2016 11:46 am |
|
|
@temtronic
was right, after adding "errors" to rs232 options I received all datas although to 9600 bps,,,
it seems that problem solved now,
I am sharing the code for other friends, maybe someone could need it...
And again, I am grateful for your help...thanks.
Code: |
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4000000) // Gecikme fonksiyonu için kullanılacak osilatör frekansı belirtiliyor.
#define use_portb_lcd TRUE // LCD B portuna bağlı
#include <lcd.c> // lcd.c dosyası tanıtılıyor
#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1,errors)
#include <ctype.h>
char result[20];
int i;
#int_rda
void goster()
{
if (kbhit())
result[0]=getc();
if(result[0]=='H') // the data that pic receives starts with "H" letter //and do not contain any H letter more. As an example : //H32YTRG6DVECDDE, because of this I searched for H with result[0]=='H'
for(i=1;i<12;i++)
{
result[i]=getc();
printf(lcd_putc" %c ",result[9]); // you will get 9.th char, if you //make it"result[8] you will get 8.th char... it'is up to you...
}
}
void main ()
{
enable_interrupts(GLOBAL);
lcd_init();
while (1)
{
enable_interrupts(int_rda);
}
} |
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Apr 29, 2016 12:25 pm |
|
|
Hi,
Your problem may appear to be 'solved', but that is very flawed code, and you and anyone that comes later should know that!
Here are the problems that need fixing:
1. Inside your int_rda interrupt handler you have a 'kbhit()' statement. This is completely unnecessary, as the very fact that the interrupt is being serviced means that a character is waiting in the UART Rx buffer.
2. Your int_rda interrupt handler is reading multiple characters. This is completely contrary to how a serial interrupt handler is intended to work. You should look for the 'H' character (if that is how you want to define the 'start' of a string), reset your buffer index, and then start buffering characters until you receive a carriage return <CR>, 9 characters, or whatever you'd like to define as the 'end of string'.....
3. You have a 'printf' inside your interrupt handler...... This is deadly, and should be avoided at all costs! Instead of this, the 'correct' way to do it is to create a 'flag', a variable that says 'the full string has been received'. This flag is set in the serial interrupt handler, and is reset in Main() after you print the entire contents of the buffer. This process will repeat over and over....
4. You should enable the int_rda interrupt before you enable GLOBAL interrupts, and you should also do it only once. Having this int_rda enable inside your 'While()' loop is pointless!
5. You should insert a small delay after you execute 'init_lcd()' to give the LCD module the time to actually initialize.....
Other than that, your program looks fine _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
hhuurrkkaann
Joined: 08 Jan 2013 Posts: 14
|
|
Posted: Fri Apr 29, 2016 12:38 pm |
|
|
ezflyr wrote: | Hi,
Your problem may appear to be 'solved', but that is very flawed code, and you and anyone that comes later should know that!
Here are the problems that need fixing:
1. Inside your int_rda interrupt handler you have a 'kbhit()' statement. This is completely unnecessary, as the very fact that the interrupt is being serviced means that a character is waiting in the UART Rx buffer.
2. Your int_rda interrupt handler is reading multiple characters. This is completely contrary to how a serial interrupt handler is intended to work. You should look for the 'H' character (if that is how you want to define the 'start' of a string), reset your buffer index, and then start buffering characters until you receive a carriage return <CR>, 9 characters, or whatever you'd like to define as the 'end of string'.....
3. You have a 'printf' inside your interrupt handler...... This is deadly, and should be avoided at all costs! Instead of this, the 'correct' way to do it is to create a 'flag', a variable that says 'the full string has been received'. This flag is set in the serial interrupt handler, and is reset in Main() after you print the entire contents of the buffer. This process will repeat over and over....
4. You should enable the int_rda interrupt before you enable GLOBAL interrupts, and you should also do it only once. Having this int_rda enable inside your 'While()' loop is pointless!
5. You should insert a small delay after you execute 'init_lcd()' to give the LCD module the time to actually initialize.....
Other than that, your program looks fine |
You are right about my mistakes
I will do what you said,
Really Thanks for help... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Fri Apr 29, 2016 12:42 pm |
|
|
ezflyr wrote: | Ttelmah wrote: | a couple more characters have already arrived, and hung the UART!.... |
Hmmm, is it actually possible to hang a Proteus (virtual) UART??? |
Yes. It is one of the things it does get 'nearly right'. It does it at the wrong time, but will hang. |
|
|
|
|
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
|