|
|
View previous topic :: View next topic |
Author |
Message |
ist Guest
|
interrupt question |
Posted: Tue Aug 08, 2006 8:48 am |
|
|
Hi;
Can I use Pin B3 as interrupt? I assigned Pin B3 as rcv pin of rs232. And want to detect the data coming. As far as I know, only B0 can be used as rs232 interrupt! Is that true (hope not, cause I already soldered the circuit). Code is below;
Code: | #USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3, ERRORS)
#define BUFFER_SIZE 8
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_ext //If there is char on serial, detect it!!
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 !!
} |
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Tue Aug 08, 2006 8:55 am |
|
|
What PIC are you using?
Errors only works with the hardware UART.
If you are using a software UART and want to use an interrupt for start bit detection then any will suffice if there is no other interrupt routines to be handled.
If however you have an 18F series PIC you can use high priority PICs for the serial handler. This can be very efficently coded enabling you to achieve high baud rate with low overhead. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
ist Guest
|
|
Posted: Thu Aug 10, 2006 7:22 am |
|
|
Thanks for ur reply andrew;
Sorry about insufficient information.
I am using pic16f877 and there is not any other interrupt part. And this interrupt is software interrupt. I will post whole program this time so that there is not any insufficient infrmation.
Kind regards, Murat!
Code: | #include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define KEYHIT_DELAY 500 // in milliseconds
#use fast_io(D)
char b_timed_getc() { //Wait for the response from pc for a limited time!!
long timeout;
char retval;
timeout=0;
while(!kbhit() && (++timeout< KEYHIT_DELAY*100))
delay_us(10);
if(kbhit())
retval = getc();
else
retval = 0;
return(retval);
}
void put_to_a( char c ) { //transmit the data grabbed from the buffer!!
putc(c);
}
#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3, ERRORS)
#define BUFFER_SIZE 8
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_ext //If there is char on serial, detect it!!
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() { //empty the buffer byte by byte
BYTE c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}
void put_to_b( char b ) { //send the response of pc!!
putc(b);
}
void main() {
char c1;
enable_interrupts(global);
enable_interrupts(int_ext);
SET_TRIS_D( 0x01 );
// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay
do {
delay_ms(10000);
while(bkbhit) {
while ( !input(PIN_D0) );
output_low(PIN_D5);
put_to_a( bgetc() );}
output_low(PIN_D5);
while( !input(PIN_D0));
c1=b_timed_getc();
if(c1==0) {
reset_cpu();
// printf("please swipe your card again");
}
put_to_b(c1);
} while (TRUE);
} |
|
|
|
|
|
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
|