View previous topic :: View next topic |
Author |
Message |
NAVID
Joined: 14 Jun 2017 Posts: 28
|
help |
Posted: Mon Aug 28, 2017 10:03 am |
|
|
hi every one
I want to send characters to pic 16f877a by hc-05 and i do this correctly. Then i want to when pic receive "^" show characters but it does not work.
I don't know why but i hope somebody can help me. This is my program:
Code: |
#include <main.h>
#include "lcd_flex.c"
#include <string.h>
int1 b=0,step=0;
int8 rec,a[11];
char c[1]='^';
//char d[1];
#INT_TBE
void TBE_isr(void)
{
}
#INT_RDA
void RDA_isr(void)
{
for(rec=0;rec<10;rec++){
a[rec]=getc();
if(strcmp(c,a[rec])==1){
step=1;} }
step=1;
}
void main()
{
// enable_interrupts(INT_TBE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init();
while(TRUE)
{
if(b==0){
lcd_gotoxy(1,1);
lcd_putc("hi lets start");
delay_ms(1000);
lcd_clear();
b=1;}
if(step==1){
lcd_clear();
lcd_gotoxy(1,1);
printf(lcd_putc,"%s ",a);
step=0; }
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Aug 28, 2017 10:13 am |
|
|
this line...
Quote: |
if(strcmp(c,a[rec])==1){
| says IF the a[rec] value is equal to the value of variable c, then do something.
However you've got an ARRAY called C, not a simple variable called C.
It should work though, as
Quote: |
if(strcmp(c(0),a[rec])==1){ |
providing the FIRST array location is C(0) and not c(1).
Really the 'test variable' ("^") should be just a character variable perhaps named caret.
There are other problems in your code.
For one, do not use the xmt ISR, not really needed.
The receive ISR only fires on ONE incoming character.
I suggest you look at the CCS supplied example program call ex_sisr.c in the 'examples' folder for how to receive a 'string' of characters.
Jay |
|
|
NAVID
Joined: 14 Jun 2017 Posts: 28
|
|
Posted: Mon Aug 28, 2017 11:18 am |
|
|
Thank you, I will go to look at the example and come back to ask some questions later ((: |
|
|
NAVID
Joined: 14 Jun 2017 Posts: 28
|
|
Posted: Tue Aug 29, 2017 11:14 am |
|
|
temtronic wrote: |
There are other problems in your code.
For one, do not use the xmt ISR, not really needed.
|
hi again
what is the xmt ISR ?? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Aug 29, 2017 2:15 pm |
|
|
this ....
Quote: |
#INT_TBE
void TBE_isr(void)
{
} |
...is the xmt ISR ( transmit ISR )
It's only 5 lines of code, not being used in your program so just delete it.
Jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Aug 31, 2017 1:29 pm |
|
|
Hi,
It hasn't been mentioned yet, but your Rx interrupt (#INT_RDA) construct is totally wrong. The serial interrupt fires for each character that is received, so you should read one - and only one - character inside the ISR. Put these characters inside an array, and process the array in Main() once the entire transmission is received. Don't read multiple characters inside the ISR! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
NAVID
Joined: 14 Jun 2017 Posts: 28
|
|
Posted: Sat Sep 02, 2017 11:19 pm |
|
|
ezflyr wrote: | Hi,
It hasn't been mentioned yet, but your Rx interrupt (#INT_RDA) construct is totally wrong. The serial interrupt fires for each character that is received, so you should read one - and only one - character inside the ISR. Put these characters inside an array, and process the array in Main() once the entire transmission is received. Don't read multiple characters inside the ISR! |
Hi, thanks.
So what i must going to do??
Can you write for me an example?? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Sep 03, 2017 1:19 am |
|
|
ex_sisr.c, shows how a serial receive routine should be done.
There have also been lots of examples here. |
|
|
|