Displaying Values...

This is a discussion on Displaying Values... within the C Programming forums, part of the General Programming Boards category; Hi all, Im now doing a project using Silicon Lab C8051F226 in C language.. and the display is a external ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    25

    Unhappy Displaying Values...

    Hi all,
    Im now doing a project using Silicon Lab C8051F226 in C language.. and the display is a external uOLED-96-G1..
    I have did some coding and now its able to do the ADC.
    lets say now i got the ADC value as '49'
    the display i get is '1'. (because '49'dec='1'acii)
    So how do i do to make the value to display '49'?
    I had paste my coding bellow. pls help with the coding.
    Thank you.

    Code:
    /////////////////////////////////////
    //  Generated Initialization File  //
    /////////////////////////////////////
    
    #include "C8051F200.h"
    #include "GSGCdef.h"
    
    //#include "dos.h"
    //#include "conio.h"
    // Peripheral specific initialization functions,
    // Called from the Init_Device() function
    
    sbit LED=P2^4;
    sbit SWITCH=P2^5;
    int ttt[10];
    int qqq;
    int aaa;
    int x=1;
    unsigned char d_receive;
    unsigned char Receive();
    void SendChar(unsigned char b);
    void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2);
    void OLED_DrawCircle(char cmd ,int x3, int y3, int radius, int color3,int color4);
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char adc, char ter);
    void delay(int value);
    void pensize(char cmd,char size);
    	int x1=0x00;
    	int y1=0x20;
    	int x2=0x60;
    	int y2=0x20;
    	int color1=0xFF;
    	int color2=0xFF;
    	int x3=0x10;
    	int y3=0x30;
    	int radius = 0x02;
    	int color3=0xF8;
    	int color4=0x00;
    
    	char col=0x05;
    	char row=0x01;
    	char font=0x02;
    	char color5=0xFF;
    	char color6=0xFF;
    	char ter=0x00;
    
    	char adc;
    	int op;
    
    
    
    
    
    
    
    void pensize(char cmd,char size)
    {
    	SendChar(cmd);
    	SendChar(size);
    }
    
    
    
    
    void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2)
    {
    	SendChar(cmd);
    	SendChar(x1);
    	SendChar(y1);
    	SendChar(x2);
    	SendChar(y2);
    	SendChar(color1);
    	SendChar(color2);
    
    }
    void OLED_DrawCircle(char cmd ,int x3, int y3, radius, int color3,int color4)
    {
    	SendChar(cmd);
    	SendChar(x3);
    	SendChar(y3);
    	SendChar(radius);
    	SendChar(color3);
    	SendChar(color4);
    
    }
    
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char adc, char ter)
    {
    	SendChar(cmd);
    	SendChar(col);
    	SendChar(row);
    	SendChar(font);
    	SendChar(color5);
    	SendChar(color6);
    	SendChar(adc);
    	SendChar(ter);
    }
    
    
    void Timer_Init()
    {
        CKCON     = 0x30;
        TMOD      = 0x20;
        TH1       = 0xFA;
        T2CON     = 0x34;
    
    
    	RCAP2L    = 0xFA;   //baud rate for 57600bps
    	RCAP2H    = 0xFF;
    
    }
    
    void UART_Init()
    {
        PCON      = 0x80;
        SCON      = 0x70;
    }
    
    void Port_IO_Init()
    {
        // P0.0  -  TX   (UART), Push-Pull   Digital
        // P0.1  -  RX   (UART), Push-Pull   Digital
        // P0.2  -  Unassigned,  Open-Drain  Digital
        // P0.3  -  Unassigned,  Open-Drain  Digital
        // P0.4  -  Unassigned,  Open-Drain  Digital
        // P0.5  -  Unassigned,  Open-Drain  Digital
        // P0.6  -  Unassigned,  Open-Drain  Digital
        // P0.7  -  Unassigned,  Open-Drain  Digital
    
        // P1.0  -  Unassigned,  Open-Drain  Digital
        // P1.1  -  Unassigned,  Open-Drain  Digital
        // P1.2  -  Unassigned,  Open-Drain  Digital
        // P1.3  -  Unassigned,  Open-Drain  Digital
        // P1.4  -  Unassigned,  Open-Drain  Digital
        // P1.5  -  Unassigned,  Open-Drain  Digital
        // P1.6  -  Unassigned,  Open-Drain  Digital
        // P1.7  -  Unassigned,  Open-Drain  Digital
    
        // P2.0  -  Unassigned,  Open-Drain  Digital
        // P2.1  -  Unassigned,  Open-Drain  Digital
        // P2.2  -  Unassigned,  Open-Drain  Digital
        // P2.3  -  Unassigned,  Open-Drain  Digital
        // P2.4  -  Unassigned,  Open-Drain  Digital
        // P2.5  -  Unassigned,  Open-Drain  Digital
        // P2.6  -  Unassigned,  Open-Drain  Digital
        // P2.7  -  Unassigned,  Open-Drain  Digital
    
        PRT0MX    = 0x01;
        PRT0CF    = 0x03;
    	P3MODE	= 0x00;
    	PRT1CF	= 0x01;
    	PRT2CF	= 0x10;
    }
    
    void Oscillator_Init()
    {
        int i = 0;
        OSCXCN    = 0x67;
        for (i = 0; i < 3000; i++);  // Wait 1ms for initialization
        while ((OSCXCN & 0x80) == 0);
        OSCICN    = 0x08;
    }
    // Initialization function for device,
    // Call Init_Device() from your main program
    void Init_Device(void)
    {
        Timer_Init();
        UART_Init();
        Port_IO_Init();
        Oscillator_Init();
    }
    
    
    unsigned char Receive()
    {
    	while(RI!=1);
    	RI=0;
    	qqq++;
    	d_receive=SBUF;
    	//RI=0;
    }
    
    void SendChar(unsigned char b)
    {
    	SBUF=b;
     	//delay(1); 
     	while(TI!=1);
    	TI=0;
    }
    
    void delay (int value)
    {
    	int a,b;
    	for (a=0; a<value; a++)
    	{
    		for (b=0; b<20000;b++)
    		{
    
    		}
    	}
    }
    
    
    
    
    
    void Display(void)
    {
    
    
    		pensize(0x70,0x00);
    
    		
    
    				OLED_DrawCircle(0x43,x3,y3,radius,color3,color4);  //display circle
    				OLED_String(0x73,col,row,font,color5,color6,adc,ter); // display value
    
    				Receive();
    
    					if(d_receive!=0x06) //not equal to acknowledge
    					{
    						
    						OLED_DrawCircle(0x43,x3,y3,radius,color3,color4);
    						Receive();
    						OLED_String(0x73,col,row,font,color5,color6,adc,ter);
    						Receive();
    					}
    
    
    
    
    
    				Receive();
    
    }
    
    void main()
    {
    
    	Init_Device();
    	TI=0;
    	RI=0;
    	x=1;
    	//qqq=0;
    	//aaa=0;
    	REF0CN = 0x03; //use VCC as reference
    	AMX0SL = 0x38; //use port1 pin0 as analog input
    	ADC0CF = 0x30;//conversion clock = SYSCLOCK/ 8, gain = 1
    	ADC0CN = 0x80;//ADC enabled, conversion started with ADBUSY, right justified
    	EA = 1; //enable all interrupts
    
    	SendChar(GSGC_AUTOBAUD); 
    	Receive();
    	SendChar(GSGC_CLS);
    	Receive();
    
    	OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2);  //display rectangle
    	if(d_receive!=0x06) //not equal to acknowledge
    					{
    						OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2);
    						Receive();
    					}
    	ADBUSY = 1;//start a conversion
    
    	while(1)
    	{
    		if (ADBUSY == 0)//wait until conversion is complete
    		{
    			op = ADC0H;//get the converted value
    			adc = op;
    			ADBUSY = 1;//start another conversion
    		}
    
    		Display();
    		delay(3);
    
    		
    	}

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Hmmmm, I've got a 1 and I want a value of 49. What *could* I do?

    What could I do??

    If I have to tell you, you'll just be sick.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,403
    Quote Originally Posted by Adak
    I've got a 1 and I want a value of 49. What *could* I do?
    Multiply by 49?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    i think u guys don't quite understand me.
    hmmm.. so wat u guys mean is to ask me to Multiply the ADCvalue by 49??!!
    but that will not work.
    let me give u another example... Lets say the ADC value i get is '122'... the display i get will be 'z'..... because 122 in ascii is 'z'
    so how do i display '1''2''2' on my display?!
    Pls help~~
    Thank you.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    ok, from the above posts, what i can get u want to display 122 as an int, what u can do

    with help of atoi get the "122" as 122 and than display ....

    duno it will work or not

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Quote Originally Posted by RockyMarrone View Post
    ok, from the above posts, what i can get u want to display 122 as an int, what u can do

    with help of atoi get the "122" as 122 and than display ....

    duno it will work or not
    hi and thx for reply.. but im unsure of atoi.. could u put it in codes?

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by vailant View Post
    hi and thx for reply.. but im unsure of atoi.. could u put it in codes?
    ok check this out please

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
        const int value = atoi("122");
        printf("value == [%d]\n", value);
    
        return 0;
    }

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Quote Originally Posted by RockyMarrone View Post
    ok check this out please

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
        const int value = atoi("122");
        printf("value == [%d]\n", value);
    
        return 0;
    }
    thanks for the reply again RockyMarrone..
    but im actuallying using c8051F226 in silicon lab in C language.. and my display is on a external unit uOLED-96-G1... which they actually display text by ascii code.

    my current status is that the display character i get is the adc value converted directly to ascii code.. you can mayb read all the above post..

    u could refer to my coding that i had pasted on my 1st post.
    void OLED_String(char cmd, char col, char row, char font, char color5, char color6, char adc, char ter);

    i had just attach a .GIF paint about the String function from the manual. you can also refer to that.

    please help~~ thanks..
    Attached Images Attached Images  

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Valiant, we're being a bit sarcastic with you. If you have a very low ascii value, like a '1', and you want to print it as it's numerical int value, you just add 48 to it, which is the ascii value of 0.

    Please, don't tell us about your display - don't know, don't care, not relevant. Ditto your code..

    Just SHOW us what you have NOW, and what you want it TO BE.

    We'll take it from there.

    Don't TELL US, SHOW US, in an example. You're including a lot of info that is just fogging up the whole problem.

    It's the old "a picture is worth a thousand words", kind of thing. Your display model and parameters and your program, and your in-laws' tired feet - just don't matter.

    ALL I want to see is what you have NOW (which will be the input to the problem), and what you WANT (output, of course).

    Can do?
    Last edited by Adak; 01-13-2010 at 08:39 PM.

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Quote Originally Posted by Adak View Post
    Valiant, we're being a bit sarcastic with you. If you have a very low ascii value, like a '1', and you want to print it as it's numerical int value, you just add 48 to it, which is the ascii value of 0.

    Please, don't tell us about your display - don't know, don't care, not relevant.

    Just SHOW us what you have NOW, and what you want it TO BE.

    We'll take it from there.

    Don't TELL US, SHOW US, in an example.

    It's the old "a picture is worth a thousand words", kind of thing.

    ALL I want to see is what you have NOW, and what you WANT.

    Can do?
    hi Adak.. i think u should not say "Valiant, we're being a bit sarcastic with you".its should be "Valiant, I'm being a bit sarcastic with you"...u have mis understand it.. the value i got is in int value.. but the display is in ascii....

    im adding in the display info is to let ppl understand more.. as i mention.. u can ignore those display codes if u dun wish to know.

    i had already mention what i want in all the above post want i want.
    ok.. now i have attached 2 paints of what i have currently and what i want. hope that make things clearer.

    sorry if i cant explain too well..
    im just trying to get some help.
    and i know u guys are also trying to help...
    Thank you all so much..
    =)
    Attached Images Attached Images   

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    hey Vailant - sorry about the name. I did misspell it.

    I didn't know English was not your first language, and thought you were maybe messing with us.

    This does what you want, I believe. It uses an array, but you can use any values.

    Code:
    /* show the system values (usually, ascii) */
    
    #include <stdio.h>
    
    int main() {
      int i;
    
      char str[] = {"abcdefghijklmnopqrstuvwxyz"};
    
    
      for(i=0;str[i]!='\0';i++) 
        printf("ascii: %c   Decimal: %d   Hex: %X \n", str[i], str[i], str[i]);
    
      i = getchar(); ++i;
      return 0;
    }
    Letters are just char's, and char's are just numbers with a small range. We can use that for your problem.

  12. #12
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Thanks for the reply..

    but... my display wont work with printf function....
    im using a different display.. that is why im giving infos of my display previously.

    help pls.... =(

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by vailant View Post
    Thanks for the reply..

    but... my display wont work with printf function....
    im using a different display.. that is why im giving infos of my display previously.

    help pls.... =(
    Unfortunately, I don't know what "send char" can do, for you, exactly. That's not part of standard C, you see.

    Can you print any number longer than one digit in length?

    Can you create a char array of say, 4 char's in length?

  14. #14
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    it should be able to... but im not sure how to create arrary string in C...
    pls guide me.. thanks a lot...
    Attached Images Attached Images  

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, now I'm starting to understand this problem.

    Code:
    char str_num[4];
    creates a char array. It needs to go quite near the top of it's function.

    so what we need to do is covert the numbers into a string, and put them in our char array. Then print them out using that print function you posted.

    I have to run some errands now. I'll post up some code to translate your ascii numbers into char digits, and put them into the char array, when I get back.
    Last edited by Adak; 01-14-2010 at 08:09 PM.

Page 1 of 3 123 LastLast
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, 12:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21