PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 09, 2010 2:25 pm |
|
|
I was able to make it work. But vs. 4.112 does have a bug, compared to
vs. 4.114. In the 18F45K22, all the i/o pins come up in Analog mode after
a power-on reset. In vs. 4.114, CCS loads all the ANSEL registers with 0
in their start-up code. This sets all the i/o pins to be in digital mode.
But in your version (4.112) CCS doesn't do this.
So to fix it, I added a short routine that emulates the behavior of 4.114.
It sets all ports to be Digital i/o. Just call this routine at the beginning of
of main() as shown in the program below. Then it should work. I did this
and it worked at both 300 baud and at 9600 baud.
The program below just echoes a character that you type in a terminal
window, such as TeraTerm. Whatever you type, will be received by the
PIC and sent back to the PC where you can see it on the screen.
Code: |
#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use rs232(baud=300, UART1, ERRORS)
void make_all_pins_digital(void)
{
#byte ANSELA = 0xF38
#byte ANSELB = 0xF39
#byte ANSELC = 0xF3A
#byte ANSELD = 0xF3B
#byte ANSELE = 0xF3C
ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
ANSELD = 0;
ANSELE = 0;
}
#int_rda
void rda_isr(void)
{
int8 c;
c = getc();
putc(c);
}
//======================================
void main(void)
{
make_all_pins_digital();
printf("Start: ");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1);
} |
|
|