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 CCS Technical Support

#use rs232 streamed (derived from code example ex_8pin.c)

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







#use rs232 streamed (derived from code example ex_8pin.c)
PostPosted: Fri Jun 18, 2004 5:32 am     Reply with quote

Dear all

Please excuse my novice question:

I am using PIC16F876 clocked at 4Mhz. I use the hardware uart to communicate with a PC using interupt driven uart. This section of code works well.


My challenge is that I am failing to understand the concept of programming a second ISR for PORT B.

#use rs232(baud=9600,xmit=pin_b4,rcv=pin_b5,stream=HOST_B)

How can I program a second ISR to be used only by Port B (for both Xmit and Rcv)? Will I not lose data from any stream if both the UART and the PORT B are active at the same time?

Your assisatance is very much appreciated.

Yours truly

Josh


I include portions of code for your analysis:



#include <16f876.h>
#include <ctype.h>


#fuses NOWDT,NOPROTECT
#use delay(clock=4000000)
#use fast_io (A)
#use fast_io (B)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stream=HOST_A)

#use rs232(baud=9600,xmit=pin_c0,stream=booth1)
#use rs232(baud=9600,xmit=pin_c1,stream=booth2)
#use rs232(baud=9600,xmit=pin_c2,stream=booth3)
#use rs232(baud=9600,xmit=pin_c3,stream=booth4)


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


#int_rda
void serial_isr() {
int t;

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;
code = ' ';
return(c);
}


main() {

set_tris_a (0);
set_tris_b (0);
// set_tris_c (0b000000);

enable_interrupts(global);
enable_interrupts(int_rda);

fprintf(host,"\r\n\Running..host.\r\n");
fprintf(booth1,"xaa4686");
fprintf(booth2,"\r\n\Running..booth2.\r\n");
fprintf(booth3,"\r\n\Running..booth3.\r\n");
fprintf(booth4,"\r\n\Running..booth4.\r\n");
while (true) {

#INCLUDE <DISPLAY.H> //this header processes received RS232 data.

while(bkbhit)

putc( bgetc() );
}

}
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Fri Jun 18, 2004 6:18 am     Reply with quote

The 16F8766 has only one hardware UART and, hence, only one UART interrupt. Any other serial stream you create will be software driven and wil have no interrupts available. Beware, on the transmit side the SW ports can work pretty well, but receiving can eat up processor time.

That said, you could fashion a sort of serial interrupt on RX, by having the RX signal on Port B and use an edge or level triggered interrupt. The start bit would trigger an interrupt and you could either process the incoming byte 'by hand', or maybe set up a timer to go back and check as each bit is anticipated. Or, use one of the interrupt-on-change pins - here you could time between changes and decipher the byte from that. Hmm - I like that way, never tried it but that could be pretty efficient. Depends on baud and what else you are doing. Maybe this is what you were thinking of. I haven't tried any of these exact methods, but it's food for thought....

- SteveS
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