Hex values to decimal


Results 1 to 14 of 14

Threaded View

  1. #8


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Hi All,
    How to convert a HEX value to DEC value. For example: Var mai = $2B and I want to store the decimal value of this (which is 43 in decimal) in other variable.
    On LCD is all ok, shows the right dec value, but how to store this in decimal in other variable that's my problem.
    I do some search on the forum but no success. Can me to someone explain how to do?

    Thanks.

    Code:
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
     __CONFIG cfg
    #ENDCONFIG
    
    DEFINE OSC 8      ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_BAUD 38400
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    define LCD_RSBIT 4
    define LCD_EREG PORTC 
    define LCD_EBIT 5 
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ANSELH = 0        ; Set RB6 (TX) pin to digital
    ANSEL = 0         ; Set all digital
    TRISA = %011100   ; Set RA5,RA4,RA3 input ; RA2,RA1,RA0 output
    TRISB = %0011     ; Set RB4,RB5 input ; RB6,RB7 output
    TRISC = %00000000 ; Set RC0,RC3,RC4,RC5,RC6, RC1,RC2,RC7 output
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2
    OPTION_REG.7=1   ; Disable weak pull ups
    
    mai var byte[2]
    decvalue var byte
    Lcdout $fe, 1
    pause 1000
    
    main:
    hserout ["01 05",13,10]
    pauseus 1                   
    HSerin 1000,main, [wait ("41 05"), skip 1, hex mai]  
     
    Lcdout $fe, 1
    lcdout  dec mai
    
    let decvalue = mai 
    
    pause 1000
    
    goto main
    Last edited by louislouis; - 2nd January 2017 at 21:07.

Similar Threads

  1. Hex to Decimal to Binary
    By Ramius in forum FAQ - Frequently Asked Questions
    Replies: 3
    Last Post: - 28th March 2014, 02:01
  2. Decimal PWM Cycle values?
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2012, 13:58
  3. Hex to Ascii to Decimal
    By khoog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st July 2009, 06:27
  4. Convert Hex to Decimal
    By RONKON in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th May 2006, 02:01
  5. Decimal values from string
    By GioppY in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th November 2005, 22:10

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts