我正在使用Arduino Uno,试图控制UC1638型液晶显示屏(240x128单色),我想用黑色填充屏幕)。搜索互联网后,我最终使用了以下代码(用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
}
注意:
我想将屏幕“涂成黑色”:尽管编译通过,但LCD屏幕似乎是空的(透明的),但是它具有功能-我在做什么错了?
非常感谢
编辑: *我添加了SCK + SDA引脚标记作为输出-尽管我相信引脚连接正常,但结果仍然相同。如果代码正确,那么我将再次检查我的密码...