其他分享
首页 > 其他分享> > [arduino uno]NOKIA 5110屏幕的显示实验

[arduino uno]NOKIA 5110屏幕的显示实验

作者:互联网

1.需求
为后续制作桌面天气站准备,能够显示天气,室内温湿度,室外温湿度
2.要点
中文的显示,arduino uno较小的flash,中文字库需要按需剪裁
安装Adafruit_PCD8544库(NOKIA5110屏的驱动芯片)
3.代码
sketch_jan17a.ino

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define CLK 3
#define SDA 4
#define DC 5
#define CS 6
#define RST 7
Adafruit_PCD8544 display = Adafruit_PCD8544(CLK, SDA, DC, CS, RST);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#include "font.c"
static const unsigned char PROGMEM logo16_glcd_bmp_hu[2][16]={{0x01,0x00,0x01,0xF8,0x01,0x00,0x3F,0xFC,0x21,0x04,0x21,0x60,0x2F,0x88,0x21,0x08},
{0x20,0xF8,0x20,0x00,0x23,0xE0,0x22,0x20,0x22,0x20,0x44,0x24,0x48,0x24,0x90,0x1C}};/*"虎",0*/
static const unsigned char PROGMEM logo16_glcd_bmp_nian[2][16]={{0x10,0x00,0x10,0x00,0x1F,0xFC,0x20,0x80,0x20,0x80,0x40,0x80,0x1F,0xF8,0x10,0x80},
{0x10,0x80,0x10,0x80,0xFF,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}};/*"年",1*/
static const unsigned char PROGMEM logo16_glcd_bmp_zhou[]={0x10,0x04,0x10,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x54,0xA4,0x52,0x94,0x52,0x94,0x90,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x20,0x84,0x20,0x84,0x40,0x04,0x80,0x04};/*"州",0*/
static const unsigned char PROGMEM logo16_glcd_bmp_da[2][16]={{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00},
{0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,0x08,0x20,0x10,0x10,0x20,0x08,0xC0,0x06}};/*"大",0*/
static const unsigned char PROGMEM logo16_glcd_bmp_ji[2][16]={{0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8},
{0x00,0x00,0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10}};/*"吉",1*/
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h,uint8_t xpos,uint8_t ypos) {
uint8_t icons[NUMFLAKES][3];
//前两个参数是位置
display.drawBitmap(xpos, ypos, bitmap, w, h, BLACK);
display.display();

}
void print_temputure(void){
Serial.print("开始打印温度");
display.clearDisplay();
//display.drawBitmap(16,16,&*font[9],16,16,BLACK);
display.setCursor(0,16);//好像没用
/**城市***/
testdrawbitmap((uint8_t*)&_font[16], 16, 16,0,0);//广
testdrawbitmap((uint8_t*)&_font[18], 16, 16,16,0);//州
/**温度***/
testdrawbitmap((uint8_t*)&_font[20], 16, 16,0,16);//温
testdrawbitmap((uint8_t*)&_font[24], 16, 16,16,16);//度
testdrawbitmap((uint8_t*)&_font[11], 8, 16,32,16);//+
testdrawbitmap((uint8_t*)&_font[2], 8, 16,40,16);//2
testdrawbitmap((uint8_t*)&_font[0], 8, 16,48,16);//0
testdrawbitmap((uint8_t*)&_font[14], 16, 16,56,16);//ºC
/***湿度****/
testdrawbitmap((uint8_t*)&_font[22], 16, 16,0,32);//湿
testdrawbitmap((uint8_t*)&_font[24], 16, 16,16,32);//度
testdrawbitmap((uint8_t*)&_font[7], 8, 16,32,32);//7
testdrawbitmap((uint8_t*)&_font[0], 8, 16,40,32);//0
testdrawbitmap((uint8_t*)&_font[13], 8, 16,48,32);//%
display.display();
}
void print_indoors(void){
Serial.print("开始打印温度");
display.clearDisplay();
//display.drawBitmap(16,16,&*font[9],16,16,BLACK);
display.setCursor(0,16);//好像没用
/**城市***/
testdrawbitmap((uint8_t*)&_font[35], 16, 16,0,0);//室
testdrawbitmap((uint8_t*)&_font[37], 16, 16,16,0);//内
/**温度***/
testdrawbitmap((uint8_t*)&_font[20], 16, 16,0,16);//温
testdrawbitmap((uint8_t*)&_font[24], 16, 16,16,16);//度
testdrawbitmap((uint8_t*)&_font[11], 8, 16,32,16);//+
testdrawbitmap((uint8_t*)&_font[2], 8, 16,40,16);//2
testdrawbitmap((uint8_t*)&_font[2], 8, 16,48,16);//2
testdrawbitmap((uint8_t*)&_font[14], 16, 16,56,16);//ºC
/***湿度****/
testdrawbitmap((uint8_t*)&_font[22], 16, 16,0,32);//湿
testdrawbitmap((uint8_t*)&_font[24], 16, 16,16,32);//度
testdrawbitmap((uint8_t*)&_font[8], 8, 16,32,32);//8
testdrawbitmap((uint8_t*)&_font[0], 8, 16,40,32);//0
testdrawbitmap((uint8_t*)&_font[13], 8, 16,48,32);//%
display.display();
}
void print_weather(void){
Serial.print("开始打印天气");
display.clearDisplay();
//display.drawBitmap(16,16,&*font[9],16,16,BLACK);
display.setCursor(0,16);//好像没用
/**城市***/
testdrawbitmap((uint8_t*)&_font[16], 16, 16,0,0);//广
testdrawbitmap((uint8_t*)&_font[18], 16, 16,16,0);//州
/****天气现象****/
testdrawbitmap((uint8_t*)&_font[30], 16, 16,0,16);//多
testdrawbitmap((uint8_t*)&_font[32], 16, 16,16,16);//云
display.display();
}
void print_huniandaji(void){
display.clearDisplay();
testdrawbitmap(*logo16_glcd_bmp_hu, 16, 16,16,16);
testdrawbitmap((uint8_t*)&logo16_glcd_bmp_nian[0],16,16,32,16);
testdrawbitmap((uint8_t*)&logo16_glcd_bmp_da[0],16,16,48,16);
testdrawbitmap((uint8_t*)&logo16_glcd_bmp_ji[0],16,16,64,16);
display.display();
}
void switch_light(void){
while(Serial.available()){
if(Serial.read()=='t'){
digitalWrite(2, HIGH);
}
else if(Serial.read()=='f'){
digitalWrite(2,LOW);
}
}
}
void setup() {
pinMode(2,OUTPUT);
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("PCD test");
display.begin();
display.setContrast(50);//对比度
display.display(); // show splashscreen
delay(2000);
display.clearDisplay(); // clears the screen and buffer
while(1){
//switch_light();
print_huniandaji();
delay(2000);
print_temputure();
delay(5000);
print_weather();
delay(5000);
print_indoors();
delay(5000);
}
}


void loop() {
// put your main code here, to run repeatedly:

}

font.c

#include <avr/pgmspace.h>
#endif
/*PCtoLCD2002取模,设置顺序取模,逐行*/
//必须存放到"闪存"中,不然无法正确读取地址
const unsigned char PROGMEM _font[50][16]={
/*
0(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 0(10) +(11) -(12) %(13) ℃(14) 广(15)
州(16) 温(17) 湿(18) 度(19) 晴(20) 阴(21) 多(22) 云(23) .(24)
*/
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/

{0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",1*/

{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/

{0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00},/*"3",3*/

{0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00},/*"4",4*/

{0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/

{0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00},/*"6",6*/

{0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/

{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/

{0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00},/*"9",9*/

{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",10*/

{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x00,0x00,0x00,0x00},/*"+",11*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",12*/

{0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xB0,0x54,0x1A,0x2A,0x2A,0x4A,0x44,0x00,0x00},/*"%",13*/

{0x60,0x00,0x91,0xF4,0x96,0x0C,0x6C,0x04,0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00},
{0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x0C,0x04,0x06,0x08,0x01,0xF0,0x00,0x00},/*"℃",14*/

{0x01,0x00,0x00,0x80,0x00,0x80,0x3F,0xFC,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00},
{0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x80,0x00},/*"广",15*//*第17行*/

{0x10,0x04,0x10,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x54,0xA4,0x52,0x94,0x52,0x94},
{0x90,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x20,0x84,0x20,0x84,0x40,0x04,0x80,0x04},/*"州",16*/

{0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8},
{0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00},/*"温",17*/

{0x00,0x00,0x27,0xF8,0x14,0x08,0x14,0x08,0x87,0xF8,0x44,0x08,0x44,0x08,0x17,0xF8},
{0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x20,0x2F,0xFE,0x00,0x00},/*"湿",18*/

{0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20},
{0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E},/*"度",19*/

{0x00,0x20,0x00,0x20,0x7B,0xFE,0x48,0x20,0x49,0xFC,0x48,0x20,0x4B,0xFE,0x78,0x00},
{0x49,0xFC,0x49,0x04,0x49,0xFC,0x49,0x04,0x79,0xFC,0x49,0x04,0x01,0x14,0x01,0x08},/*"晴",20*/

{0x00,0x00,0x7D,0xFC,0x45,0x04,0x49,0x04,0x49,0x04,0x51,0xFC,0x49,0x04,0x49,0x04},
{0x45,0x04,0x45,0xFC,0x45,0x04,0x69,0x04,0x52,0x04,0x42,0x04,0x44,0x14,0x48,0x08},/*"阴",21*//*第29行*/

{0x02,0x00,0x02,0x00,0x07,0xF0,0x08,0x20,0x38,0x40,0x04,0x80,0x03,0x40,0x0C,0x80},
{0x71,0xF8,0x02,0x08,0x0C,0x10,0x32,0x20,0x01,0x40,0x01,0x80,0x0E,0x00,0x70,0x00},/*"多",22*/

{0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x02,0x00},
{0x04,0x00,0x04,0x00,0x08,0x40,0x10,0x20,0x20,0x10,0x7F,0xF8,0x20,0x08,0x00,0x08},/*"云",23*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00},/*".",24*/
 
{0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x3F,0xF8,0x04,0x00,0x08,0x20},
{0x1F,0xF0,0x01,0x10,0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00},/*"室",0*//*第36行*/

{0x01,0x00,0x01,0x00,0x01,0x00,0x7F,0xFC,0x41,0x04,0x41,0x04,0x41,0x04,0x42,0x84},
{0x42,0x44,0x44,0x24,0x48,0x14,0x50,0x14,0x40,0x04,0x40,0x04,0x40,0x14,0x40,0x08}/*"内",1*/
};

4.效果图

5.[分享]取字模软件及本例中的设置

PCtoLCD2002

标签:5110,16,0x04,arduino,0x20,NOKIA,0x00,0x10,0x42
来源: https://www.cnblogs.com/qsbye/p/16542297.html