Nicolas Electronics

Electronic projects and programming

Winstar 16×2 Character OLED display library

Here’s a little library for a WS0010 controller used in a Winstar WEH001602AL 16×2 character OLED display.

It’s been built for a PIC microcontroller and is still a work in progress as only the 8-bit parallel mode works.

The advantage of the library is that I’m using defines for the used I/O and the delays.
It should be very easy to change those I/O and delay function to make the library work on an AVR or other MCU.

1
2
3
4
5
6
7
8
9
10
#define WS0010_delay_ms(var) __delay_ms(var)
#define WS0010_delay_us(var) __delay_us(var)
 
#define DATA_PORT PORTB
#define DATA_TRIS TRISB
#define CONTROL_PORT PORTC
#define CONTROL_TRIS TRISC
#define RS_BIT 0 // pin C0
#define RWB_BIT 1 // pin C1
#define EN_BIT 2 // pin C2

The library sets the I/O as outputs when you call the init function.
You have to manually disable any other function (ADC, …) on the port you want to use for either the control or the data port.

I’m using a structure to help me initialize the OLED display. This makes it easier for the user and myself to set the font, the parallel mode, the cursor, …

1
2
3
4
5
6
7
8
9
10
11
12
typedef struct{
    enum PMODE mode; // 8 bit or 4 bit mode
    enum LINE line; // 5x8 char + 16x1 disp, 5x10 char + 16x1 disp, 5x8 char + 16x2 disp
    enum CGROM font; // Eng/Jap, West EU I, West EU II, Eng/Rus
 
    enum STATE display; // on, off
    enum STATE cursor; // on, off
    enum STATE cursor_blink; // on, off
 
    enum CURSOR cursor_dir; // decr, incr (after writing char, move left or right from char written)
    enum DIR display_shift; // left, right
}WS0010_Param;

I’ve made an initParam function that will enable the display with the 8 bit mode, 16×2 display mode, West EU I font, cursor and cursor blink on, cursor increment and display shift right.

OLED Display Test

Here’s the download link: OLED Display lib

Enjoy, feedback is welcom.

– pyroesp

4 thoughts on “Winstar 16×2 Character OLED display library

  • Ashkar says:

    Hey brother, Thank you for your Work,I need this library that it should work on AVR Atmega32 Mcu,But I am unable to get it running after modifying the #define statements.Could you please check this up.

    • pyroesp says:

      I just remembered that to set an I/O as output on an AVR you have to set a bit in the DDRx register, which is the opposite of what you do on a PIC.

      For now, you can change this in the WS0010_InitLCD function:

      1
      2
      
      DATA_TRIS = 0xFF
      CONTROL_TRIS = 0xFF

      Note that it’s a destructive operation, not taking care of previous settings of the DDRx registers.

      Hopefully, this helps.

  • Sergey says:

    Dude, greate job, thx a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box