Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Logic to print text in SSD1306.

Status
Not open for further replies.

Praveen Kumar P S

Member level 4
Joined
Aug 21, 2014
Messages
79
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
India
Activity points
627
Hello Guys,

I was writing a program for my SSD1306 oled display from scratch without any third party. I have successfully initialized the display. But I dont know the logic to turn on the pixels for a particular ascii character. I am stuck with the logic to print a character on the display. Help needed guys.


Thank you
 

Hi,

maybe you need to use a lookup table for the pixels per character.

Show us what you have done so far.
Are you able to switch ON/OFF particular pixels?

Klaus
 
To be honest, I never seen any nice looking and optimal from code and performance point of view library in open sources. Every time we have to write our own.
The most popular issue is to plot symbol pixel by pixel. The most efficient way is to specify the memory window and full fill it with the content. I did increase refresh rate 100 times on similar display this way.
 

Hi,

maybe you need to use a lookup table for the pixels per character.

Show us what you have done so far.
Are you able to switch ON/OFF particular pixels?

Klaus

Hi, Thanks for the replay.
Yes, I am able to turn ON/OFF the pixels. Thanks to datasheet.
could you please be more specific on lookup tables.. Its something new to me..

Here is my code:

Code:
#include <xc.h>
#include <stdint.h>

#define _XTAL_FREQ 16000000            //20 for the Delays
void i2c_init(void);
void i2c_start(void);
bit i2c_write(uint8_t);
uint8_t i2c_read(void);
void i2c_stop(void);
void wait(void);
void i2c_rstart(void);
void i2c_nack(void);
//void init_comm(void);
void ssd_cmd(uint8_t);
void ssd_dat(uint8_t);

#pragma config FOSC        = HS
#pragma config WDT         = OFF
#pragma config LVP         = OFF
#pragma config BOR         = OFF
#pragma config MCLRE       = ON
#pragma config PWRT        = ON
#pragma config PBADEN      = OFF

#define SSD1306_LCDWIDTH      128
#define SSD1306_LCDHEIGHT      64
#define SSD1306_SETCONTRAST   0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COLUMNADDR 0x21
#define SSD1306_PAGEADDR   0x22
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2


uint8_t rec,data;

void main(void) {
    
    //init_comm();
    i2c_init();
        
    ssd_cmd(SSD1306_DISPLAYOFF);                    // 0xAE
    ssd_cmd(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
    ssd_cmd(0x80);                                  // the suggested ratio 0x80
    ssd_cmd(SSD1306_SETMULTIPLEX);                  // 0xA8
    ssd_cmd(0x3F);
    ssd_cmd(SSD1306_SETDISPLAYOFFSET);              // 0xD3
    ssd_cmd(0x0);                                   // no offset
    ssd_cmd(SSD1306_SETSTARTLINE);// | 0x0);        // line #0
    ssd_cmd(SSD1306_CHARGEPUMP);                    // 0x8D
    ssd_cmd(0x14);                                  // using internal VCC
    ssd_cmd(SSD1306_MEMORYMODE);                    // 0x20
    ssd_cmd(0x00);                                  // 0x00 horizontal addressing
    ssd_cmd(SSD1306_SEGREMAP | 0x1);                // rotate screen 180
    ssd_cmd(SSD1306_COMSCANDEC);                    // rotate screen 180
    ssd_cmd(SSD1306_SETCOMPINS);                    // 0xDA
    ssd_cmd(0x12);
    ssd_cmd(SSD1306_SETCONTRAST);                   // 0x81
    ssd_cmd(0xff);
    ssd_cmd(SSD1306_SETPRECHARGE);                  // 0xd9
    ssd_cmd(0xF1);
    ssd_cmd(SSD1306_SETVCOMDETECT);                 // 0xDB
    ssd_cmd(0x40);
    ssd_cmd(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
    ssd_cmd(SSD1306_NORMALDISPLAY);                 // 0xA6
    ssd_cmd(SSD1306_DISPLAYON);                     //display panel on
       
   __delay_ms(10);
   
    uint8_t i=0xb0,j=0;
    
    
    while(i <= 0xb7){
        
        ssd_cmd(0x10); 
        ssd_cmd(i);  
        ssd_cmd(0x00);
        ssd_cmd(0x10);
     
        while(j <= 127) {
            ssd_dat(0xff);  
           j++;
        }
        j=0;
        i=i+1;
    }
         
    while(1) {
        } 
    return;
}

void wait() {
    while((SSPSTAT & 0x04) || (SSPCON2 & 0x1f)); 
}
 
void i2c_init() {
    
    TRISB0 = 1;        
    TRISB1 = 1;
    SSPADD = 39;
    SSPCON1 = 0x08;
    SSPEN = 1; 
    SMP = 1;                            
}  

void i2c_start() { 
    wait();
    SEN = 1;
    while(SSPIF != 1);
    SSPIF = 0;   
}

void i2c_rstart() { 
    wait();
    RSEN = 1;
    while(SSPIF != 1);
    SSPIF = 0;   
}

bit i2c_write(uint8_t dat) {
    wait();
    SSPBUF = dat;
    while(SSPIF != 1);
    SSPIF = 0;
    return ACKSTAT;
}

uint8_t i2c_read() {
    wait();
    RCEN = 1;
    while(!BF);
    rec = SSPBUF;
    return rec;
}

void i2c_nack() { 
    wait();
    ACKDT = 1;
    ACKEN = 1; 
}

void i2c_stop() {
    wait();
    PEN = 1;
    while(SSPIF != 1);
    SSPIF = 0;
}

//void init_comm() {
//    TRISC6 = 0;
//   
//    SYNC = 0;                 // Asynchronous Mode
//    SPEN = 1;                 // configures RX/DT and TX/CK pins as serial port pins in RCSTA
//    BRGH = 0;                 //  Select low speed baud 
//    SPBRG = 25;               // Calculated for baudrate = 9600
//    TXEN = 1;   
//}

void ssd_cmd(uint8_t cmd) {
    i2c_start();
    i2c_write(0x78);
    i2c_write(0x00);
    i2c_write(cmd);      // 0b10000010
    i2c_stop();
}

void ssd_dat(uint8_t dat) {
    i2c_start();
    i2c_write(0x78);
    i2c_write(0x40);
    i2c_write(dat);      // 0b10000010
    i2c_stop();
}

- - - Updated - - -

To be honest, I never seen any nice looking and optimal from code and performance point of view library in open sources. Every time we have to write our own.
The most popular issue is to plot symbol pixel by pixel. The most efficient way is to specify the memory window and full fill it with the content. I did increase refresh rate 100 times on similar display this way.

I agree with you. The most frustrating thing is that these libraries are bulky and most of the time it wont fit inside the memory.
 

hello,


[B]an example to Draw a Texte [/B] with use of lookup table
You need to be able to draw a point (pixel )...
and have enough space to store characteres tables

PIC18F87J50 and SPI linked instead of I2C ..
i used a debug mode , wich can show the display result of char on a terminal ( via UART)
so more easy to understand..
Oled_Text_test_with_UART2.jpg
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top