Need Help!! uOLED-96-G1

hi all.. im currently working on uOLED-96-G1 with C8051F226.. i would like to know how could i adjust contrast using external switch.. i understand and 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 from 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..

but im having problem with the switch function.. im here to get some help.... can any1 help me please??

but im having problem with the switch function.. im here to get some help.... can any1 help me please??

Oooh, I love guessing games. :)

No, I don't. >:( What problem(s) are you having with what switch function in what code?

Like PaulS said. I (we) would need some more info. For example; What firmware (PmmC file) do you want to use? The serial platform or the 4DGL platform version?

I personally have a uOLED-160-G1 which is the same except size but haven't had time to try the analog input pin as button input yet.

Jeroen

hi… thx for reply…
sorry if i can’t explain too well… :frowning:
firmware (PmmC file)??? << i don’t quite understand this…
im using microcontroller C8051F226… and using silicon lab… in C language…
this is the example of my code.

#include "C8051F200.h"
#include "GSGCdef.h"
void OLED_DrawLine(char cmd ,int x1, int y1, int x2, int y2,int color1,int color2);

int x1=0x00;
int y1=0x20;
int x2=0x60;
int y2=0x20;
int color1=0xFF;
int color2=0xFF;

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 Timer_Init()
{
    CKCON     = 0x30;
    TMOD      = 0x20;
    TH1       = 0xFA;
    T2CON     = 0x34;


      RCAP2L    = 0xFA;   //baud rate for 57600bps
      RCAP2H    = 0xFF;

}


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 UART_Init()
{
    PCON      = 0x80;
    SCON      = 0x70;
}

void delay (int value)
{
      int a,b;
      for (a=0; a<value; a++)
      {
            for (b=0; b<20000;b++)
            {

            }
      }
}

void main()
{

      Init_Device();
      TI=0;
      RI=0;
      x=1;
      //qqq=0;
      //aaa=0;


      SendChar(GSGC_AUTOBAUD); 
      Receive();
      SendChar(GSGC_CLS);
      Receive();

OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2); 
if(d_receive!=0x06) //not equal to acknowledge
{
      OLED_DrawLine(0x4C,x1,y1,x2,y2,color1,color2);
      Receive();
}
}

currently im able to adjust the contrast by adding
OLED_DisplayControl(0x59, 0x02, valueC)
by changing the valueC from 0x00 to 0x0F
but i would like to change the valueC by adding external switch connected to the uOLED-96-G1 (pin7) using the [switch-buttons-joystick status] command like, OLED_Switch(0x4A, char option)
e.g. if i press switch 1 valueC=0x00, if i press switch 2 valueC=0x0F
hope u guys could understand me more… hope to hear from u guys again!
Thank you!!!

hi vailant,

firmware (PmmC file)??? << i don’t quite understand this…

It’s the software that runs on the processor on the back of the display. If you haven’t changed it your display will run the “serial” firmware.

microcontroller C8051F226

I hope you realized that this is an arduino forum. Here we generally discuss about different microcontrollers.

If you have managed to draw a line at least you did the setup of the display alright and you can send commands and receive answers. Reading the buttons should (havent done so myself) be a matter as sending
0x4A or J “Switch-Buttons-Joystick Status” then
0x8 “Return Buttons-Joystick Status”
and than you should get a status returned from the display.

00hex : No Buttons pressed (or pressed button has been released).
01hex : SW1 (UP) pressed.
02hex : SW2 (LEFT) pressed.
03hex : SW3 (DOWN) pressed.
04hex : SW4 (RIGHT) pressed.
05hex : SW5 (FIRE) pressed.

Hope this helped,

Jeroen

yes... i understand that.. because im using C8051F226.. just hope i could get some help... hope u guys don't mind...

yes.. i understand the "Switch-Buttons-Joystick Status" this is part of my code..

void OLED_Switch(char cmd, char option);
void OLED_DisplayControl(char cmd, char modeC, char valueC);
char option = 0x08;
void OLED_Switch(char cmd, char option)
{
      SendChar(cmd);
      SendChar(option);
}
void SendChar(unsigned char b)
{
      SBUF=b;
       //delay(1); 
       while(TI!=1);
      TI=0;
}
unsigned char Receive()
{
      while(RI!=1);
      RI=0;
      qqq++;
      d_receive=SBUF;
      //RI=0;
}
void Switch(void)
{
      OLED_Switch(0x4A,option);
      Receive();
      
      if (d_receive==0x01)        //when switch 1 is pressed
      {
            valueC = 0x01;
      }
      else
      {
            valueC = 0x09;
      }
}
void DisplayControl(void)
{

      OLED_DisplayControl(0x59, 0x02, valueC);
      Receive();

      if(d_receive!=0x06) //not equal to acknowledge
      {
                                    
            OLED_DisplayControl(0x59, 0x02, valueC);
            Receive();
      }
}

but im unable to get the value from SBUF... could any1 help me pls.. is there anyway that i could check if the "Switch-Buttons-Joystick Status" is actually working??? can any1 pls guide me with a program code??? thanks!!!!

Code will be difficult because i haven't coded it yet for an arduino and i don't know the exact syntax for your controller.

What i don't understand from your code is the "unsigned char Receive()" function. It should return an unsigned char but i do not see a "return d_receive;" at the end. If "d_receive" is a global variable shouldn't the function be "void Receive()". Remember that i don't know anything about your controller. Do you get anything from that function? Something like a NAK(0x15)? Do you normally check for ACK or NAK?

What software version is on the display? (Version-Device Info Request - 56hex) - pmmc_rev Obvious question; Have you checked all hardware connections/ resistor values?

Jeroen

yeah.. i think it should be void Receive()...

erm... so how do i check my software version?? how do i exactly use the (Version-Device Info Request - 56hex)?? any code for that?

Sorry it took a while to respond.

From memory; The “Version-Device Info Request” command (56hex) and a 0hex or 1hex makes the screen display it’s properties and sends the properties back serially.
These are the functions i use (2 snippets, your mileage may vary)

void uOLED::DeviceInfo ()
{
  write(0x56);       // send DeviceInfoRequest command
  write(0x01);       // 0 = info to serial port only. 1 = info to serial port and screen.
  for ( byte i=0; i<5; i++)
      {
      RBack();                         // dump 5 times the serial input from screen
      }
}

//Read a byte from serial port send by display
char uOLED::RBack()
{
  // Wait for serial data 
  while (!available()) 
    { 
        // do nothing (this could be a trap if nothing is received)
    }
  return read();
}

write() = write a byte over the serial port.
available() = is there a byte to read from the serial port?
read() = read a byte from the serial port.

good luck,

Jeroen

hi.. i have check.. im using version 0.015.. can anyone help me please...

im using version 0.015

Of the arduino ide? I thought you used another series of microcontroller?

because im using C8051F226

Code syntax will be different but i think you could rewrite my example functions.

Have you checked that you can receive from the display? For example ack/nak or read the color of a pixel?

Jeroen

hi..... erm.. sorry but i don't really understand... :-[

What don’t you understand.

Jeroen