View previous topic :: View next topic |
Author |
Message |
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
Pic18F13K22 rda_int Problems |
Posted: Sun Jan 17, 2010 5:28 pm |
|
|
Hi
Thanks for any help in advance.
I started a new project using the Pic 18F13K22. I cannot get the serial interrupt to activate. I know that code should work because I have used the same code with 18F252 and 18F6722 pics.
I am not posting my project code because it would be too long.
I did some searching in the forum and found this short piece of code written by PCM PROGRAMMER. I tried the code but still does not work.
Compiler Version 4.88 PCH
I modified the code to work with the 18F13K22 chip. The code compiles fine and runs. Output to serial terminal 'Hello World' is observed. But I cannot echo data back by any keys on keyboard via rda interrupt.?
Any Ideas???.
Thanks Again
Code: |
#include <18F13K22.H>
#fuses intrc_io, nowdt, noprotect, mclr, nolvp, put, nofcmen, noieso
#fuses borv30, nodebug
#device *=16
#device adc=8
#define FREQ_OSC 8000000
#define BAUD_RATE 9600
#use delay(clock = FREQ_OSC)
#byte PIR1 = 0xf9e
#byte SPBRG = 0xfaf
#byte RCSTA = 0xfab
#byte TXREG = 0xfad
#byte RCREG = 0xfae
#byte TXSTA = 0xfac
#bit TXIF = PIR1.4
#bit RCIF = PIR1.5
#bit CREN = RCSTA.4
//------------------------
// Wait for the hardware UART's transmitter
// to become ready and then send the specified
// character.
void my_putc(char c)
{
while(!TXIF);
TXREG = c;
}
//------------------------
// Wait for character to be available from the
// hardware UART's receiver and then return it.
// If there is an overrun error, then clear it.
char my_getc(void)
{
int temp;
int retval;
while(!RCIF);
temp = RCSTA;
retval = RCREG;
if(bit_test(temp, 1))
{
CREN = 0;
CREN = 1;
}
return(retval);
}
//-------------------------
void init_uart(void)
{
SPBRG = (FREQ_OSC / (BAUD_RATE * 16)) -1;
TXSTA = 0x26;
RCSTA = 0x90;
}
#int_rda
void rda_isr(void)
{
char c;
c = my_getc();
my_putc(c);
}
//================================
void main()
{
init_uart();
printf(my_putc, "Hello World\n\r");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 17, 2010 9:35 pm |
|
|
Quote: | Compiler Version 4.88 PCH |
Post your real version. Version numbers are in this format: x.xxx |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
Pic18F13K22 rda_int Problems |
Posted: Sun Jan 17, 2010 10:44 pm |
|
|
Sorry
Compiler Version 4.088 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 18, 2010 12:18 am |
|
|
I'm not sure why you're doing all this register stuff. Why not base your
code on this post here:
http://www.ccsinfo.com/forum/viewtopic.php?t=40214&start=7
I don't have vs. 4.088, but I do have vs. 4.087. I looked at the .LST
file for that version, and the fix for the ANSELx registers is needed.
The rest of it looks like it will probably work. |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Mon Jan 18, 2010 7:36 pm |
|
|
Thanks Its working. |
|
|
|