在线时间68 小时
UID3090366
注册时间2015-5-24
NXP金币71
TA的每日心情 | 开心 2018-1-30 19:52 |
---|
签到天数: 19 天 连续签到: 1 天 [LV.4]偶尔看看III
金牌会员
 
- 积分
- 1514
- 最后登录
- 2018-5-28
|

楼主 |
发表于 2016-9-3 13:47:01
|
显示全部楼层
四、LCD5110部分程序,带6x8字库
- /*
- * lcd5110.h
- *
- * Created on: Sep 2, 2016
- * Author: Administrator
- */
- #ifndef LCD5110_H_
- #define LCD5110_H_
- #include "font6x8.h"
- #include "Delay.h"
- #include "LED.h"
- #include "SCLK.h"
- #include "DIN.h"
- #include "DC.h"
- #include "RST.h"
- #include "SCE.h"
- #define HIGH TRUE
- #define LOW FALSE
- #define LCD_COMMAND 0
- #define LCD_DATA 1
- #define LCD5110_CS(state) (SCE_PutVal(state))
- #define LCD5110_RST(state) (RST_PutVal(state))
- #define LCD5110_DC(state) (DC_PutVal(state))
- #define LCD5110_DIN(state) (DIN_PutVal(state))
- #define LCD5110_SCK(state) (SCLK_PutVal(state))
- #define LCD5110_LED(state) (LED_PutVal(state))
- void LCD5110_init(void);
- void LCD5110_write_char(uint8_t c);
- void LCD5110_write_char_inv(uint8_t c);
- void LCD5110_clear(void);
- void LCD5110_set_XY(uint8_t X, uint8_t Y);
- void LCD5110_write_string(uint8_t *s);
- void LCD5110_write_Dec(uint16_t buffer);
- #endif /* LCD5110_H_ */
复制代码
- /*
- * lcd5110.c
- *
- * Created on: Sep 2, 2016
- * Author: Administrator
- */
- #include "lcd5110.h"
- void LCD5110_LCD_write_byte(uint8_t dat, uint8_t LCD5110_MOde);
- /**
- * Initialize LCD module
- *
- * Input parameters : none
- * Return value : none
- */
- void LCD5110_init(void)
- {
- // Set pin initial state
- LCD5110_LED(0); //Turn back light off
- LCD5110_RST(0); //Set LCD reset = 0;
- LCD5110_DC(1); //Mode = command;
- LCD5110_DIN(1); //Set In at high level;
- LCD5110_SCK(1); //Set CLK high;
- LCD5110_CS(1); //Unselect chip;
- //Keep reset pin low for 10 ms
- Delay(10);
- //Release Reset Pin
- LCD5110_RST(1); //LCD_RST = 1;
- //Configure LCD module
- LCD5110_LCD_write_byte(0x21, LCD_COMMAND); //Extended instruction set selected
- LCD5110_LCD_write_byte(0xB7, LCD_COMMAND); //Set LCD voltage (defined by experimentation...)
- LCD5110_LCD_write_byte(0x14, LCD_COMMAND); //Set Bias for 1/48
- LCD5110_LCD_write_byte(0x06, LCD_COMMAND); //Set temperature control (TC2)
- LCD5110_LCD_write_byte(0x20, LCD_COMMAND); //Revert to standard instruction set
- LCD5110_clear(); //Clear display (still off)
- LCD5110_LCD_write_byte(0x0c, LCD_COMMAND); //Set display on in "normal" mode (not inversed)
- }
- /**
- * Write byte to the module.
- *
- * @param dat data to write
- * @param mode 0 if command, 1 if data
- *
- * @retval None
- */
- void LCD5110_LCD_write_byte(uint8_t dat, uint8_t mode)
- {
- uint8_t i;
- LCD5110_CS(0); //SPI_CS = 0;
- if (0 == mode)
- LCD5110_DC(0); //LCD_DC = 0;
- else
- LCD5110_DC(1); //LCD_DC = 1;
- for (i = 0; i < 8; i++) {
- LCD5110_DIN(dat & 0x80); //SPI_MO = dat & 0x80;
- dat = dat << 1;
- LCD5110_SCK(0); //SPI_SCK = 0;
- LCD5110_SCK(1); //SPI_SCK = 1;
- }
- LCD5110_CS(1); //SPI_CS = 1;
- }
- /**
- * Write character to LCD at current position
- *
- * @param c: char to write
- * @retval None
- */
- void LCD5110_write_char(uint8_t c) {
- uint8_t line;
- uint8_t ch = 0;
- c = c - 32;
- for (line = 0; line < 6; line++) {
- ch = font6_8[c][line];
- LCD5110_LCD_write_byte(ch, LCD_DATA);
- }
- }
- /**
- * Write character to LCD in inverse video at current location
- *
- * @param c: char to write
- * @retval None
- */
- void LCD5110_write_char_inv(uint8_t c) {
- uint8_t line;
- uint8_t ch = 0;
- c = c - 32;
- for (line = 0; line < 6; line++) {
- ch = ~font6_8[c][line];
- LCD5110_LCD_write_byte(ch, LCD_DATA);
- }
- }
- /**
- * Write string to LCD at current position. String must be null terminated.
- *
- * @param s: string pointer
- * @retval None
- */
- void LCD5110_write_string(uint8_t *s) {
- uint8_t ch;
- while (*s != '\0') {
- ch = *s;
- LCD5110_write_char(ch);
- s++;
- }
- }
- /**
- * Clear display. Write 0 in all memory location.
- *
- * @param None
- * @retval None
- */
- void LCD5110_clear() {
- uint8_t i, j;
- for (i = 0; i < 6; i++)
- for (j = 0; j < 84; j++)
- LCD5110_LCD_write_byte(0, LCD_DATA);
- }
- /**
- * Set memory current location for characters (set coordinates).
- * Applies only for Fonts with a 6 pixels width.
- *
- * @param X: Column (range from 0 to 13)
- * @param Y: Row (range from 0 to 5)
- * @retval None
- *
- */
- void LCD5110_set_XY(uint8_t X, uint8_t Y) {
- uint8_t x;
- x = 6 * X;
- LCD5110_LCD_write_byte(0x40 | Y, LCD_COMMAND);
- LCD5110_LCD_write_byte(0x80 | x, LCD_COMMAND);
- }
- /**
- * Write integer to LCD
- *
- * @param b: integer to write
- * @retval None
- */
- void LCD5110_Write_Dec(uint16_t b) {
- uint8_t datas[3];
- datas[0] = b / 1000;
- b = b - datas[0] * 1000;
- datas[1] = b / 100;
- b = b - datas[1] * 100;
- datas[2] = b / 10;
- b = b - datas[2] * 10;
- datas[3] = b;
- datas[0] += 48;
- datas[1] += 48;
- datas[2] += 48;
- datas[3] += 48;
- LCD5110_write_char(datas[0]);
- LCD5110_write_char(datas[1]);
- LCD5110_write_char(datas[2]);
- LCD5110_write_char(datas[3]);
- }
复制代码
- /*
- * font6x8.h
- *
- * Created on: Sep 3, 2016
- * Author: Administrator
- */
- #ifndef FONT6X8_H_
- #define FONT6X8_H_
- #include "stdint.h"
- extern uint8_t font6_8[][6];
- #endif /* FONT6X8_H_ */
复制代码
- /*
- * font6x8.c
- *
- * Created on: Sep 3, 2016
- * Author: Administrator
- */
- #include "font6x8.h"
- uint8_t font6_8[][6] =
- {
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
- { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
- { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
- { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
- { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
- { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
- { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
- { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
- { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
- { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
- { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
- { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
- { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
- { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
- { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
- { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
- { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
- { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
- { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
- { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
- { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
- { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
- { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
- { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
- { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
- { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
- { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
- { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
- { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
- { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
- { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
- { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
- { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
- { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
- { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
- { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
- { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
- { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
- { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
- { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
- { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
- { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
- { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
- { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
- { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
- { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
- { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
- { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
- { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
- { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
- { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
- { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
- { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
- { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
- { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
- { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
- { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
- { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
- { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
- { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
- { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
- { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
- { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
- { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
- { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
- { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
- { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
- { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
- { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
- { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
- { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
- { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
- { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
- { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
- { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
- { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
- { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
- { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
- { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
- { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
- { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
- { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
- { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
- { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
- { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
- { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
- { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
- { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
- { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
- { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
- { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
- { 0x00,0x00, 0x06, 0x09, 0x09, 0x06 } // horiz lines
- };
复制代码
|
|