Thread: Displaying Values...

  1. #16
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    yes... ok...
    hope to hear from u again soon!
    thanks a lot!!!

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, this is the C program, but now we need to see about using it's guts, with your display.

    Run this on your pc, and see if it does what you want, first.

    Code:
    #include <stdio.h>
    
    int main() {
      
      unsigned char digit, snum[4];
      int i, n, j;
      int num[] = {3,14,159,26,53,155,218,91,79,66};                    
      snum[3] = '\0';            //this must stay, and never change value
    
      for(i = 0; i < sizeof(num)/sizeof(int); ++i) {   //for each number
        for(j = 0; j < 3; j++)         //reset the string array
          snum[j] = 32;                //fill 3 elements with blank spaces                
        n = num[i];
        j = 2;
        while(n) {                     //strip off each digit from n
          digit = n % 10;
          n /= 10;                     
          snum[j] = digit + '0';       //assign digit's string value to snum
          --j;
        }
        printf("Original Number: %d  String Digits: %s\n", num[i], snum);   
        getchar();
      }
      
      printf("\n\n\t\t\t     press enter when ready");
      i = getchar();
      return 0;
    }

  3. #18
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    thanks for the reply..
    but my display will not be able do printf... it print value only by ascii value.

    Currently what im able to do to the display is to:

    1.) display 1 character. the ADC value in ascii format.. e.g. when i adjust the adc value to 114, the display shows 1 character 'r'(but what i want is to show 3 character '1''1''4', which is '49''49''52' in ascii).
    Code:
    op=ADC0H;
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char op, char ter);
    OLED_String(0x73,col,row,font,color5,color6,op,ter);
    2.) display 3 character.. but is hard coded.
    Code:
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char char1, char char2, char char3, char ter);
    char1 = 49;
    char2 = 49;
    char3 = 52;
    OLED_String(0x73,col,row,font,color5,color6,char1,char2,char3,ter);
    so now i need to find out how do i change the ADC value from integer to string to ascii?
    e.g.when ADC value ='114' how do i change to '1''1''4' then to '49''49''52'
    so i can put them into char1,char2,char3.

    sry if i cant explain well.
    pls help~~..
    Thank you......

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The problem is solved, it just has to be integrated into your program, my good Dr. Watson.

    Some experimentation will be necessary, since I don't have your setup to work with.


    Something like this, for the device:
    Code:
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char char1, char char2, char char3, char ter);
    char1 = 49;
    char2 = 49;
    char3 = 52;
    OLED_String(0x73,col,row,font,color5,color6,char1,char2,char3,ter);
    
    
    Now we change that to:
    
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char char1, char char2, char char3, char ter);
    char1 = snum[0];
    char2 = snum[1];
    char3 = snum[2];
    char4 = '\0';
    OLED_String(0x73,col,row,font,color5,color6,char1,char2,char3,char4,ter);
    (but what i want is to show 3 character '1''1''4', which is '49''49''52' in ascii).
    My program does that, by adding '0' to the number - ascii 48.

    1+48 = 49, 4+48= 52.

    Sweet, yes?

  5. #20
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    ok... i'll try it out thee few days...

    but there's a line i dun quite understand..
    Code:
    int num[] = {3,14,159,26,53,155,218,91,79,66};
    can u explain to me this line??
    thx alot....

    thank you so much for all ur reply...

    ok.. i'll be back in bout 2 days. thank you!!

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Those were just testing numbers. Your program won't need them, at all.

  7. #22
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    oic..... thank you so much........... enjoy ur weekends!! =)
    see ya again!

  8. #23
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You too.

  9. #24
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    hi...
    i've tried the code.. but its not working right..
    currently my ADC value (op) work fine.. it changes as i adjust the signal.
    but my char1, char2, char3 all equal to 32 ('blank')..
    The following are part of my code.
    Code:
    unsigned char digit, snum[4];
    int j, k, l;
    int num[] = {3,14,159,26,53,155,218,91,79,66}; 
    
    void main()
    {
    
    	Init_Device();
    	TI=0;
    	RI=0;
    	x=1;
    	//qqq=0;
    	//aaa=0;
    
    	SendChar(GSGC_AUTOBAUD);
    	Receive();
    	SendChar(GSGC_CLS);
    	Receive();
    	convert_all();
    	DisplayAD();
    	DisplayLine();
    	rectangle();
    	delay(3);
    	DisplayCircle();
    
    	ADBUSY = 1;//start a conversion
    
    	while(1)
    	{		
    		if (ADBUSY == 0)//wait until conversion is complete
    		{
    			op=ADC0H;
    
     			 for(j = 0; j < sizeof(num)/sizeof(int); ++j) 
     			 {   //for each number
     			   for(l = 0; l < 3; l++)         //reset the string array
      			    snum[l] = 32;         //fill 3 elements with blank spaces                
      			  k = num[j];
      			  l = 2;
      			  while(k) 
    				{                     //strip off each digit from n
       			   digit = k % 10;
       			   k /= 10;                     
       			   snum[j] = digit + '0';       //assign digit's string value to snum
       			   --l;
       			 }
    
      			}
    
    				char1 = snum[0];
    				char2 = snum[1];
    				char3 = snum[2];
    
    
    			ADBUSY = 1;//start another conversion
    		}
    		
    	}
    	
    }

  10. #25
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Never mind.. i got it using another simple method.. thanks for ur help!!! =)
    Code:
    void hundred()		/*convert 1st value Axx*/
    {
    	opvalue_h = opvalue_h/100;
    	t = opvalue_h+48;
    }
    void ten()			/*convert 2nd value xAx*/
    {
    	opvalue_t = opvalue_t/10;		
    	opvalue_t = opvalue_t%10;
    	u = opvalue_t+48;
    }
    void one()			/*convert 3rd value	xxA.*/
    {
    	opvalue_o = opvalue_o%10;
    	v = opvalue_o+48;
    }
    
    void OLED_StringTop(char cmd, char col, char row, char font, char color5, char color6, char t, char u, char v, char ter)

  11. #26
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is better to use '0' than 48 since it is more readable (and more portable, though that is not really a concern, I suppose).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #27
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Yes.. agreed.. changed.. Thanks!!

    Now i have need another help again..
    I need to display the same ADC dec value in Hex.. using ascii...

    e.g. dec value = '123' i need to display '7''B'. so i need to store a value '55' to r and '66' to s

    Code:
    void OLED_StringBottom(char cmd, char col2, char row2, char font2, char color7, char color8, char r, char s, char ter);

  13. #28
    Registered User
    Join Date
    Jan 2010
    Posts
    25

    Question

    ok.. im done with the hex...

    now i need to convert the ADC dec value back to analog value.
    eg.. if i input 3v>> ADC value = 255, analog value = 3.0
    if i input 1.5v>> ADC value = ~127, analog value = 1.5
    (currenly im already able to get the ADC value)

    now i need help getting the analog value to be display....
    pls help me with the code..

    THANKS!!!

  14. #29
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Tell me if this is correct:

    Code:
    /* for Vailant's heart monitor */
    
    #include <stdio.h>
    
    int main() {
      int adc, n;
      float analog;
    
      printf("\n\nEnter an ADC value:" );
      scanf("%d", &adc);
      n = (adc % 50);
      adc += (50 - n);
      analog = 1.0 * adc;
      analog = adc/100.0;
      printf("\n ADC value is: %.1f", analog);
    
      while((n = getchar()) != '\n');
      n = getchar();
      return 0;
    }
    If that's correct, then we can adapt that logic, into something that will run on your monitor.
    Last edited by Adak; 01-20-2010 at 08:12 AM.

  15. #30
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Hi Adak.
    my display wont be able to do the printf function...
    so i need to print a character by a character.
    e.g. (3.0>>> '3' & '.' & '0')

    im able to get the dot('.') now by printing dec (46).... and when i input a 3v singnal im already able to get the value 255...

    so now what i need is to get two integer
    e.g. '3' & '0' when i input a 255,
    '1' & '5' when i input a 127 or 128. ect...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying Minimum and Maximum values from input
    By mgardnertech in forum C Programming
    Replies: 1
    Last Post: 06-29-2008, 08:47 PM
  2. Storing values from Edit Box into an array
    By E_I_S in forum C++ Programming
    Replies: 10
    Last Post: 06-05-2008, 06:24 AM
  3. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-21-2008, 11:18 PM
  4. Displaying numerical values in a window
    By drb2k2 in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2003, 12:05 PM
  5. unsigned char vs signed char and range of values
    By Silvercord in forum C++ Programming
    Replies: 5
    Last Post: 01-22-2003, 01:30 PM