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 CCS Technical Support

Pic16f1823 Hardware Uart

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



Joined: 09 Apr 2011
Posts: 3

View user's profile Send private message

Pic16f1823 Hardware Uart
PostPosted: Mon May 30, 2011 1:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 30, 2011 1:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 30, 2011 2:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 30, 2011 2:42 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 30, 2011 2:46 pm     Reply with quote

Thank you very much! that did it :D
Eddy71ua



Joined: 23 Sep 2009
Posts: 55
Location: Ukraine

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 13, 2018 2:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 13, 2018 3:42 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 13, 2018 3:52 am     Reply with quote

Thank you so much! Everything works great. Very Happy
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