0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.