View previous topic :: View next topic |
Author |
Message |
rstevenson
Joined: 09 Apr 2011 Posts: 3
|
Pic16f1823 Hardware Uart |
Posted: Mon May 30, 2011 1:44 pm |
|
|
I'm using Pickit2's uart tool to receive the uart. My problem is i can get the software uart to work but my hardware one does not work. I have checked if i used the right pins many times, I've used getenv to make sure they were the right pins. Is there anything i am doing wrong? oh and my compiler version is 4.12. Help is greatly appreciated!
Code: | #include <16F1823.h>
#DEVICE ADC=10
#FUSES NOWDT NOWRT NOLVP NOCPD NOPROTECT
#FUSES MCLR PUT INTRC_IO NOBROWNOUT
#use delay(clock=8000000)
#USE RS232(baud=9600, xmit=PIN_A2, rcv=PIN_C0)
//#use rs232(uart1, baud=9600)
void main()
{
setup_oscillator(OSC_8MHZ);
delay_us(20);
while (true){
printf("hello");
delay_ms(1000);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 30, 2011 1:59 pm |
|
|
Use this line, and use pin C4 for Tx, and pin A1 for Rx:
Code: |
#use rs232(baud=9600, UART1) |
If it doesn't work, then post your full compiler version (all 4 digits). |
|
|
rstevenson
Joined: 09 Apr 2011 Posts: 3
|
|
Posted: Mon May 30, 2011 2:11 pm |
|
|
i just tried that and i still get nothing. when i used getenv the pins for rx and tx were 97 and 96 which were A0 and A1.
edit: 4.120 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 30, 2011 2:42 pm |
|
|
I made a mistake. I was reading the data sheet section for the 16F1822.
The pins for UART1 for 16F1823 should be:
Tx: Pin C4
Rx: Pin C5
Keep using this line:
Code: |
#use rs232(baud=9600, UART1) |
|
|
|
rstevenson
Joined: 09 Apr 2011 Posts: 3
|
|
Posted: Mon May 30, 2011 2:46 pm |
|
|
Thank you very much! that did it :D |
|
|
Eddy71ua
Joined: 23 Sep 2009 Posts: 55 Location: Ukraine
|
|
Posted: Tue Feb 13, 2018 2:52 am |
|
|
PCM programmer wrote: | I made a mistake. I was reading the data sheet section for the 16F1822.
The pins for UART1 for 16F1823 should be:
Tx: Pin C4
Rx: Pin C5
Keep using this line:
Code: |
#use rs232(baud=9600, UART1) |
|
In datasheet wrote that the TX / RX pins can be switched to the pins PA0 / PA1
How can I do that? (REGISTER APFCON)
config:
Code: |
#use rs232(baud=9600, UART1A) |
not work (v.5.075) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 13, 2018 3:42 am |
|
|
Quote: |
In datasheet wrote that the TX / RX pins can be switched to the pins
PA0 / PA1. How can I do that? (REGISTER APFCON) |
To select the alternate pins for the UART on the 16F1823, use the following
code to setup the APFCON register:
Code: | #include <16F1823.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
#byte APFCON = getenv("SFR:APFCON")
#bit TXSEL = APFCON.2
#bit RXSEL = APFCON.7
//======================
void main()
{
TXSEL = 1;
RXSEL = 1;
while(TRUE);
}
|
|
|
|
Eddy71ua
Joined: 23 Sep 2009 Posts: 55 Location: Ukraine
|
|
Posted: Tue Feb 13, 2018 3:52 am |
|
|
Thank you so much! Everything works great. |
|
|
|