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

ex_rtc.c code explanation

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



Joined: 09 May 2012
Posts: 3

View user's profile Send private message

ex_rtc.c code explanation
PostPosted: Wed May 09, 2012 4:00 pm     Reply with quote

Could someone please explain what the following lines of code mean.
Line 57) first=getc(); how does getc() know where to go to get first?
Line 60) first-='0';
Line 100) printf("\r\nPress S to change, D to Display: "); Where does S & D come from?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 09, 2012 4:07 pm     Reply with quote

Quote:
how does getc() know where to go to get first?

You define the UART parameters in the #use rs232() statement that you
type into your program. Consult the CCS manual for parameters and/or
look at sample code that we post in this forum. Here is the line from the
ex_rtc.c file. Pins C6 and C7 are listed in the 16F877 data sheet as the
pins for the hardware UART:
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


Quote:
first-='0';

This code is subtracting the ASCII "bias" of 0x30 (which is '0'), so it can
convert ASCII numbers '0' to '9' (0x30 to 0x39) to binary values (0 to 9).


Quote:
Where does S & D come from?

From getc(). When you type S or D into a terminal program which runs
on your PC (such as TeraTerm), the character is transmitted to the PIC's
UART, which receives it and then getc() gets it from the UART. getc()
will wait in an internal loop, until the UART has a character available,
ie., it waits for you to press a key on your PC's keyboard while TeraTerm
has the focus.
CharlesParker47



Joined: 09 May 2012
Posts: 3

View user's profile Send private message

ex_rtc.c code explanation
PostPosted: Wed May 09, 2012 8:20 pm     Reply with quote

To PCM programmer:
Thank you very much.
I did not realize that a PC was connected and used in the actual running of the program.
When I saw the printf statement, I assumed, wrongly, it was connect to an LCD.
Therefore, the confusion, of where the S and D were coming from.
I thought it was running as an independant, stand alone module.
Thank you also for the explanation of first-='0'.
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