Decode Hex in Dec

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

cross mob
Anonymous
Not applicable

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

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

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...

View solution in original post

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

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...

0 Likes
Anonymous
Not applicable

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 =   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

0 Likes
Anonymous
Not applicable

 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);

   

 

   

 

   

0 Likes
Anonymous
Not applicable

 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

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

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

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

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

0 Likes