'Controlling UC1638 Graphical LCD screen

I am using Arduino Uno, trying to control LCD screen type UC1638 (240x128 monochrome) I want to fillup the screen in black). Searching up the internet I ended up using this code (written in C):

/* The below source code is from the LCD manufacturer, when he has no
   idea about Arduino, this is translated from code he gave me for AVR
   - I assume "sbit" is just Arduino GPIO settings, so I changed them
   here accordingly - but I am not sure if it is the correct settings I
   shall use for the LCD screen via Arduino
 */

#include "stdio.h"
#include "stdlib.h"

//sbit RST = P3^1;
//sbit CD  = P3^0;  
//sbit SCK = P1^0; //WRB=WR0
//sbit SDA = P1^1; //RDB=WR1
//sbit CS = P3^2;

void writei(unsigned char Cbyte)
{
    unsigned char i;
    digitalWrite(11, LOW); //CS=0;
    digitalWrite(12, LOW); //CD=0;
    for(i=0;i<8;i++) {
         digitalWrite(SCK, LOW); // SCK=0;
         digitalWrite(SDA, Cbyte&0x80?HIGH:LOW); // SDA=Cbyte&0x80?1:0;
         digitalWrite(SCK, HIGH); // SCK=1;
         Cbyte=Cbyte<<1;
    }
    digitalWrite(11, HIGH); // CS=1;
}

void writed(unsigned char Dbyte) { 
    unsigned char i;
    digitalWrite(11, LOW); //CS=0;
    digitalWrite(12, HIGH); //CD=1;    
    for(i=0;i<8;i++) {
        digitalWrite(SCK, LOW); // SCK=0;
        digitalWrite(SDA, Dbyte&0x80?HIGH:LOW); // SDA=Dbyte&0x80?1:0;
        digitalWrite(SCK, HIGH); // SCK=1;

        Dbyte=Dbyte<<1;    
    }
    digitalWrite(11, HIGH);  // CS=1; 
}

void DelayMS(unsigned int MS)
{
    unsigned char us,usn;
    while(MS!=0)
    {
         usn=2;
         while(usn!=0) { us=0xf6; while(us!=0){us--;}; usn--; }
         MS--;
    }
}

void LCD_INIT(void) {

    //writei(0xe3);//system reset
    digitalWrite(13, LOW); // RST=0;
    DelayMS(10); //1ms

    digitalWrite(13, HIGH); // RST=1;
    DelayMS(500);//Delay more than 150ms.

    writei(0xe1);//system reset
    writed(0xe2);

    DelayMS(2);
    writei(0x04);//set column Address
    writed(0x00);// 

    //writei(0x2f);// internal VLCD
    //writei(0x26);// TC
    writei(0xEb);//set bias=1/12
    writei(0x81);//set vop
    writed(90);//  pm=106 Set VLCD=15V

    writei(0xb8);//屏蔽MTP
    writed(0x00);

    writei(0xC4);//set lcd mapping control
    //writei(0x00);   //MY  MX 0

    writei(0xA3);//set line rate  20klps
    writei(0x95);  // PT0   1B P P
    //writei(90);

    writei(0xf1);   //set com end
    writed(159);    //set com end   240*128

    writei(0xC2);
    writei(0x31);   //APC
    writed(0X91);    // 1/0: sys_LRM_EN disable
    writei(0xc9);
    writed(0xad);  //  display 
}
void setWindowsProgame()     //com36--160  seg51--205
{
    writei(0x04);   //colum  
    writed(0x00);
    writei(0x60);    //page     
    writei(0x70);   
    writei(0xf4);
    writed(0);        //startx  
    writei(0xf6);
    writed(239);      //endx   
    writei(0xf5);  
    writed(0);        //    
    writei(0xf7);
    writed(15);      //endy    PANGE  16页
    writei(0xf9);  //窗口功能开 
    writei(0xC4);//set lcd mapping control
}
void display_black(void)
{
    int i,j,k;
    setWindowsProgame();
    for(i=0;i<240;i++) {
        for(j=0;j<18;j++) { writei(0x01); writed(0xff); }
    }
}  
void display_wirte ()
{
    int i,j,k;
    setWindowsProgame();
    for(i=0;i<240;i++) {
        for(j=0;j<18;j++) { writei(0x01); writed(0x00); }
    }
}
void display_pic()
{      
    int i,j,K;
    char d; 
    setWindowsProgame();
    i=0; 
    K=0;
    for(i=0;i<240*16;i++)   //240*144
    {
        writei(0x01);
        d=0xff; //d=PIC[K++];
        writed(d);
    }
}

void setup() {
    // IO declaration: (GPIO setup)
    pinMode(12, OUTPUT); // CD
    pinMode(13, OUTPUT); // RST (RW)
    pinMode(11, OUTPUT); // CS
    pinMode(SCK, OUTPUT);
    pinMode(SDA, OUTPUT);
    LCD_INIT();
}

void loop(){
    display_pic(); // Fill-up the screen in black
}

Notes:

  1. The screen is 240*128 monochrome pixels.
  2. Chip is UC1638
  3. I am using Arduino Uno (if it helps regarding the available GPIOs)
  4. I know about the "LiquidCrystal" library, but the examples gaven to me till now are for text screen of 16*2, not graphical screen - I believe that the GPIOs are completely different.

I want to "paint" the screen in black: Though the compilation passes OK, the LCD screen seems empty (transparent), but it has power - What I am doing wrong?

Thanks a lot

EDIT: * I added SCK+SDA pins mark as output - Though I believe pins connected OK, the result is still the same. If the code is OK, then I will double check my pins...



Solution 1:[1]

I found and solved some problems in the code:

First, the delay of the delayms function in the source code is not accurate, so I replaced it with the delay function in Arduino.

Then, the value (90) of Vbias (command 0x81) set during LCD initialization is low. After changing to 200, the contrast is significantly improved.

Finally, this is the current code, which runs well on STM32F103C8T6:

#include <stdio.h>
#include <stdlib.h>

#define SDA PA7
#define SCK PA5
#define RST PB6
#define CS  PB10
#define CD  PB0

void writei(unsigned char Cbyte)
{
    unsigned char i;
    digitalWrite(CS, LOW); //CS=0;
    digitalWrite(CD, LOW); //CD=0;
    for(i=0;i<8;i++) {
         digitalWrite(SCK, LOW); // SCK=0;
         digitalWrite(SDA, Cbyte&0x80?HIGH:LOW); // SDA=Cbyte&0x80?1:0;
         digitalWrite(SCK, HIGH); // SCK=1;
         Cbyte=Cbyte<<1;
    }
    digitalWrite(CS, HIGH); // CS=1;
}

void writed(unsigned char Dbyte) { 
    unsigned char i;
    digitalWrite(CS, LOW); //CS=0;
    digitalWrite(CD, HIGH); //CD=1;    
    for(i=0;i<8;i++) {
        digitalWrite(SCK, LOW); // SCK=0;
        digitalWrite(SDA, Dbyte&0x80?HIGH:LOW); // SDA=Dbyte&0x80?1:0;
        digitalWrite(SCK, HIGH); // SCK=1;

        Dbyte=Dbyte<<1;    
    }
    digitalWrite(CS, HIGH);  // CS=1; 
}


void LCD_INIT(void) {

    //writei(0xe3);//system reset
    digitalWrite(RST, LOW); // RST=0;
    delay(10); //1ms

    digitalWrite(RST, HIGH); // RST=1;
    delay(500);//Delay more than 150ms.

    writei(0xe1);//system reset
    writed(0xe2);

    delay(2);
    writei(0x04);//set column Address
    writed(0x00);

    //writei(0x2f);// internal VLCD
    //writei(0x26);// TC
    writei(0xEb);//set bias=1/12
    writei(0x81);//set vop
    writed(200);//  pm=106 Set VLCD=15V

    writei(0xb8);//??MTP
    writed(0x00);

    writei(0xC4);//set lcd mapping control
    //writei(0x00);   //MY  MX 0

    writei(0xA3);//set line rate  20klps
    writei(0x95);  // PT0   1B P P
    //writei(90);

    writei(0xf1);   //set com end
    writed(159);    //set com end   240*128

    writei(0xC2);
    writei(0x31);   //APC
    writed(0X91);    // 1/0: sys_LRM_EN disable
    writei(0xc9);
    writed(0xad);  //  display 
}
void setWindowsProgame()     //com36--160  seg51--205
{
    writei(0x04);   //colum  
    writed(0x00);
    writei(0x60);    //page     
    writei(0x70);   
    writei(0xf4);
    writed(0);        //startx  
    writei(0xf6);
    writed(239);      //endx   
    writei(0xf5);  
    writed(0);        //    
    writei(0xf7);
    writed(19);      //endy    PANGE  16?
    writei(0xf9);  //????? 
    writei(0xC4);//set lcd mapping control
}
void display_black(void)
{
    int i,j,k;
    setWindowsProgame();
    for(i=0;i<240;i++) {
        for(j=0;j<20;j++) { writei(0x01); writed(0xff); }
    }
}  
void display_wirte()
{
    int i,j,k;
    setWindowsProgame();
    for(i=0;i<240;i++) {
        for(j=0;j<20;j++) { writei(0x01); writed(0x00); }
    }
}
void display_pic()
{      
    int i,j,K;
    char d; 
    setWindowsProgame();
    i=0; 
    K=0;
    for(i=0;i<240*20;i++)   //240*144
    {
        writei(0x01);
        d=0xff; //d=PIC[K++];
        writed(d);
    }
}

void setup() {
    // IO declaration: (GPIO setup)
    pinMode(CD, OUTPUT); // CD
    pinMode(RST, OUTPUT); // RST (RW)
    pinMode(CS, OUTPUT); // CS
    pinMode(SCK, OUTPUT);
    pinMode(SDA, OUTPUT);
    LCD_INIT();
}

void loop(){
    display_black(); // Fill-up the screen in black
    delay(1000);
    display_wirte();
    delay(1000);
}

photo of setup

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wovano