Thread: Need Help!! C8051F226 with uOLED-96-G1.

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

    Need Help!! C8051F226 with uOLED-96-G1.

    hi all.. im currently working on uOLED-96-G1 with C8051F226 using silab in C language..
    i would like to know how could i adjust contrast using external switch..

    Currently im able to use the Display Control Function to adjust the contrast.
    OLED_DisplayControl(0x59, 0x02, valueC)
    so i could set the contrast by change the valueC = 0x00 to 0x0F..

    now i would like to use external switch and connect to the Switch Pin of the uOLED (Pin7) to adjust the contrast by changing the value in valueC..

    i want the valueC = 0x00, when i press the switch 1..
    and valueC = 0x0F, when i press the switch 2.. etc..

    but im having problem with the switch function..
    can any1 help me please??

    i've attached a paint to show more info about the uOLED..

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The hardware diagram is not too useful. What I'd want is the software interface specifications or directions, to the hardware Display Control Function.

    Get that, and then we've got some place to start in.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    hi Adak!
    hmmm.. sorry.. but what does it mean by "software interface specifications or directions" any example???

    i've attached the Display Control Function piant.. hope it'll provide more info..

    this is an example of my code.. currently im able to display n adjust the contrast by changing the valueC inside coding...
    Code:
    /////////////////////////////////////
    //  Generated Initialization File  //
    /////////////////////////////////////
    #include "stdio.h"
    #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;
    
    void SendChar(unsigned char b);
    void OLED_DrawRectangle(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2);
    void delay(int value);
    void pensize(char cmd,char size);
    void rectangle(void);
    void display(void);
    
    void OLED_DisplayControl(char cmd, char modeC, char valueC);
    void OLED_Switch(char cmd, char option);
    
    char valueC;			//contrast range 0x00-0x0F
    char option = 0x08;
    char status;
    
    void OLED_DisplayControl(char cmd, char modeC, char valueC)
    {
    	SendChar(cmd);
    	SendChar(modeC);
    	SendChar(valueC);
    }
    
    void OLED_Switch(char cmd, char option)
    {
    	SendChar(cmd);
    	SendChar(option);
    }
    
    
    void pensize(char cmd,char size)
    {
    	SendChar(cmd);
    	SendChar(size);
    }
    
    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;
    	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();
    }
    
    
    void 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<20;b++)
    		{
    
    		}
    	}
    }
    
    
    void Switch(void)
    {
    	OLED_Switch(0x4A,option);
    	Receive();
    	if (d_receive == 0x01)
    	{
    		valueC = 0x01;
    	}
    	else if (d_receive == 0x02)
    	{
    		valueC = 0x0F;
    	}
    	else
    	{
    		valueC = 0x05;
    	}
    }
    
    void DisplayControl(void)
    {
    	
    	OLED_DisplayControl(0x59, 0x02, valueC);
    	Receive();
    
    	if(d_receive!=0x06) //not equal to acknowledge
    	{						
    		OLED_DisplayControl(0x59, 0x02, valueC);
    		Receive();
    	}
    }
    
    void OLED_DrawRectangle(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 rectangle(void)
    {
    
    	int x1=0x00;
    	int y1=0x00;
    	int x2=0x50;
    	int y2=0x3F;
    	int color1=0x50;
    	int color2=0x50;
    	pensize(0x70,0x00);
    
    		
    	OLED_DrawRectangle(0x72,x1,y1,x2,y2,color1,color2);  //display rectangle
    	Receive();
    
    		if(d_receive!=0x06) //not equal to acknowledge
    		{
    			OLED_DrawRectangle(0x72,x1,y1,x2,y2,color1,color2);
    			Receive();
    		}
    
    
    }
    
    void main()
    {
    
    	Init_Device();
    	TI=0;
    	RI=0;
    	x=1;
    	//qqq=0;
    	//aaa=0;
    	SendChar(GSGC_AUTOBAUD); 
    	Receive();
    	SendChar(GSGC_CLS);
    	Receive();
    
    	Switch();
    	DisplayControl();
    
    	while (1)
    	{
    	rectangle();
    	}
    
    }
    what i wish to do is use the external switch to get the respond value to adjust the valueC.
    Last edited by vailant; 01-26-2010 at 10:23 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Great, but when you' want to control the intensity of the display using an external switch - that's hardware, not software.

    Even if the switch could be controlled by software, I still wouldn't know how to do it, without the instructions from the switch maker.

    You're at the hardware level, and I need you to bring the problem up to the software level. A print out of the hardware schematic, won't do I'm afraid.


    Don't you have any instructions for interfacing with this device? I know there is information in the program you posted - but I need more. I don't see anything in that program relating to adding another switch to control the intensity of the display.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    hi..
    hmmm.. i hope this would help....
    http://www.4dsystems.com.au/download...S-SIS-rev2.pdf

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'll have to go through it when I've more time, but first impression is:

    Oh Hell Yes!

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Thank you so so so much Adak....
    hope to have good news from u soon! =)

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    According to the schematic and directions, you can either hook up an external series of up to 5 switches, or you can hook up 1 multi-position switch with up to 5 different settings.

    Have you tried hooking up the switch(es) and testing that?

    I'm still not sure what you want the software to do for you.

    Won't this function of your program handle this for you?

    Code:
    void Switch(void)
    {
    	OLED_Switch(0x4A,option);
    	Receive();
    	if (d_receive == 0x01)
    	{
    		valueC = 0x01;
    	}
    	else if (d_receive == 0x02)
    	{
    		valueC = 0x0F;
    	}
    	else
    	{
    		valueC = 0x05;
    	}
    }
    I'm not sure what the "respond value" is, is that the 0x01, 0x02, 0x0F, or 0x05 values?

  9. #9
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    yes.. i had connected 2 switches to the uOLED according to the schemetic i show on the 1st post. and i had also test the switches. it gives different value when i press the switch. which should be correct.

    as for the function void Switch, that is the function which i want to get the respond value of the switch function(i hope). It suppose to return me 0x01(when switch 1 pressed), 0x02(switch 2 pressed), and so on... and i suppose that value will be going to my SBUF. which i stated d_receive = SBUF.. and the valueC is the value that able to adjsut the display contrast. so when value 0x01 is fed into d_receive, valueC = 0x01... but now when i check the SBUF value, it always give me either 0x06 or 0x15.. which is a acknowledge response of ACK and NAK.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I notice you have rem'ed out the include file "dos.h". That means you don't have it, then?

    You'll need to set up some delay between the TX and RX, so put that into your program, and then see what you have working (and what still isn't working, if anything).

    I wouldn't worry about what you think you should receive, etc. For now, if something is working correctly, and is operating within it's normal operating range for temperature, etc., let's say "it's OK", and concentrate on anything that obviously is not working.

    We'll benefit by being as functionally oriented as possible, right now. Like with SBUF. I have no idea if you should be receiving ACK and NAK back from it, somewhere. For now, if things are working, let it be.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    everything work fine for now... just that the Switch function seems not to be working..
    so what should i do now?

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Can you confirm with a multi-meter, that all the switches are wired up correctly, each one also wired up to it's resistor, and each resistor then going to ground?

    The delay function is coded up and working OK?

    What does happen when you push the switch?

Popular pages Recent additions subscribe to a feed