|
|
View previous topic :: View next topic |
Author |
Message |
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
printf and last versions of pcw |
Posted: Fri Dec 17, 2004 12:42 pm |
|
|
I have the last versions of PCW and have some problems.
To determine where are the problems I write little programs for 16F876. And I found some differences.
Here a part of my test program.
Code: |
char cMin, csec;
.....
cMin = 12;
csec= 54;
.....
printf(LCD_PutChar,"%02U %02d", cMin, csec);
.....
|
The printf( ) is in the while() and I increment cMin and csec each second. When the two variables come to 99, I reset to 1.
This program, compiled with version 3.163, show me 12 54 on my LCD and each second the two values are incremented. It's ok.
When I compile with versions 3.212 , 3.213 and 3.214 I see on my LCD 10 50. After 10 seconds I have 20 60 and so one. I never see 21 22 23 .... Only 20 30 40 ...
If I change the printf to printf(LCD_PutChar,"%02u:%02U", cMin, csec);
I have the same printing.
The last manual don't give a change in the parameters and the readme file don't give info. I see only this message on the CCS New version board :
Code: |
3.212 A %u and %d bug is fixed
|
Have somebody an answer ? Where is my mistake ?
Thanks and regard. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 17, 2004 5:48 pm |
|
|
You didn't provide a test program, so I made one.
Instead of having the output go to an LCD, I just have it
go to the terminal window on my PC. It works OK with
PCM vs. 3.214. Here is the output:
Code: | 12 54
13 55
14 56
15 57
16 58
17 59
18 60
19 61
20 62
21 63
22 64
23 65
24 66
25 67
26 68
27 69 |
Code: | #include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main()
{
char i;
char cMin = 12;
char cSec = 54;
while(1)
{
printf("%02U %02d \n\r", cMin, cSec);
cMin++;
cSec++;
delay_ms(500);
}
while(1);
} |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Dec 17, 2004 6:48 pm |
|
|
There seems to be a problem when using the lcd (lcd_putc). In the below test program, the first line prints correctly while the 2nd line is like what the posted saw.
Code: | #include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include "mylcd.c"
void main()
{
char i;
char cMin = 12;
char cSec = 54;
char buf[20];
lcd_init();
while(1)
{
sprintf(buf,"\f%02U %02d", cMin, cSec);
i = 0;
while (buf[i])
lcd_putc(buf[i++]);
printf(lcd_putc,"\n%02U %02d", cMin, cSec);
cMin++;
cSec++;
if (cMin == 99)
cMin = 1;
if (cSec == 99)
cSec = 1;
delay_ms(500);
}
} |
|
|
|
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
|
Posted: Sat Dec 18, 2004 3:04 am |
|
|
Many thanks for your answers.
I agree the fact that I don't have try with a terminal on my PC.
If my test program work fine on LCD compiled with my old version, with the 3 last versions it don't.
Normaly I used %02d for this variable, %02U was just for test.
Then the problem is in the LCD routine, but only with the 3 last versions. It's what Mark say.
Now the best is to compare both version.
Thanks and have a nice week end. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Dec 18, 2004 7:58 am |
|
|
To clear things up for anyone else reading this, the problem isn't per ce with the printf and its not with the lcd routine either but rather the 'glue' between them. |
|
|
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
|
Posted: Sun Dec 19, 2004 7:26 am |
|
|
Mark, thanks for your advies about this problem.
Here follow a little test program to show the problem and to discover "the glue".
My program is :
Code: |
/* test lcd 876 pcwh 3.214*/
#include <16F876.h>
#device *=16
#fuses HS,NOWDT,PUT,BROWNOUT,WRT,NOLVP
#use delay (clock=16000000)
#define CRYSTAL_FREQ 16000000
#define LINE_1 0x00
#define LINE_2 0x40
#define CLEAR_DISP 0x01
#define LCD_D0 PIN_A0 //DB4
#define LCD_D1 PIN_A1 //DB5
#define LCD_D2 PIN_A2 //DB6
#define LCD_D3 PIN_A3 //DB7
#define LCD_EN PIN_B6 //enable
#define LCD_RS PIN_B7 // rs
static char cSec;
const char Title [] = "Test LCD";
#separate void LCD_Init ( void );
#separate void LCD_SetPosition ( unsigned int cX );
#separate void LCD_PutChar ( unsigned int cX );
#separate void LCD_PutCmd ( unsigned int cX );
#separate void LCD_PulseEnable ( void );
#separate void LCD_SetData ( unsigned int cX );
Main ()
{
set_tris_a ( 0x00 ); // tout output
set_tris_b ( 0x00 );
cSec = 12 ;
LCD_Init ( ) ;
LCD_PutCmd ( CLEAR_DISP );
LCD_SetPosition ( LINE_1 );
printf(LCD_PutChar,"%s", Title);
LCD_SetPosition ( LINE_2 );
printf(LCD_PutChar,"%02d",cSec);
while (true)
{
}
}
|
To reduce the code, I don't print the LCD routine.
After compilation with version 3.163 and 3.214, I have compared the difference in the asm code.
I give here only the differences. First the with PCW version 3.163
Code: |
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 101
0003: NOP
.................... /* test lcd 876 pcwh 3.163*/
....................
.................... #include <16F876.h>
.................... //////// Standard Header file for the PIC16F876 device ////////////////
.................... #device PIC16F876
.................... #list
....................
.................... #device *=16
.................... #fuses HS,NOWDT,PUT,BROWNOUT,WRT,NOLVP
.................... #use delay (clock=16000000)
*
0032: MOVLW 24
0033: MOVWF 04
0034: BCF 03.7
.............................................................
.................... static char cSec;
*
0108: BCF 03.5
0109: CLRF 20
....................
.................... const char Title [] = "Test LCD";
*
0004: BCF 0A.0
0005: BCF 0A.1
0006: BCF 0A.2
0007: ADDWF 02,F
0008: RETLW 54
0009: RETLW 65
000A: RETLW 73
000B: RETLW 74
000C: RETLW 20
000D: RETLW 4C
000E: RETLW 43
000F: RETLW 44
0010: RETLW 00
....................
.................... printf(LCD_PutChar,"%s", Title);
0117: CLRF 21
0118: MOVF 21,W
0119: CALL 004
011A: IORLW 00
011B: BTFSC 03.2
011C: GOTO 121
011D: INCF 21,F
011E: MOVWF 23
011F: CALL 094
0120: GOTO 118
.................... printf(LCD_PutChar,"%02d",cSec);
*
00BC: MOVF 21,W
00BD: MOVWF 77
00BE: BTFSC 21.7
00BF: GOTO 0C4
00C0: BTFSS 22.2
00C1: GOTO 0CE
00C2: MOVLW 20
00C3: GOTO 0C9
00C4: COMF 77,F
00C5: INCF 77,F
00C6: MOVF 77,W
00C7: MOVWF 21
00C8: MOVLW 2D
00C9: MOVWF 78
00CA: MOVWF 23
00CB: CALL 094
00CC: BTFSS 22.2
00CD: BSF 22.3
00CE: MOVF 21,W
00CF: MOVWF 23
00D0: MOVLW 64
00D1: MOVWF 24
00D2: CALL 0A7
00D3: MOVF 77,W
00D4: MOVWF 21
00D5: MOVF 78,W
00D6: MOVLW 30
00D7: BTFSS 03.2
00D8: GOTO 0E0
00D9: BTFSC 22.0
00DA: GOTO 0E6
00DB: BTFSC 22.3
00DC: GOTO 0E6
00DD: BTFSC 22.4
00DE: MOVLW 20
00DF: GOTO 0E2
00E0: BCF 22.3
00E1: BCF 22.4
00E2: ADDWF 78,F
00E3: MOVF 78,W
00E4: MOVWF 23
00E5: CALL 094
00E6: MOVF 21,W
00E7: MOVWF 23
00E8: MOVLW 0A
00E9: MOVWF 24
00EA: CALL 0A7
00EB: MOVF 77,W
00EC: MOVWF 21
00ED: MOVF 78,W
00EE: MOVLW 30
00EF: BTFSS 03.2
00F0: GOTO 0F5
00F1: BTFSC 22.3
00F2: GOTO 0F9
00F3: BTFSC 22.4
00F4: MOVLW 20
00F5: ADDWF 78,F
00F6: MOVF 78,W
00F7: MOVWF 23
00F8: CALL 094
00F9: MOVLW 30
00FA: ADDWF 21,F
00FB: MOVF 21,W
00FC: MOVWF 23
00FD: CALL 094
00FE: BCF 0A.3
00FF: BCF 0A.4
0100: GOTO 129 (RETURN)
*
0124: MOVF 20,W
0125: MOVWF 21
0126: MOVLW 01
0127: MOVWF 22
0128: GOTO 0BC
....................
.................... while (true)
|
And for PCWH version 3.124
Code: |
CCS PCM C Compiler, Version 3.214, 26317 19-d�c.-04 12:44
Filename: C:\CCS Tests\876 lcd 214.LST
ROM used: 318 words (4%)
Largest free fragment is 2048
RAM used: 7 (2%) at main() level
11 (3%) worst case
Stack: 4 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 112
0003: NOP
.................... /* test lcd 876 pcwh 3.214*/
....................
....................
.................... static char cSec;
*
011B: BCF 03.5
011C: CLRF 20
....................
.................... const char Title [] = "Test LCD";
....................
.................... #separate void LCD_Init ( void );
.................... #separate void LCD_SetPosition ( unsigned int cX );
....................
.................... cSec = 12 ;
0121: MOVLW 0C
0122: BCF 03.5
0123: MOVWF 20
....................
.................... printf(LCD_PutChar,"%s", Title);
012A: CLRF 21
012B: MOVF 21,W
012C: CALL 004
012D: IORLW 00
012E: BTFSC 03.2
012F: GOTO 134
0130: INCF 21,F
0131: MOVWF 23
0132: CALL 094
0133: GOTO 12B
.................... printf(LCD_PutChar,"%02d",cSec);
0137: MOVF 20,W
0138: MOVWF 21
0139: MOVLW 01
013A: MOVWF 22
013B: GOTO 0BC
....................
.................... while (true)
|
There are no difference in the LCD code.
I see that :
- the code for the const char Title [] = "Test LCD"; is missing
- the code for printf(LCD_PutChar,"%02d",cSec); is totally different
- the code for printf(LCD_PutChar,"%s", Title); call to addresse 0004 not excist.
What can I do ?
I thing the only solution is send a mail to CCS....
Thanks for all what you do in this forum. Have a nice day. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 19, 2004 12:20 pm |
|
|
To see the code which begins at 0004, edit the 16F876.H file
and comment out the #nolist statement at the beginning of the file.
Example:
//////// Standard Header file for the PIC16F876 device ////////////////
#device PIC16F876
// #nolist <- Comment out this line
Then recompile your program and look at the .LST file.
You will now see the code at 0004. |
|
|
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
|
Posted: Wed Dec 22, 2004 4:28 pm |
|
|
Answer received today from CCS :
Code: |
This will be fixed in 3.215.
|
Thanks. |
|
|
bfmitch
Joined: 21 Aug 2004 Posts: 8
|
A workaround |
Posted: Mon Jan 03, 2005 9:11 am |
|
|
If you need to display int8 values, print them as int16 instead with the variable cast as an int16.
Code: |
int8 var1;
int8 var2;
printf ( lcd_putc, "Variable1: %lu Lbs", (int16)var1 );
printf ( lcd_putc, "Variable2: %lu", (int16)var2 );
|
When they get the bug fixed, it'll be simple to change them to what they should be.
The problem doesn't seem to exist when using serout in 3.214. However, I seem to remember that in 3.212 it did exist in serout. It drove me crazy for about 4 hours one day. I finally decided it was an optimization issue and found a different way to do it.
If they fixed it by modifying serout instead of printf, I hope they remember to take the change out of serout when printf gets fixed. |
|
|
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
Thanks. |
Posted: Mon Jan 03, 2005 5:49 pm |
|
|
Thanks for your suggestion. I'll try tomorrow. |
|
|
Guest
|
How about 3.215 ? |
Posted: Wed Jan 05, 2005 8:35 am |
|
|
How about 3.215 ? |
|
|
bfmitch
Joined: 21 Aug 2004 Posts: 8
|
Just Updated Apparently |
Posted: Wed Jan 05, 2005 8:42 am |
|
|
Two days ago the current version was 3.214. I haven't received an email telling me that 3.215 was available. Apparently it is now. |
|
|
GDetienne
Joined: 20 Sep 2003 Posts: 47 Location: Brussel - Belgium
|
Bug solved |
Posted: Fri Jan 07, 2005 1:29 am |
|
|
This bug is solved in the last version (3.215).
Thanks for you help. |
|
|
|
|
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
|