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 support@ccsinfo.com

Can you please help me to understand this?

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








Can you please help me to understand this?
PostPosted: Tue Feb 22, 2005 7:27 am     Reply with quote

Hello,
I am trying to understand how printf is implemented in CCS so I can develop codes that can work in two different OSC mode.

I wrote a very simple code and then view its list:
The list for the code is as follow:

CCS PCH C Compiler, Version 3.214, 26831 22-Feb-05 12:56

ROM used: 464 bytes (1%)
Largest free fragment is 65072
RAM used: 8 (0%) at main() level
13 (0%) worst case
Stack: 2 locations

*
0000: GOTO 013C
.................... #include <18F2620.h>
.................... //////// Standard Header file for the PIC18F2620 device ////////////////
.................... #device PIC18F2620
.................... #list
....................
.................... #use delay(clock=8000000)
.................... #fuses NOWDT,WDT128,INTRC, NOPROTECT, NOIESO, NOBROWNOUT, BORV21, PUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, NOFCMEN, NOXINST, NOPBADEN, NOLPT1OSC, NOMCLR
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS)
....................
.................... void main()
.................... {
013C: CLRF FF8
013E: BCF FD0.7
0140: CLRF FEA
0142: CLRF FE9
0144: MOVF FC1,W
0146: ANDLW C0
0148: IORLW 0F
014A: MOVWF FC1
014C: MOVLW 07
014E: MOVWF FB4
0150: MOVF FB4,W
0152: BCF FA1.6
0154: MOVLW 0C
0156: MOVWF FAF
0158: MOVLW 22
015A: MOVWF FAC
015C: MOVLW 90
015E: MOVWF FAB
0160: CLRF 05
.................... int i=0;
0162: CLRF 06
.................... printf("test1");
0164: CLRF 07
0166: MOVF 07,W
0168: RCALL 0004
016A: INCF 07,F
016C: MOVWF 00
016E: MOVF 00,W
0170: BTFSS F9E.4
0172: BRA 0170
0174: MOVWF FAD
0176: MOVLW 05
0178: SUBWF 07,W
017A: BNZ 0166
.................... printf("test2");
017C: CLRF 07
017E: MOVF 07,W
0180: RCALL 001A
0182: INCF 07,F
0184: MOVWF 00
0186: MOVF 00,W
0188: BTFSS F9E.4
018A: BRA 0188
018C: MOVWF FAD
018E: MOVLW 05
0190: SUBWF 07,W
0192: BNZ 017E
.................... printf("Test3=%d",i);
0194: CLRF 07
0196: MOVF 07,W
0198: RCALL 0030
019A: INCF 07,F
019C: MOVWF 00
019E: MOVF 00,W
01A0: BTFSS F9E.4
01A2: BRA 01A0
01A4: MOVWF FAD
01A6: MOVLW 06
01A8: SUBWF 07,W
01AA: BNZ 0196
01AC: MOVFF 06,08
01B0: MOVLW 18
01B2: MOVWF 09
01B4: BRA 0088
.................... #use delay(clock=32000)
.................... printf("test4");
01B6: CLRF 07
01B8: MOVF 07,W
01BA: RCALL 004A
01BC: INCF 07,F
01BE: MOVWF 00
01C0: MOVF 00,W
01C2: BTFSS F9E.4
01C4: BRA 01C2
01C6: MOVWF FAD
01C8: MOVLW 05
01CA: SUBWF 07,W
01CC: BNZ 01B8
....................
.................... }
....................
01CE: SLEEP

Configuration Fuses:
Word 1: 0900 NOIESO INTRC NOFCMEN
Word 2: 0E18 NOBROWNOUT WDT128 NOWDT BORV21 PUT
Word 3: 0100 CCP2C1 NOPBADEN NOLPT1OSC NOMCLR
Word 4: 0081 STVREN NODEBUG NOLVP NOXINST
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTR NOEBTRB


The first printf ( starts from memory location 0164 has a RCALL which it pointed to 172. but I couldn’t find any return instruction to show that this call will return eventually.

In the second printf, this RCALL points to a place in the third printf(!) and in the third printf it is pointed to the forth printf and in the forth printf it is pointed to some where that isn’t in my list?

I think there is something wrong here. Probably the list isn’t correct or my understanding of RCALL isn’t accurate. Could somebody help me to understand what is happening here?

Best regards
Ttelmah
Guest







PostPosted: Tue Feb 22, 2005 9:06 am     Reply with quote

If you want to work at two different clock rates, don't try to fiddle with the printf, instead use it's ability to call a subroutine to actually print.
If you code your printf statements as:

printf(your_function,"What to print");

Then 'your_function' will be called for every byte of the print. You can simply have this contain the speed change code.
You will find that the printf 'calls', are much more comprehensible if you turn off the 'nolist' option in the processor .h file. The calls are to table lookup routines, to return the constant characters from memory. These are called in turn for each character in the string, and each character is then put into the serial transmission register, if the busy flag is not set.
You are wrong in where you think the RCALL instructions go. They go to the absolute addresses they _say_. The compiler handles the job of working out the relative offset. So an 'RCALL 30', does not jump you forward 30 instructions, but jumps you to address 30. If you disassemble the code inside MPLAB, you will see the actual instruction generated.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 22, 2005 5:24 pm     Reply with quote

Since you are using the hardware uart it doesn't really matter. What you need to do it set the uart setup registers manually. Switch speeds (osc) then just change the baud rate generator register. Beaware of the other functions that rely on the clock=XXXXXXXX statement. Namely the delays.
Guest








PostPosted: Tue Feb 22, 2005 5:25 pm     Reply with quote

Thank you very much for your help.

I will look at your suggestion for the way of working with two different OSC setting. Your point made me more enthusiastic and will be appreciated if you could help me for the following items as well:

1- What do you mean by:
• ” I should turn off #nolisting in the header file”
• “RCALL transferring to an absolute address” How is it possible? RCALL is a relative subroutine call, Where is my misunderstanding?

Best regards
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