View previous topic :: View next topic |
Author |
Message |
CharlesParker47
Joined: 09 May 2012 Posts: 3
|
ex_rtc.c code explanation |
Posted: Wed May 09, 2012 4:00 pm |
|
|
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
|
|
Posted: Wed May 09, 2012 4:07 pm |
|
|
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)
|
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
|
ex_rtc.c code explanation |
Posted: Wed May 09, 2012 8:20 pm |
|
|
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'. |
|
|
|