Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > LCD to display decimal number

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



LCD to display decimal number
Moderator:
ANCY

Post Reply
Follow this topic



LCD to display decimal number

Swee Huei posted on 08 Mar 2012 1:13 AM PST
Top Contributor
33 Forum Posts

I am currently using the PSoC 5 development kit (CY8CKIT-050).

I am unable to display decimal number on the LCD, and can only display integer value.

For example, I want to display 75.92 on the LCD. Presently I can only display 75.

How do I display the decimal after the number 75?

Thanks




Re: LCD to display decimal number

H L posted on 08 Mar 2012 02:11 AM PST
Top Contributor
679 Forum Posts

 How about upload the project so others can see what is wrong.



Re: LCD to display decimal number

Gautam Das posted on 08 Mar 2012 03:01 AM PST
Cypress Employee
742 Forum Posts

Hi Swee Huei,

 

If you intend to display digits after decimal points, then you need to declare an array and use sprintf function to convert floating point number into an array of characters.

Then you can use the character LCD APIs to print the number on LCD.



Re: LCD to display decimal number

Swee Huei posted on 08 Mar 2012 05:33 PM PST
Top Contributor
33 Forum Posts

Below is the extract of the code. Basically I want to display the PWM duty cycle in decimal on the LCD display.

Please kindly advise what went wrong, if possible. Thanks a lot.

#include

<device.h>

#include

<stdio.h>

void

main()float Period1; float Compare1;float duty1;float duty1str;float Period2;float Compare2;float duty2;char dtuy2str;/* Prepare components */

clock_1_Enable();

CharLCD_1_Start();

PWM_1_Start();

PWM_2_Start();

 

/* Write a byte to a Control Register */

Control_Reg_1_Write(0x00);

 

/* Read the current value assigned to a Control Register */

Control_Reg_1_Read();

 

/* Read the current value assigned to Status Register */

Status_Reg_1_Read();

 

 

Period1 = PWM_1_ReadPeriod();

Compare1 = PWM_1_ReadCompare();

duty1 = (Period1 - Compare1) / Period1 *100;

Period2 = PWM_2_ReadPeriod();

Compare2 = PWM_2_ReadCompare();

duty2 = (Period2 - Compare2) / Period2 *100;

 

 

/* Display current Period, Compare value, status of PWM output */

CharLCD_1_Position(0,0);

CharLCD_1_PrintString(

CharLCD_1_Position(0,10);

"PWM1 DUTY");

CharLCD_1_PrintNumber(duty1);

 

CharLCD_1_Position(1,0);

CharLCD_1_PrintString(

CharLCD_1_Position(1,10);

"PWM2 DUTY");

CharLCD_1_PrintNumber(duty2);

 

CharLCD_1_Position(1,13);

CharLCD_1_PrintString(

 

"%");

}

/* [] END OF FILE */

{

 

 

 

 

 

 

 

 

 

 



Re: LCD to display decimal number

Swee Huei posted on 08 Mar 2012 05:34 PM PST
Top Contributor
33 Forum Posts

Dear dasg,

Thanks for your suggestion. I will try.



Re: LCD to display decimal number

Gautam Das posted on 08 Mar 2012 08:48 PM PST
Cypress Employee
742 Forum Posts

Hi Swee Huei,

 

Looking at your code, the following areas can be looked into:

 

1) The Period1, Compare1, Period2 and Compare2 can be declared as unsigned integer of 8 or 16 bits (uint8 or uint16) depending upon the resolution of the PWM components used.

2) The variable which holds the duty cycle value, duty1 and duty2 can then be typecasted to float while computation.

3) Duty cycle computation depends upon the Compare type. If you are using Compare type of "Less", then duty cycle will be (Compare / (Period + 1)) * 100

4) Instead of printing the duty1 and duty2 directly, you need to first convert the floating point number into an array which can then be printed on LCD. For this you can use sprintf function as shown below:

 

duty1_string[6];

char

"%2.2f", duty1);/* Floating point number is converted to decimal point format for display */

sprintf(duty1_string,

CharLCD_1_PrintString(duty1_string);

 

Let us know if this works.



Re: LCD to display decimal number

Gautam Das posted on 08 Mar 2012 08:54 PM PST
Cypress Employee
742 Forum Posts

Oops! looks like the code got mangled.

Rewriting the code below:

 

char duty1_string[6];

sprintf (duty1_string, "%2.2f", duty1); /* Floating point number is converted to decimal point format for display */

CharLCD_1_PrintString(duty1_string);

 

 



Re: LCD to display decimal number

Swee Huei posted on 11 Mar 2012 05:32 PM PST
Top Contributor
33 Forum Posts

Dear dasg,

Thanks a lot for your help. I tried your suggestion, and it works.

Regards



Re: LCD to display decimal number

occupy posted on 28 Sep 2012 03:22 PM PST
Top Contributor
61 Forum Posts

thanks the upstairs

 learned  a  lot,

thanks!






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20