Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > Decode Hex in Dec

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



Decode Hex in Dec
Moderator:
ARVI

Post Reply
Follow this topic



Decode Hex in Dec

badalgazi posted on 23 Mar 2012 12:53 PM PST
Member
3 Forum Posts

 

Hello, 

im from Germany and i begin with the Posoc board eval1 for a week. 

I need help, cant find any code to decode hex in dec

I´ll show my data on my lcd, but i cant

 

Thanks for help

 

 




Re: Decode Hex in Dec

Bob Marlowe posted on 23 Mar 2012 01:44 PM PST
Top Contributor
1768 Forum Posts

Welcome in the fscinating world of PSoCs!

If it is too difficult for you to calculate Hex to dec, let the C-Compiler do the job:

char Buffer[9];

csprintf(Buffer,"%d",YourValue);

LCD_Position(0,0);

LCD_PrString(Buffer);

 

That will do the thing.

Happy coding

Bob

PS: It is rather late in Germany now...



Re: Decode Hex in Dec

posted on 23 Mar 2012 02:23 PM PST
Member
9 Forum Posts

How big of a number are you tring to convert. Signed or Unsigned?  Real of integer.

I ways like the mod function  Assume unsignded int

Digit1 =  VariableInHex % 10
VariableInHex /=10;
Digit10 =  VariableInHex % 10
VariableInHex /=10;
Digit100 =  VariableInHex % 10
VariableInHex /=10;
Digit1 =  VariableInHex % 10
VariableInHex /=10;

Put the digitd in an Array and make a loop 

Int Digit[6];  //assuming 999,999 is large enough

for( i = 0 ; i<6; 1++){
    Digit[i] =   VariableInHex % 10
   VariableInHex /=10;
}

If you wanted a string the add an array of O 1 2 3 4 5 6 7 8 9   and have the moded value point to the correct character

 

 

Thanks



Re: Decode Hex in Dec

badalgazi posted on 23 Mar 2012 04:20 PM PST
Member
3 Forum Posts

 Hello, 

thanks for the support ;)

but it not works they give errors

here my code

 

#include <m8c.h>        // part specific constants and macros

#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

#include "_const.h"

#include "stdarg.h"

#include "limits.h"

#define __STDLIB_H

 

void main(void)

{

  

   

   LCD_Start();

   M8C_EnableGInt ;                            // Turn on interrupts 

   SleepTimer_Start();

   SleepTimer_SetInterval(SleepTimer_64_HZ);   // Set interrupt to a

   SleepTimer_EnableInt();                     // 64 Hz rate

 

 

    unsigned char Buffer[9];

int i=0x7f;

csprintf(Buffer,"%d",i);

    SleepTimer_SyncWait(64, SleepTimer_WAIT_RELOAD);

LCD_Position(0,0);

    LCD_PrString(Buffer);

 

 



Re: Decode Hex in Dec

badalgazi posted on 23 Mar 2012 04:22 PM PST
Member
3 Forum Posts

 Here the error code

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(23): illegal statement termination

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(23): skipping `unsigned' `char'

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(23): undeclared identifier `Buffer'

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(23): type error: pointer expected

!W C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(23):[warning] expression with no effect elided

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(24): illegal statement termination

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(24): skipping `int'

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(24): undeclared identifier `i'

!W C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(26):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function 

takes or returns values other than int

!W C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(26):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function 

takes or returns values other than int

!E C:\Users\BA\DOCUME~1\PSOCDE~1.2PR\Gara\Gara\main.c(29): type error in argument 1 to `LCD_PrString'; found `int' expected `pointer to char'

C:\PROGRA~2\Cypress\PSOCDE~1\5.2\Common\CY110F~1\tools\make: *** [obj/main.o] Error 1



Re: Decode Hex in Dec

Bob Marlowe posted on 24 Mar 2012 02:12 AM PST
Top Contributor
1768 Forum Posts

You ougth to use the right location for your variable-definitions: i and Buffer may not be declared within your program, that is not tolerated by C.

and you have to

#include <stdio.h>

and delete that #define __std.. etc it will conflict with compiler-internals

Have a C-manual at hand http://publications.gbdirect.co.uk/c_book/ it will help you with ANY questions concerning C

 

Bob



Re: Decode Hex in Dec

Bob Marlowe posted on 24 Mar 2012 02:19 AM PST
Top Contributor
1768 Forum Posts

Oh, yes, I just see....

You are in the world of embedded microcontrollers now. They are built to run as long as there is power applied. so, your program just starts, does its job and then ends. What does "ends" mean in this context? The Program will start all over again!

so put (where your #defines should go to)

#define forever 1

and where you want to do the main-job (not the initializations, they are done only once)

while (forever)

{

   // This is the main-loop that runs all the time

}

 

 

Happy coding

Bob






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