PSoC1 LCD

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
ChDe_285186
Level 4
Level 4

 I have loaded the PWM PRS example and added an LCD to display the CompareValue as a percentage as well as show the CompareValue as a bar graph. The 0 bargraph appears to be all partially on without the hexbyte displayed.

   

Archive attached

   

Any suggestions?

   

Chris 

0 Likes
66 Replies
Anonymous
Not applicable

@ bob. Is csprinf for wide characters?

   

also I was wondering why it's need to have type cast, I think it should not need to. as the formating string "%3d" is actually on flash.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Greetings from Harvard.

   

Since in the PSoC1 code the access to data residing in flash differs from ram accesses functiond need to know where parameters are stored. So sometimes two different functions exist like LCD_PrString() and LCD_PrCString();

   

Same is for sprintf() which expects the formatstring residing in ram and csprintf() expecting it in flash. This is specific for the PSoC1 implementation, PSoC3,4 and 5's C-compiler work differently.

   

 

   

Bob

0 Likes
ChDe_285186
Level 4
Level 4

 csprintf (s,%3d,BG) prints 3d on the LCD. Nothing else.

   

sprintf(s,%3d,ip) should print the value pointed to by ip into s with the format of up to 3 characters right justified leading zero's replaced with a space.

   

 

   

Nothing like what actually happens.

   

Regards

   

Chris D.

0 Likes
ChDe_285186
Level 4
Level 4

 sorry that should read csprintf(s,"%3d",BG)

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Using a modifyer (%3) requires a different library. See Dinesh's post here www.cypress.com/

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Dinesh's thread predates Imagecraft Pro release, makes one

   

wonder if the gyrations still needed as pointed out by thread.

   

 

   

Regards, Dana.

0 Likes
ChDe_285186
Level 4
Level 4

 Dinesh's post only used stdio.h. What different library did he call? 

   

When I used that format of csprintf as suggested by Bob the result was to print the "3d" characters on the LCD. Not what I wanted.

   

Has anyone actually done this on the 3210 eval kit?

   

Regards

   

Chris D

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I have an application that has done both integer, longs,

   

and floats, but used HiTech compiler.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Same for me, but uses ImageCraft compiler.

   

Did you already post your actual project here?

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

sprintf(s,%3d,ip) should print the value pointed to by ip into s with the format of up to 3 characters right justified leading zero's replaced with a space.

   

 

   

sprintf will take a numeric in ram and fill an array with the ascii string representation, using formatting parameter,

   

terminated with a NULL character. After you execute sprintf then you execute the LCD_PrString() on the buffer that

   

sprintf() filled.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Working example attached

   

 

   

Bob

0 Likes
ChDe_285186
Level 4
Level 4

 I loaded Bob's project. I also had to manually include PSoCAPI.h manually to Bob's library file because it was not included.

   

I have had to also add PRS.h?? and PWM.h?? before it would start the compiler.

   

Then the compiler produced the following error string

   

 

   
    Compiling...   
   
    creating project.mk    
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(14):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(14):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(15):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(15):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !E F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(15): undeclared identifier `PGA_HIGHPOWER'   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(16):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(16):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !E F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(16): undeclared identifier `ADC_HIGHPOWER'   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(25):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(25):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(28):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(28):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(29):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(29):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(31):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(31):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(32):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    !W F:\DOCUME~1\SOLARI~1\Cypress\ADCTest\PDPROJ~1\PDPROJ~1\main.c(32):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function    
   
    takes or returns values other than int   
   
    make: *** [obj/main.o] Error 1   
   
    main.o - 3 error(s) 16 warning(s)  09:31:25   
   
        
   
        
   
    I have had to add files to the library every time I create a new project.   
   
    Could the compiler file be corrupted?   
   
        
   
    Regards   
   
    Chris Devitt   
0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I compiled Bob's project under PSOC Designer 5.4 with no mods, and it completed error free.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This is the version info -

   

 

   

Imagecraft Compiler Standard V7.0.5
PSoC Designer Code Examples 5.4 - Build 2946 - 19-May-2013.10:14:46
PSoC Designer Content 5.4 CP1 - Build 3013 - 14-July-2014.07:37:02
PSoC Designer Core 5.4 - Build 2946 - 19-May-2013.10:14:46
PSoC Designer Documentation 5.4 CP1 - Build 3013 - 14-July-2014.07:37:02

   

 

   

Regards, Dana.

0 Likes
ChDe_285186
Level 4
Level 4

 My version is identical.

   

What now?

   

Chris D.

0 Likes
ChDe_285186
Level 4
Level 4

 Problem Solved!!!

   

I have added LCD_PrCString("   ") at the same position on the LCD as the LCD_Prstring command thus,

   

 

   
     itoa(ip,pos,10);   
   
     //format the ascii string pct to 3 characters, right justified stored in pnt//   
   
     sprintf(s,ip,"% 3d");   
   
     //Print contents of pnt to the LCD at this position//   
   
     LCD_Position(1,12);   
   
     LCD_PrString(pnt);   
   
     //Print the tens interger stored in first at this position//   
   
     LCD_Position(1,3);   
   
     LCD_PrHexByte(first);   
   
     //Print the units interger stored in second at this position//   
   
     LCD_Position(1,5);   
   
     LCD_PrHexByte(second);   
   
        
   
     //Draw Bargraph line 0 position 0//   
   
     LCD_DrawBG(0,0,16,BG);   
   
     LCD_Position(1,12);   
   
     LCD_PrCString("   ");   
   
        
   
    Now the LCD reads correctly for 1, 2, and 3 interger numbers.   
   
    Still cannot figure out why Bob's project would not compile. I will investigate further.   
   
        
   
    Regards   
   
        
   
    Chris D   
0 Likes
Anonymous
Not applicable
    //format the ascii string pct to 3 characters, right justified stored in pnt//   
   
    sprintf(s,ip,"% 3d");   
   

is this correct?

0 Likes
ChDe_285186
Level 4
Level 4

 Yes, Thats correct as well as fill leading zero's with a blank character-- BUT-- it does NOT right justify. The number 5 is printed as 500 and the number 50 is also printed as 500 once the display has displayed 100. When the program is reinitilised the display reads 50 (127 is 50% of 255) if the bargraph is reduced to 3% the display reads30. If I increase the display to 100% then back to 50% the display teads 500 and maintains the 3 character format.

   

Using LCD_PrCstringF("   "); at the position of the character print on the LCD fixes the problem. The single digit numbers print as a single digit ie 5% displays 5  even if I run up to 100% and back to 5%.

   

As for your other suggestions re the debounce, it is not required as the inputs come from a digital source.

   

The other suggestions re if-then-else loops, in my humble opinion, makes the program harder to follow.

   

Regards

   

Chris D

0 Likes
Anonymous
Not applicable

Should the 2nd argument be the formatting, and the third one be the number to print?

0 Likes
Anonymous
Not applicable
    I am a bit confused:   
   
        
   
    your program.   
   
        
   
    itoa(ip,pos,10);   
   
    //format the ascii string pct to 3 characters, right justified stored in pnt//   
   
    sprintf(s,ip,"% 3d");   
   
        
   
    itoa already convert the value of pos to a ASCII string in in pct[], what is the purpose of the sprintf? Would this be the reason you still getting the wrong display?   
   
        
   
        
0 Likes
Anonymous
Not applicable

BTW can someone tell me where I can find documentation about that csprintf()? Tks

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

In the presented code-snippets are some ambiguities as coding, parameter order, variable declarations, It would clear many questions and shoten the discussiond when we can get an actual project archive.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given
     itoa(ip,pos,10);   
   
     //format the ascii string pct to 3 characters, right justified stored in pnt//   
   
     sprintf(s,ip,"% 3d");   
   
        
   
    This typing negates the usefulness of the itoa() call. sprintf() will overwrite   
   
    the buffer with its solution.   
   
        
   
    Regards, Dana.   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

And of course it should read

   

 

   

char s[17];

   

int ip;

   

csprintf(s,"%3d",ip);

   

LCD_PrString(s);

   

 

   

Mark the parameter order: csprintf(char*Buffer,"FormatString",Var1,Var2,...)

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Useful reference -

   

 

   

    

   

          http://www.cypress.com/?id=4&rID=43630

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 @Dana, thanks for the link. But there is mainly fo5 the cprintf rsther than csprintf. Any way, I read the header files in the designer project, and kown a bit more about these special library funtions. 

0 Likes
Anonymous
Not applicable

 @Bodb. I think the same too.

0 Likes