准备材料
- Arduino UNO *1
- Nokia 5110 LCD *1
- 跳线 若干
接线
Nokia 5110 | Arduino | |
---|---|---|
RST | -> | 6 |
CE | -> | 7 |
DC | -> | 5 |
DIN | -> | 4 |
CLK | -> | 3 |
VCC | -> | 5V |
BL | -> | 3V3 |
GND | -> | GND |
加载库文件
到http://www.rinkydinkelectronics.com/download.php?f=LCD5110_Basic.zip下载LCD5110的库文件,在Arduino IDE中,点击项目
->加载库
->添加一个.zip库
,选择下载好的LCD5110_Basic.zip
库文件即可。
示例程序
#include <LCD5110_Basic.h>
LCD5110 myGLCD(3,4,5,6,7);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
void setup()
{
myGLCD.InitLCD(); //Intializing LCD
}
void loop()
{
myGLCD.setFont(SmallFont);
myGLCD.print("Hello World",CENTER,16);
delay(1000);
myGLCD.clrScr();
}
常用函数
- LCD5110(SCK,MOSI,DC,RST,CS);//设置引脚
Usage: LCD5110 myGLCD(8,9,10,11,12); - InitLCD([contrast]);//初始化
Usage:myGLCD.initLCD(); - setContrast(contrast);//设置对比度(0-127)
Usage:myGLCD.setContrast(70); - enableSleep();//设置睡眠状态
Usage:myGLCD.enableSleep(); - disableSleep();//关闭睡眠状态
Usage:myGLCD.disableSleep(); - clrScr();//清屏
Usage:myGLCD.clrScr(); - clrRow(row[,start_x[,end_x]]);//清除行的一部分或者整行
Usage:myGLCD.clrRow(5,42); - invert(mode);//倒置
Usage:myGLCD.invert(true); - print(st,x,y);//显示字符串
Usage:myGLCD.print("Hello Wrold", CENTER, 0); - printNumI(num,x,y[,length[,filler]]);//显示整数
Usage:myGLCD.printNumI(num, CENTER, 0); - printNumF(num,dec,x,y[,divider[,length[,filler]]]);//显示小数
Usage:myGLCD.printNumF(num, 3,CENTER, 0); - setFont(fontname);//设置字体大小
Usage:myGLCD.setFont(SmallFont); - drawBitmap(x,y,data,sx,sy);//用于显示自定义字符
Usage:myGLCD.drawBitmap(0,0,bitmap,32,32);