С дисплеем нокиа3410.
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <Wire.h>
#include "TinyBME280.h"
// Nokia LCD pin numbers
#define LCD_MOSI PINB2 //DIN,SDA,data
#define LCD_SCK PINB4 //CLK,SCL,clock
#define LCD_CD PINB1 //DC, D/C
#define LCD_RESET PINB0 //Res,reset
/*pin CS подключить на GND
pin Vout через конденсатор на GND */
/** Number of columns */
#define LCD_COL 96 //for Nokia 3310-84
/** Number of text rows */
#define LCD_ROW 10 //for Nokia 3310-6
int const sda = PB5;//pin 17
int const scl = PB7;//pin 19
extern const uint8_t SMALL_FONT[] PROGMEM;
const uint8_t SMALL_FONT[] PROGMEM = {
0x7C, 0x82, 0x82, 0x82, 0x7C, // 30 0
0x00, 0x84, 0xFE, 0x80, 0x00, // 31 1
0x84, 0xC2, 0xA2, 0x92, 0x8C, // 32 2
0x42, 0x82, 0x8A, 0x96, 0x62, // 33 3
0x30, 0x28, 0x24, 0xFE, 0x20, // 34 4
0x4E, 0x8A, 0x8A, 0x8A, 0x72, // 35 5
0x7C, 0x92, 0x92, 0x92, 0x64, // 36 6
0x02, 0xE2, 0x12, 0x0A, 0x06, // 37 7
0x6C, 0x92, 0x92, 0x92, 0x6C, // 38 8
0x4C, 0x92, 0x92, 0x92, 0x7C, // 39 9
0x00, 0x60, 0x60, 0x00, 0x00, // .
0x01, 0x01, 0x7F, 0x01, 0x01,// т
0x7F, 0x49, 0x49, 0x49, 0x41,//e
0xFF, 0x02, 0x0C, 0x02, 0xFF,//м
0x7F, 0x01, 0x01, 0x01, 0x7F,//п
0x7F, 0x09, 0x09, 0x09, 0x06,//p
0x07, 0x48, 0x48, 0x48, 0x3F,//у
0x7C, 0x12, 0x11, 0x12, 0x7C,//a
0x00, 0x0C, 0x12, 0x12, 0x0C,//gradus
0x3E, 0x41, 0x41, 0x41, 0x22,//c
0x7F, 0x49, 0x49, 0x49, 0x36,//в
0x40, 0x3E, 0x01, 0x01, 0x7F,//л
0x77, 0x08, 0x7F, 0x08, 0x77,//ж
0x7F, 0x08, 0x08, 0x08, 0x7F,//H
0x00, 0x7F, 0x48, 0x48, 0x30,//Ь
0x46, 0x26, 0x10, 0xC8, 0xC4,//%
0x60, 0x3F, 0x21, 0x3F, 0x60,//д
0x7F, 0x10, 0x08, 0x04, 0x7F,//и
0xF8, 0x20, 0x50, 0x88, 0x00,//к
0x3E, 0x41, 0x41, 0x41, 0x3E,//о
0xFE, 0x02, 0x02, 0x02, 0xFE,//п
0x40, 0xA8, 0xA8, 0xA8, 0xF0,//a
0x7C, 0x82, 0x82, 0x82, 0x44,//c
};
void setup() {
uint8_t val = (1 << LCD_SCK) | (1 << LCD_MOSI) | (1 << LCD_RESET) | (1 << LCD_CD);
PORTB &= ~val;
DDRB |= val;
PORTB |= (1 << LCD_RESET);
lcdCommand(0x21); // LCD Extended Commands.
lcdCommand(0xA1); // Set LCD Vop (Contrast).
lcdCommand(0x04); // Set Temp coefficent.
lcdCommand(0x14); // LCD bias mode 1:48.
lcdCommand(0x20); // LCD Normal commands
lcdCommand(0x0C); // Normal display, horizontal addressing
// clear nokia LCD
lcdCommand(0x80);
lcdCommand(0x40);
// Fill in the whole display with ZEROS
for(uint16_t index = 0; index < (LCD_COL * LCD_ROW); index++)
lcdData(0x00);
Wire.begin();
BME280setI2Caddress(0x76);
BME280setup();
}
void loop() {
int t = BME280temperature();
int p = BME280pressure()/100;
int h = BME280humidity();
lcdPrintChar(0, 22,26);//д
lcdPrintChar(0, 29,17);//а
lcdPrintChar(0, 36,20);//в
lcdPrintChar(0, 43,21);//л
lcdPrintChar(0, 50,12);//е
lcdPrintChar(0, 57,23);//н
lcdPrintChar(0, 64,27);//и
lcdPrintChar(0, 71,12);//е
lcdPrintChar(1,26,p/ 1000);
lcdPrintChar(1,33,(p/100) % 10);
lcdPrintChar(1,40,(p/ 10) % 10);
lcdPrintChar(1,47,p % 10);
lcdPrintChar(1, 54,28);//к
lcdPrintChar(1, 61,30);//п
lcdPrintChar(1, 68,31);//а
lcdPrintChar(3, 8, 11);//т
lcdPrintChar(3, 15,12);//е
lcdPrintChar(3, 22,13);//м
lcdPrintChar(3, 29,14);//п
lcdPrintChar(3, 36,12);//е
lcdPrintChar(3, 43,15);//р
lcdPrintChar(3, 50,17);//а
lcdPrintChar(3, 57,11);//т
lcdPrintChar(3, 64,16);//у
lcdPrintChar(3, 71,15);//р
lcdPrintChar(3, 78,17);//а
lcdPrintChar(4,26,t/ 1000);
lcdPrintChar(4,33,(t/ 100) % 10);
lcdPrintChar(4,40,10);
lcdPrintChar(4,45,(t/ 10) % 10);
// lcdPrintChar(4,54, t % 10);
lcdPrintChar(4,52, 18);
lcdPrintChar(4,59, 32);
lcdPrintChar(6, 15,20);//в
lcdPrintChar(6, 22,21);//л
lcdPrintChar(6, 29,17);//а
lcdPrintChar(6, 36,22);//ж
lcdPrintChar(6, 43,23);//н
lcdPrintChar(6, 50,29);//0
lcdPrintChar(6, 57,19);//с
lcdPrintChar(6, 64,11);//т
lcdPrintChar(6, 71,24);//ь
lcdPrintChar(7,26,h/1000 % 10);
lcdPrintChar(7,33,(h/100) % 10);
lcdPrintChar(7,40,10);
lcdPrintChar(7,45,(h/10) % 10);
// lcdPrintChar(7,54,h % 10);
lcdPrintChar(7,52,25);//%
}
void sspiOutMSB(uint8_t sck, uint8_t mosi, uint16_t data, uint8_t bits) {
uint16_t mask = (1 << (bits - 1));
uint8_t output = (1 << mosi);
uint8_t clock = (1 << sck);
while(bits) {
// Set data
if(data&mask)
PORTB |= output;
else
PORTB &= ~output;
// Bring the clock high
PORTB |= clock;
// Move to the next bit
mask = mask >> 1;
bits--;
// Bring the clock low again
PORTB &= ~clock;
}
}
void lcdData(uint8_t data) {
// Bring CD high
PORTB |= (1 << LCD_CD);
// Send the data
sspiOutMSB(LCD_SCK, LCD_MOSI, data, 8);
}
/** Send a command byte to the LCD
*
* @param cmd the command byte to send.
*/
void lcdCommand(uint8_t cmd) {
// Bring CD low
PORTB &= ~(1 << LCD_CD);
// Send the data
sspiOutMSB(LCD_SCK, LCD_MOSI, cmd, 8);
}
/** Write a single character
*/
void lcdPrintChar(uint8_t row, uint8_t col, uint8_t ch) {
// Set the starting address
const uint8_t *chdata = SMALL_FONT + (ch * 5);
lcdCommand(0x80 | col);
lcdCommand(0x40 | (row % LCD_ROW));
// And send the column data
for(uint8_t pixels = 0; pixels < 5; pixels++, chdata++) {
uint8_t data = pgm_read_byte_near(chdata);
lcdData(data);
// for double sized font put
// lcdData(data);
};
// Add the padding byte
//if(col < LCD_COL)
lcdData(0x00);
}