巡航66 发表于 2018-11-17 10:38:54

关于LCD12864显示的问题

今日用ARDUINO NANO 、DS3231和LCD12864 连接,做一个时钟测试。SPI连接。能够显示时间、日期、温度数据。第一次使用LCD12864,不熟悉其特性,用LCDA.CLEAR();//清屏 语句后,屏幕总是闪烁,注销该语句,闪烁情况有所好转。LCD12864型号是12864B V2.0、接ARDUINO NANO上5V电源,蓝色背光、白色字体。但显示的字体深浅不一,请教各位高手,是因为NANO板供电不足还是其他原因?测试语句如下,望不吝赐教!!
#include "LCD12864RSPI.h"
#define AR_SIZE( a ) sizeof( a ) / sizeof( a )
#include <DS3231.h>
#include <Wire.h>
DS3231 Clock;
int ss,s1,s2;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;
char str;
char str2;
int ye,mo,da,dow,ho,mi,se,tp;
unsigned char XQ1[]={0xD0, 0xC7,0xC6, 0xDA,0xD2, 0xBB};//星期一
unsigned char XQ2[]={0xD0, 0xC7,0xC6, 0xDA,0xB6, 0xFE};//星期二
unsigned char XQ3[]={0xD0, 0xC7,0xC6, 0xDA,0xC8, 0xFD};//星期三
unsigned char XQ4[]={0xD0, 0xC7,0xC6, 0xDA,0xCB, 0xC4};//星期四
unsigned char XQ5[]={0xD0, 0xC7,0xC6, 0xDA,0xCE, 0xE5};//星期五
unsigned char XQ6[]={0xD0, 0xC7,0xC6, 0xDA,0xC1, 0xF9};//星期六
unsigned char XQ7[]={0xD0, 0xC7,0xC6, 0xDA,0xC8, 0xD5};//星期日
unsigned char WDBZ[]={0xA1,0xE6};   //℃
unsigned char N[]={ 0xC4, 0xEA};//年
unsigned char Y[]={ 0xD4, 0xC2};//月
unsigned char R[]={ 0xC8, 0xD5};//日
unsigned char MH[]={0xA3, 0xBA};//冒号
unsigned char SW[]={ 0xCA,0xD2,0xCE, 0xC2};//室温

void setup()
{
// 启动I2C(IIC)接口
Wire.begin();
      //以下部分是初始化时间,每次板子通电之后都会初始化成这个时间,只是测试用,以后可以删除。
      Clock.setSecond(9);//Set the second
      Clock.setMinute(55);//Set the minute 设置分钟
      Clock.setHour(9);//Set the hour 设置小时
      Clock.setDoW(6);    //Set the day of the week 设置星期几
      Clock.setDate(17);//Set the date of the month 设置月份
      Clock.setMonth(11);//Set the month of the year 设置一年中的月份
      Clock.setYear(18);//Set the year (Last two digits of the year) 设置年份(在今年的最后两位数——比如2013年最后的13)
LCDA.Initialise();       // 屏幕初始化
}
void XQ()
{
   switch (dow)
   {
      case 1:
      LCDA.DisplayString(3,0,XQ1,6);      //如果可行换这一句
      break;
      case 2:
      LCDA.DisplayString(3,0,XQ2,6); ;//星期二
      break;
      case 3:
      LCDA.DisplayString(3,0,XQ3,6); ;//星期三
      break;
      case 4:
       LCDA.DisplayString(3,0,XQ4,6); ;//星期四
      break;
      case 5:
       LCDA.DisplayString(3,0,XQ5,6); ;//星期五
      break;
      case 6:
       LCDA.DisplayString(3,0,XQ6,6);//星期六
      break;
      case 7:
      LCDA.DisplayString(3,0,XQ1,7); ;//星期日
      break;
   
   //default:
}
}
void ReadDS3231()
{
se=Clock.getSecond();
mi=Clock.getMinute();
ho=Clock.getHour(h12, PM);
da=Clock.getDate();
mo=Clock.getMonth(Century);
ye=Clock.getYear();
tp=Clock.getTemperature();
dow=Clock.getDoW();
}
void loop()
{
ReadDS3231();

int yye=2000+ye;
dtostrf(yye,4,0,str);
LCDA.DisplayString(0,0,(unsigned char *)str,sizeof(str));
LCDA.DisplayString(0,2,N,4); //N
dtostrf(mo,0,0,str);
LCDA.DisplayString(0,3,(unsigned char *)str,sizeof(str));
LCDA.DisplayString(0,4,Y,2); //月
dtostrf(da,0,0,str);
LCDA.DisplayString(0,5,(unsigned char *)str,sizeof(str));
LCDA.DisplayString(0,6,R,2); //日

dtostrf(ho,0,0,str2);
LCDA.DisplayString(1,1,(unsigned char *)str2,sizeof(str2));
LCDA.DisplayString(1,2,MH,2); //冒号
dtostrf(mi,0,0,str2);
LCDA.DisplayString(1,3,(unsigned char *)str2,sizeof(str2));
LCDA.DisplayString(1,4,MH,2); //冒号
dtostrf(se,0,0,str2);
LCDA.DisplayString(1,5,(unsigned char *)str2,sizeof(str2));
//delay(500);
XQ();
LCDA.DisplayString(3,4,SW,4); //室温
dtostrf(tp,0,0,str2);
LCDA.DisplayString(3,6,(unsigned char *)str2,sizeof(str2));
LCDA.DisplayString(3,7,WDBZ,4); //温度标志
delay(1000);//间隔1000ms(1000ms=1秒)循环一次。
//LCDA.CLEAR();//清屏
}
页: [1]
查看完整版本: 关于LCD12864显示的问题