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

Interrupt for software uart 18F452

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







Interrupt for software uart 18F452
PostPosted: Sat May 10, 2003 3:55 am     Reply with quote

How can I make a interrupt routine for the software uart that can both receive and transmit serial data? (I need to use two uart's with interrupt). If I send a character using hyperterminal, I only get back garbage. Do I loose data information because of the ext interrupt? The start message "PIC started" (Check the code below) is printed out nicely. If i poll the port in the main loop everything works fine.

Please help.

/Fredrik

//--------------------------------------------------------

#include <18f452.h>
#device *=16 ADC=10
#include <string.h>

//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
#ID CHECKSUM
#ZERO_RAM
#use DELAY(CLOCK=19860800)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#byte PORTA=0xf80
#byte PORTB=0xf81
#byte PORTC=0xf82
#byte PORTD=0xf83
#byte PORTE=0xf84

#int_ext
void ext_isr(void);

#use rs232(baud=38400, xmit=PIN_B1, rcv=PIN_B0, PARITY=N, BITS=8)

void main(void) {

SET_TRIS_A(0x00); // A out
SET_TRIS_B(0x01); // Input: B0, Output: B1-B7
SET_TRIS_C(0xa8); // 1010 1000
SET_TRIS_D(0x00); // D out
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

printf("\r\nPIC started\r\n");
delay_ms(100);

while(1)
{
}
}

#int_ext
void ext_isr(void)
{
char c;
c = getc(); // receive the character
putc(c); // echo back character to sender
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 14337
Nikki
Guest







Re: Interrupt for software uart 18F452
PostPosted: Sat May 10, 2003 9:34 am     Reply with quote

:=#use rs232(baud=38400, xmit=PIN_B1, rcv=PIN_B0, PARITY=N, BITS=8)

I did this, but it only worked at a maximum 57600 with a 40Mhz crystal. Try lowering the baud rate to 19200.

The main problem I think is the interrupt latency of 35 or more instruction.

Nikki
___________________________
This message was ported from CCS's old forum
Original Post ID: 14339
Fredrik
Guest







Re: Interrupt for software uart 18F452
PostPosted: Mon May 12, 2003 6:31 am     Reply with quote

Added the line "ext_int_edge(H_TO_L);" to the code and that solved the problem.

:= SET_TRIS_D(0x00); // D out
:= ext_int_edge(H_TO_L);
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);


/Fredrik
___________________________
This message was ported from CCS's old forum
Original Post ID: 14371
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