CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Help with serial interupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
isaac aiyanyo
Guest







Help with serial interupt
PostPosted: Fri Dec 06, 2002 11:05 am     Reply with quote

Hello pic_stars
i need some of your expert advice on theis problem.
i am new to pic c but i am determine to learn.
i am trying to display the characters that are received during
interupt but i can't seem to using a serial lcd connected to RA0
and running at 9600 baud.
when i run the program i and type in says
1111111111111111 , i get the correct characters displayed on hyperterminal
Buffered data =>1111111111111111 but on the lcd its is displayed as
1 1 1 1 on the top line and 1 1 1 1 on the bottom line
i want to be able to display the characters on the lcd
please could you guys help and tell me were i am going wrong.
the program is below
Thanks in advance
Isaac

#if defined(__PCM__)
#include <16F876.H>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
void lcdout() ;

#byte port_a=5
#byte port_b=6
#byte port_c=7


#define BUFFER_SIZE 16
byte buffer[BUFFER_SIZE];
byte next_in = 0;
byte next_out = 0;


#int_rda
void serial_isr()
{

int t;
output_low(PIN_C4);
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) \% BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}

#define bkbhit (next_in!=next_out)

byte bgetc()
{
byte c;

while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) \% BUFFER_SIZE;
return(c);
}



main()
{
int i;
enable_interrupts(global);
enable_interrupts(int_rda);

printf("\r\n\Running...\r\n");

// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay

do
{
output_high(PIN_C4);
delay_ms(10000);
printf("\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
printf("\r\n");
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)

//putc( bgetc() );

for (i=0;i<16;i++)
{

printf( " \%c\r\n ",buffer[i]);

}
}
while (TRUE);

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 9835
R.J.Hamlett
Guest







Re: Help with serial interupt
PostPosted: Fri Dec 06, 2002 11:38 am     Reply with quote

:=Hello pic_stars
:= i need some of your expert advice on theis problem.
:= i am new to pic c but i am determine to learn.
:= i am trying to display the characters that are received during
:= interupt but i can't seem to using a serial lcd connected to RA0
:= and running at 9600 baud.
:= when i run the program i and type in says
:= 1111111111111111 , i get the correct characters displayed on hyperterminal
:= Buffered data =>1111111111111111 but on the lcd its is displayed as
:= 1 1 1 1 on the top line and 1 1 1 1 on the bottom line
:= i want to be able to display the characters on the lcd
:= please could you guys help and tell me were i am going wrong.
:= the program is below
:=Thanks in advance
:=Isaac
:=
:=#if defined(__PCM__)
:=#include <16F876.H>
:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=void lcdout() ;
:=
:=#byte port_a=5
:=#byte port_b=6
:=#byte port_c=7
:=
:=
:=#define BUFFER_SIZE 16
:=byte buffer[BUFFER_SIZE];
:=byte next_in = 0;
:=byte next_out = 0;
:=
:=
:=#int_rda
:=void serial_isr()
:={
:=
:= int t;
:= output_low(PIN_C4);
:= buffer[next_in]=getc();
:= t=next_in;
:= next_in=(next_in+1) \% BUFFER_SIZE;
:= if(next_in==next_out)
:= next_in=t; // Buffer full !!
:=}
:=
:=#define bkbhit (next_in!=next_out)
:=
:=byte bgetc()
:={
:= byte c;
:=
:= while(!bkbhit) ;
:= c=buffer[next_out];
:= next_out=(next_out+1) \% BUFFER_SIZE;
:= return(c);
:=}
:=
:=
:=
:=main()
:={
:= int i;
:= enable_interrupts(global);
:= enable_interrupts(int_rda);
:=
:= printf("\r\n\Running...\r\n");
:=
:= // The program will delay for 10 seconds and then display
:= // any data that came in during the 10 second delay
:=
:= do
:= {
:= output_high(PIN_C4);
:= delay_ms(10000);
:= printf("\r\nBuffered data => ");
:= while(bkbhit)
:= putc( bgetc() );
:= printf("\r\n");
:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=
:= //putc( bgetc() );
:=
:= for (i=0;i<16;i++)
:= {
:=
:= printf( " \%c\r\n ",buffer[i]);
:=
:= }
:= }
:= while (TRUE);
:=
:=}
This is because of the different output statements you are using. The first one that sends the data back to hyperterminal is using putc, and therefore just sends the '1' characters in your example. However in the second part of the code, where you send the data to the RS232, you use 'printf(" \%c\r\n ",buffer[1]);'
This sends 'space, character, carriage_return, line_feed, space' for each character. The exact positions this gives on your LCD, will depend on how it handles the line feed/carriage return characters, but is why you are getting the characters spaced out onto the two lines.
You have done well so far (keeping the serial code tidy, and doing the main handling outside the interrupt routines), so tidy the second output, and you should be moving forward. :-)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9838
isaac aiyanyo
Guest







Re: Help with serial interupt
PostPosted: Sat Dec 07, 2002 4:30 am     Reply with quote

R.J.Hamlett
Thank you very much for your response.
i did remove the CR ,space and new line so that it reads
printf( "\%c",buffer[i]);
i now get the characters displayed but they are not
consistant.
i noticed and timed the response and noticed that
from power up if i wait 10 or 11 seconds then send the
data to the pic it receives and displays the correct
characters but not all the time.
would it be possible to use putc("\%c",buffer[i]); ?
why do you think i get this problem.
Isaac







:=Hello pic_stars
:= i need some of your expert advice on theis problem.
:= i am new to pic c but i am determine to learn.
:= i am trying to display the characters that are received during
:= interupt but i can't seem to using a serial lcd connected to RA0
:= and running at 9600 baud.
:= when i run the program i and type in says
:= 1111111111111111 , i get the correct characters displayed on hyperterminal
:= Buffered data =>1111111111111111 but on the lcd its is displayed as
:= 1 1 1 1 on the top line and 1 1 1 1 on the bottom line
:= i want to be able to display the characters on the lcd
:= please could you guys help and tell me were i am going wrong.
:= the program is below
:=Thanks in advance
:=Isaac
:=
:=#if defined(__PCM__)
:=#include <16F876.H>
:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=void lcdout() ;
:=
:=#byte port_a=5
:=#byte port_b=6
:=#byte port_c=7
:=
:=
:=#define BUFFER_SIZE 16
:=byte buffer[BUFFER_SIZE];
:=byte next_in = 0;
:=byte next_out = 0;
:=
:=
:=#int_rda
:=void serial_isr()
:={
:=
:= int t;
:= output_low(PIN_C4);
:= buffer[next_in]=getc();
:= t=next_in;
:= next_in=(next_in+1) \% BUFFER_SIZE;
:= if(next_in==next_out)
:= next_in=t; // Buffer full !!
:=}
:=
:=#define bkbhit (next_in!=next_out)
:=
:=byte bgetc()
:={
:= byte c;
:=
:= while(!bkbhit) ;
:= c=buffer[next_out];
:= next_out=(next_out+1) \% BUFFER_SIZE;
:= return(c);
:=}
:=
:=
:=
:=main()
:={
:= int i;
:= enable_interrupts(global);
:= enable_interrupts(int_rda);
:=
:= printf("\r\n\Running...\r\n");
:=
:= // The program will delay for 10 seconds and then display
:= // any data that came in during the 10 second delay
:=
:= do
:= {
:= output_high(PIN_C4);
:= delay_ms(10000);
:= printf("\r\nBuffered data => ");
:= while(bkbhit)
:= putc( bgetc() );
:= printf("\r\n");
:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=
:= //putc( bgetc() );
:=
:= for (i=0;i<16;i++)
:= {
:=
:= printf( " \%c\r\n ",buffer[i]);
:=
:= }
:= }
:= while (TRUE);
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 9850
R.J.Hamlett
Guest







Re: Help with serial interupt
PostPosted: Sat Dec 07, 2002 5:57 am     Reply with quote

:=R.J.Hamlett
:= Thank you very much for your response.
:= i did remove the CR ,space and new line so that it reads
:= printf( "\%c",buffer[i]);
:= i now get the characters displayed but they are not
:= consistant.
:= i noticed and timed the response and noticed that
:= from power up if i wait 10 or 11 seconds then send the
:= data to the pic it receives and displays the correct
:= characters but not all the time.
:= would it be possible to use putc("\%c",buffer[i]); ?
:= why do you think i get this problem.
:= Isaac
Yes, you should be able to use putc. Printf, internally uses putc, and is normally only used, where you want to 'format' the output, changing (for instance) internal numbers into hex strings etc. However though printf, may be adding some overhead (it depends on how efficient the compiler is at realising that you are really only performing a 'putc'), I doubt if this is causing the problem.
Try putc anyway, to see if it helps.
Then I'd be more inclined to consider the speed of the LCD. Does it (for instance), need some time to initialise (this would explain the need to wait before the first character)?. Does it need any 'wake up' initialisation string?. It may also be that it needs some time between characters, which could explain the inconsistent behaviour. Your output loop, will pretty much send the characters without any pause. Normally I'd not expect this to be a problem with simple text (most LCD chipsets take only uSecs to actually write a character), but some commands (like CLS, and HOME), require several mSec to complete, and this has to be allowed for. Worth also realising that the data being sent to the LCD, will be using a 'soft' UART, instead of the hardware used for the PC communications, and this might be getting slightly 'mistimed', if anything else is happening at the same time (remember if more characters are received, this will result in a receive interrupt, which could lead to such an error).

Best Wishes

:=:=Hello pic_stars
:=:= i need some of your expert advice on theis problem.
:=:= i am new to pic c but i am determine to learn.
:=:= i am trying to display the characters that are received during
:=:= interupt but i can't seem to using a serial lcd connected to RA0
:=:= and running at 9600 baud.
:=:= when i run the program i and type in says
:=:= 1111111111111111 , i get the correct characters displayed on hyperterminal
:=:= Buffered data =>1111111111111111 but on the lcd its is displayed as
:=:= 1 1 1 1 on the top line and 1 1 1 1 on the bottom line
:=:= i want to be able to display the characters on the lcd
:=:= please could you guys help and tell me were i am going wrong.
:=:= the program is below
:=:=Thanks in advance
:=:=Isaac
:=:=
:=:=#if defined(__PCM__)
:=:=#include <16F876.H>
:=:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=:=#use delay(clock=20000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=:=void lcdout() ;
:=:=
:=:=#byte port_a=5
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=
:=:=
:=:=#define BUFFER_SIZE 16
:=:=byte buffer[BUFFER_SIZE];
:=:=byte next_in = 0;
:=:=byte next_out = 0;
:=:=
:=:=
:=:=#int_rda
:=:=void serial_isr()
:=:={
:=:=
:=:= int t;
:=:= output_low(PIN_C4);
:=:= buffer[next_in]=getc();
:=:= t=next_in;
:=:= next_in=(next_in+1) \% BUFFER_SIZE;
:=:= if(next_in==next_out)
:=:= next_in=t; // Buffer full !!
:=:=}
:=:=
:=:=#define bkbhit (next_in!=next_out)
:=:=
:=:=byte bgetc()
:=:={
:=:= byte c;
:=:=
:=:= while(!bkbhit) ;
:=:= c=buffer[next_out];
:=:= next_out=(next_out+1) \% BUFFER_SIZE;
:=:= return(c);
:=:=}
:=:=
:=:=
:=:=
:=:=main()
:=:={
:=:= int i;
:=:= enable_interrupts(global);
:=:= enable_interrupts(int_rda);
:=:=
:=:= printf("\r\n\Running...\r\n");
:=:=
:=:= // The program will delay for 10 seconds and then display
:=:= // any data that came in during the 10 second delay
:=:=
:=:= do
:=:= {
:=:= output_high(PIN_C4);
:=:= delay_ms(10000);
:=:= printf("\r\nBuffered data => ");
:=:= while(bkbhit)
:=:= putc( bgetc() );
:=:= printf("\r\n");
:=:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=:=
:=:= //putc( bgetc() );
:=:=
:=:= for (i=0;i<16;i++)
:=:= {
:=:=
:=:= printf( " \%c\r\n ",buffer[i]);
:=:=
:=:= }
:=:= }
:=:= while (TRUE);
:=:=
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 9851
isaac aiyanyo
Guest







Re: Help with serial interupt (Now working)
PostPosted: Sun Dec 08, 2002 10:26 am     Reply with quote


R.J.Hamlett
Thank you very much for your response.
i took your advice and both circuits are working
perfectly.
i included a 1000mS start up delay for the lcd
and i also used putc.
You have being great help.
i have included the modifier program below and i tried to
comment it to the best of my abolity
Thanks a million
Isaac


#if defined(__PCM__)
#include <16F876.H>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
void lcdout() ;

#byte port_a=5
#byte port_b=6
#byte port_c=7


#define BUFFER_SIZE 16
byte buffer[BUFFER_SIZE];
byte Data [16];
byte next_in = 0;
byte next_out = 0;




#int_rda
void serial_isr()
{

int t;
output_low(PIN_C4);
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) \% BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}

#define bkbhit (next_in!=next_out)

byte bgetc()
{
byte c;

while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) \% BUFFER_SIZE;
return(c);
}



main()
{

int i;
delay_ms(1000); // 1 sec delay to enable lcd to start up
enable_interrupts(global); // enable global interupt
enable_interrupts(int_rda); // enable serial interupt

do
{

output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
//ready to receive data
printf("Powering up !!\r\n"); //Display this on hyperterminal

delay_ms(10000); //The program will delay for 10 seconds and then display
//any data that came in during the 10 second delay
printf("\r\nBuffered data => "); // display this to hypertherminal
while(bkbhit) // cheak if (bkbhit) is set or true
putc( bgetc() ); //if true there is data so display it
printf("\r\n"); //with carriage return and new line

// be displayed is the data received during int
// and not the ones received when displaying
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
// Now set the pins and data rate for the serial lcd on ra0

for (i=0;i<16;i++) // loop 16 times though buffer[0]
{ // to buffer[15]
Data[i]= buffer[i]; // copy buffer & store in Data array
putc(Data[i]); // display the characters in those locations
} // on serial lcd connecte RA0
}
while (TRUE); // Do it all again

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 9864
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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