Thread: Not getting the actual output while displaying hex numbers in decimal format

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Not getting the actual output while displaying hex numbers in decimal format

    I need to display 0-15 hex numbers[0X00-0x0F] in decimal value...& I'm getting the output but it's not exactly what it should be,below is my code..
    [This not the complete code,but main part where the changes are done]

    Actual output i should get is for 1v it should generate 0001,for 2v it should generate 0010 and simultenously till [15v-1111]...
    But what i'm getting is exactly different to this for eg for 7v,8v&9v the bits generated are 1101,1011,1011 respectively...
    Please anyone help me in resolving this.. http://img.codecall.net/public/style...001_unsure.gif
    Code:
    :
    
    
    Code:
    sbit V1 = P2^0; 
    sbit V2 = P2^2;
    sbit V3 = P2^4;
    sbit V4 = P2^6;
    #define DAC_table  V1,V2,V3,V4
    
    #include <stdio.h> 
    #include <string.h> 
    idata unsigned int ptr2tbl ; 
    
    void fnSelectAmplitude(void)   
    { 
    unsigned char DAC_table[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};//tell me if I have done wrong here 
    ptr2tbl == &DAC_table[16]; //is this correct I have used equal to'==' instead of assignment operator   
    line_display(1, "Amp Sel"); 
    sprintf(line_buf," %03d V",(unsigned int)ptr2tbl);
     line_display(2, line_buf); 
    while(START_KEY)
     { 
    if(!UP_KEY) 
    {
     for(i=0;i<15;i++) 
    { 
    P2 = ptr2tbl++; 
    } 
    }
     else if(!DOWN_KEY) 
    {  
     P2 = ptr2tbl--; 
    }
     else 
    { 
    ++wait_for_any_key_counter_0; 
    if(wait_for_any_key_counter_0 >= 240) //120 to 240; Any Key not Pressed Delay is 120 * 75ms break;
     } 
    delay_ms(75);  // Debounce Delay 
    sprintf(line_buf," %03d  V", (unsigned int)ptr2tbl);
     }
    delay_ms(500);  // Screen Change Delay 
    } 
    
    main()
     { 
    P2 = 0; 
    ptr2tbl = DAC_table; //i think here i'm doing wrong if i'll assign to address(&) operator i'm getting error 
    while(1) 
    { 
    disable_timer0(); 
    }

    Last edited by angiey; 04-26-2013 at 04:42 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,458
    What exactly are you trying to accomplish with the following line?
    Code:
    #define DAC_table  V1,V2,V3,V4
    A couple of questions about the following line:
    Code:
    sprintf(line_buf," %03d V",(unsigned int)ptr2tbl);
    Why the cast? ptr2tbl is already an unsigned int. the "%d" format specifier is used for a signed int, not an unsigned int. You may want to view the documentation for the printf() family of functions and select the proper format specifier.

    Code:
    ptr2tbl == &DAC_table[16]; //is this correct I have used equal to'==' instead of assignment operator   
    line_display(1, "Amp Sel");
    To answer the question in your comment, no this line is not correct, it's not actually doing anything. What are you actually trying to accomplish with this line?

    You also must find and use an indentation style you like. This will make your program much easier to read.

    JIm

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    1,646
    Like jimblumberg, I don't understand what you're trying to accomplish with #define of DAC_table V1,V2,V3,V4.

    If you want to display values 0 through 15 as a string "0000" through "1111", you could use an array of 16 strings of 4 characters each, or an array of 16 integers with the decimal values 0, 1, 10, 11, 100, ..., 1110, 1111, and print out the integers with "%04d". The user won't know or care what your program is doing internally to display 4 bit values as 4 character string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-13-2012, 07:50 PM
  2. Replies: 15
    Last Post: 10-28-2006, 04:30 AM
  3. format numbers output?
    By DanC in forum C++ Programming
    Replies: 4
    Last Post: 03-09-2006, 06:54 AM
  4. My program is displaying.....actual hearts
    By Wiretron in forum C Programming
    Replies: 3
    Last Post: 11-09-2005, 11:41 AM
  5. Displaying pointer's actual values in inheritance
    By Poof in forum C++ Programming
    Replies: 14
    Last Post: 07-29-2004, 07:34 AM

Tags for this Thread