Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 25, 2024, 04:58:42 04:58


Login with username, password and session length


Pages: [1]
Print
Author Topic: How convert HEX to DEC ?  (Read 17295 times)
0 Members and 1 Guest are viewing this topic.
tsupuntu
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 0
-Receive: 1


« on: April 23, 2005, 12:41:19 00:41 »

How convert HEX to DEC ?
EX.. I want convert 0x1a to 26 , 0x0a to 10 then I will send to Sevent segment........Thank
Logged
nimdonia
Newbie
*
Offline Offline

Posts: 19

Thank You
-Given: 3
-Receive: 1


« Reply #1 on: April 23, 2005, 03:05:46 03:05 »

use a scientific calculator and use the BASE.. 0x1a is 1A (hex) just forget bout the 0x
....
Logged
gezgin
Guest
« Reply #2 on: April 23, 2005, 03:42:03 15:42 »

char Dec2Hex(char ch)
{
   if (ch<10) return ch;
   if (ch<20) return ch+6;
   if (ch<30) return ch+12;
   if (ch<40) return ch+18;
   if (ch<50) return ch+24;
   if (ch<60) return ch+30;
   if (ch<70) return ch+36;
   if (ch<80) return ch+42;
   if (ch<90) return ch+48;
   if (ch<100) return ch+54;
}

char Hex2Dec(char ch)
{
   if (ch<0x10) return ch;
   if (ch<0x20) return ch-6;
   if (ch<0x30) return ch-12;
   if (ch<0x40) return ch-18;
   if (ch<0x50) return ch-24;
   if (ch<0x60) return ch-30;
   if (ch<0x70) return ch-36;
   if (ch<0x80) return ch-42;
   if (ch<0x90) return ch-48;
   if (ch<0x100) return ch-54; else return 99;
   
}
 Smiley http://www.sonsivri.com/forum/newreply.php?do=newreply&noquote=1&p=352#
Logged
kathir
Junior Member
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 1
-Receive: 7


« Reply #3 on: April 23, 2005, 04:04:34 16:04 »

this is hex to bin   routine

void Bin (int hex, int bin[], Cool //changes bytes to bits
{
 int i;
 for (i=0; i < bit; i++)
 {
  if (hex%2) bin = 1; else bin = 0;
  hex = hex/2;

 }
Logged
tsupuntu
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 0
-Receive: 1


« Reply #4 on: April 24, 2005, 12:34:04 00:34 »

Big thank
Logged
tsupuntu
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 0
-Receive: 1


« Reply #5 on: April 24, 2005, 12:54:04 00:54 »

Thank for all reply but not work.  
I make counter count to "0x0A"on sevent segment It show "10" or count to "0xff" on sevent segment show "256" or count to "0xffff"  on seventsegment show "65535" so must convert hex to dec and then send to digit control
Logged
leemarrow
Newbie
*
Offline Offline

Posts: 32

Thank You
-Given: 328
-Receive: 52


« Reply #6 on: April 27, 2005, 01:10:10 13:10 »

Quote from: tsupuntu
Thank for all reply but not work.  
I make counter count to "0x0A"on sevent segment It show "10" or count to "0xff" on sevent segment show "256" or count to "0xffff"  on seventsegment show "65535" so must convert hex to dec and then send to digit control


what's language you need? ASM, PICBASIC, C?
Logged
tsupuntu
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 0
-Receive: 1


« Reply #7 on: April 29, 2005, 07:14:37 19:14 »

Yea!!! Now it work  it change hex 16 bit to Dec and show to Sevensegment
Now 4 digit but it improve to 10 digit
=========================================


#include <16F628A.h>
//#include
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, NOBROWNOUT, NOMCLR, LVP, NOCPD
#byte VRCON = 0x9f
#byte TRISB = 0x86
#byte TRISA = 0x85
#byte CMCON = 0x1f
#byte INTCON = 0x0b
#byte OPTION_REG = 0x81
#byte A = 0x05
#byte B = 0x06
   //#bit inputalarm =   B.1
   //#bit sensor2=   B.2
   //#bit int0=   B.0
   //#bit sensor3 =   B.3
   #bit d0=   A.0
   #bit d1 =   A.1
   //#bit centrallock2= B.7
   #bit d2 =   A.2
   #bit d3 =   A.3
//#define lt 2
//#define cen1 1
//#define cen2 7
//#define sys 3
//#define al 0
//#define in 0
//#define sen1 2
//#define sen2 3
int32 i,buf,div1;
int16 hde,key;
int j,k,seg1,div2,seg0,seg2,seg3,seg4,seg5,seg6,seg7,seg8,seg9,m;
void div(){
div1=buf/m;
div2=buf-(m*div1);
}

void hextodec(){
seg0=0;
seg1=0;
seg2=0;
seg3=0;
seg5=0;
seg4=0;
seg6=0;
seg7=0;
seg8=0;
seg9=0;
buf=i;
m=0x0a;
j=0;
while(buf>0x00){

div();
buf=div1;
if(j==0){seg0=div2;}
if(j==1){seg1=div2;}
if(j==2){seg2=div2;}
if(j==3){seg3=div2;}
if(j==4){seg4=div2;}
if(j==5){seg5=div2;}
if(j==6){seg6=div2;}
if(j==7){seg7=div2;}
if(j==8){seg8=div2;}
if(j==9){seg9=div2;}
j=j+1;
}
}

void segmentconv(){
// 0    1    2    3    4    5    6    7    8    9    a    b    c    d    e    f
byte const segmentdata[16] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
key=segmentdata[key];
}
void main()
{
#ASM
   movlw   0x01
   movlw   0x00
   movwf   TRISB
   movlw   0xf0
   movwf   TRISA
   clrf   VRCON
   movlw   0x00
   movwf   INTCON
   bcf   INTCON,1
   movlw   0x07
   movwf   CMCON
   movlw   0xcd
   movwf   OPTION_REG

#ENDASM
//***+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//waitforstart();
i=0x00000000;
start:
//delay_ms(1000);
hde=0x0000;

hextodec();

key=seg0;
segmentconv();
output_b(key);
bit_set(A,0);
delay_us(12);
bit_clear(A,0);


key=seg1;
segmentconv();
output_b(key);
bit_set(A,1);
delay_us(12);
bit_clear(A,1);


key=seg2;
segmentconv();

output_b(key);
bit_set(A,2);
delay_us(12);
bit_clear(A,2);


key=seg3;
segmentconv();

output_b(key);
bit_set(A,3);
delay_us(12);
bit_clear(A,3);
//bit_set(A,1);
//output_b(key);
//bit_set(A,2);
//output_b(key);
//bit_set(A,3);
//output_b(key);
i=i+0x00000001;
//if (i==0x0a){
//i=0;
//}
goto start;

}
Logged
BobBlick
Guest
« Reply #8 on: January 08, 2006, 01:47:07 13:47 »

http://www.edaboard.com/ftopic147107.html
Logged
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2429

Thank You
-Given: 405
-Receive: 545


Uhm? where did pickit put my mute button


« Reply #9 on: January 08, 2006, 02:27:33 14:27 »

Use this calculator
Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
lillbear
Senior Member
****
Offline Offline

Posts: 276

Thank You
-Given: 223
-Receive: 182



« Reply #10 on: March 23, 2006, 07:19:04 19:19 »

Newbie Thanks you Smiley
Logged
Den4o
Junior Member
**
Offline Offline

Posts: 39

Thank You
-Given: 950
-Receive: 2


« Reply #11 on: March 23, 2006, 08:34:51 20:34 »

Thank you, bbarney
Logged
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #12 on: March 31, 2006, 10:33:45 22:33 »

HEX to DEC
 
void lcd_display(int16 value){
char ch; //curent char
ch = (value / 1000); //thousands
lcd_putc(0x30 + ch); //make an ASCII char and display to LCD
ch = (value / 100) % 10;
lcd_putc(0x30 + ch);
lcd_putc('.');
ch = (value / 10) % 10;
lcd_putc(0x30 + ch);
ch = value % 10;
lcd_putc(0x30 +ch);
lcd_putc(0b11011111);//degree simbol
}
 
I display on a LCD a HEX value of 4 digits(DEC).
FF -> becomes 2 5 5
but another way... a more simple way(takes longer CPU time) is using %d argument of printf function. Take a look at CCS help.
You can printf to a function not only to RS232.
« Last Edit: March 31, 2006, 10:36:09 22:36 by tavioman » Logged

- Brain juice -
burakgurer
Guest
« Reply #13 on: May 19, 2006, 11:48:59 23:48 »

void bcd()
{
    for(;; )
   {
      temp = count - 1000;
      if(temp<0)
      {break;}
      ++digit[4];
      count = temp;
   }
   for(;; )
   {
      temp = count - 100;
      if(temp<0)
      {break;}
       ++digit[3];
       count = temp;
   }
   for(;; )
   {
      temp = count - 10;
      if(temp<0)
      {break;}
      ++digit[2];
      count = temp;
   }
   digit[1] = count;    
}

//for 7 segment
« Last Edit: May 19, 2006, 11:53:15 23:53 by burakgurer » Logged
aslan_korhan
Active Member
***
Offline Offline

Posts: 147

Thank You
-Given: 1
-Receive: 60



WWW
« Reply #14 on: May 20, 2006, 01:48:37 01:48 »

program to convert
http://www.sonsivri.com/forum/showthread.php?t=1311
Logged
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #15 on: May 20, 2006, 12:04:16 12:04 »

He needs a C snippet for converting inside the MCU.
Logged

- Brain juice -
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC