目录
准备工作
翻出在老王家购买的ST7565液晶屏,就折腾它了。
树莓派使用wiringPi库,像这样就可以控制GPIO上的LED闪烁,很简单对吧?
#include <wiringpi.h>
#define LED 25
int main(void)
{
if(wiringPiSetup() < 0)return 1;
pinMode (LED,OUTPUT) ;
while(1)
{
digitalWrite(LED, 1) ;
delay (200);
digitalWrite(LED, 0) ;
delay (200);
}
}
gcc led.c –o led -lwiringPi #编译
sudo ./led #运行
屏幕已经在STM32上运行过几次,自己整理出了库文件,库文件由三个文件组成
- fonts.h 字库文件,16*16汉字字形和8*16汉字字形
- ST7565.c 控制LCD的接口函数
- ST7565.h 头文件,可以在此修改引脚的宏定义
准备工作就到这里,开干
修改程序
ST7565.h中,修改宏定义,将#define Set_CS HAL_GPIO_WritePin(GPIOA,GPIO_PIN9_GPIO_PIN_SET)类似的宏定义语句注释掉,这是STM32HAL库的IO口操作函数,我们要更换成wiringPi库的IO口操作函数。且include也要修改。#include <stdint.h>是因为程序里面使用了类似uin8_t或者uint16_t类似的数据类型定义,在linux环境下包含这个头文件可以正确识别这些定义。改动后的头文件大致如下
#include <wiringPi.h>
#include <stdint.h>
#define SDA 25
#define SCL 24
#define RS 29 //A0 命令和数据切换
#define CS 28
#define RES 21
#define Set_SDA digitalWrite(SDA,1)
#define Reset_SDA digitalWrite(SDA,0)
#define Set_SCK digitalWrite(SCL,1)
#define Reset_SCK digitalWrite(SCL,0)
#define SetR_S digitalWrite(RS,1)
#define Reset_R_S digitalWrite(RS,0)
#define Set_CS digitalWrite(CS,1)
#define Reset_CS digitalWrite(CS,0)
#define Set_RES digitalWrite(RES,1)
#define Reset_RES digitalWrite(RES,0)
在ST7565.c中修改,新增GPIO初始化函数,修改Delayms函数,新增main.c函数
改动如下
void Delayms(uint16_t ms)
{
//HAL_Delay(ms);
usleep(ms * 20);
}
void gpio_intit(void)
{
if(wiringPiSetup() < 0)
printf("init wiringPiSetp error\r\n");
pinMode(SDA,OUTPUT);
pinMode(SCL,OUTPUT);
pinMode(RS,OUTPUT);
pinMode(CS,OUTPUT);
pinMode(RES,OUTPUT);
}
int main(void)
{
gpio_intit();
LcdInit();
disp_str_color("欢迎",0,0,0);
disp_str_color("Hello World !",0,2,0);
return 0;
}
然后运行指令
gcc -o ST7565 ST7565.c -lwiringPi #编译
./ST7565 #运行
运行效果
就可以在屏幕上看到如下画面啦
提示
ST7565库使用GB2312编码格式,在树莓派上编辑会乱码,我的解决方案是用树莓派系统的Geany编辑代码
在这个菜单选项选择编码
再点击这个按钮重新载入文件就可以正常编辑GB2312文件啦
字模可以按照自己喜欢添加,取模软件设置如下
完整代码
fonts.h
#ifndef __FONTS_H
#define __FONTS_H
typedef struct
{
unsigned char Index[2];
char Msk[32];
}typFNT_GB16;
const typFNT_GB16 GB_16[] = {
"欢", 0x04,0x34,0xC4,0x04,0xC4,0x3C,0x20,0x10,0x0F,0xE8,0x08,0x08,0x28,0x18,0x00,0x00,
0x10,0x08,0x06,0x01,0x82,0x8C,0x40,0x30,0x0C,0x03,0x0C,0x10,0x60,0xC0,0x40,0x00,
"迎", 0x40,0x42,0x44,0xC8,0x00,0xFC,0x04,0x02,0x82,0xFC,0x04,0x04,0x04,0xFE,0x04,0x00,
0x00,0x40,0x20,0x1F,0x20,0x47,0x42,0x41,0x40,0x7F,0x40,0x42,0x44,0x63,0x20,0x00,
"显", 0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x00,
0x40,0x42,0x44,0x4D,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x49,0x44,0x66,0x40,0x00,
"示", 0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x43,0x42,0x60,0x40,0x00,
0x00,0x10,0x08,0x04,0x06,0x40,0x80,0x7F,0x00,0x00,0x02,0x04,0x0C,0x18,0x00,0x00,
"汉", 0x10,0x22,0x64,0x0C,0x80,0x04,0x74,0x84,0x04,0x04,0x04,0xC4,0x3E,0x04,0x00,0x00,
0x04,0x04,0x7E,0x01,0x80,0x40,0x20,0x11,0x0A,0x04,0x0B,0x10,0x60,0xC0,0x40,0x00,
"字", 0x00,0x10,0x0C,0x24,0x24,0x24,0x25,0x26,0xA4,0x64,0x24,0x04,0x14,0x0C,0x00,0x00,
0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x03,0x02,0x00,
"测", 0x10,0x22,0x6C,0x00,0x80,0xFC,0x04,0xF4,0x04,0xFE,0x04,0xF8,0x00,0xFE,0x00,0x00,
0x04,0x04,0xFE,0x01,0x40,0x27,0x10,0x0F,0x10,0x67,0x00,0x47,0x80,0x7F,0x00,0x00,
"试", 0x40,0x42,0xCC,0x00,0x10,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x12,0x14,0x10,0x00,
0x00,0x00,0x7F,0x20,0x10,0x20,0x60,0x3F,0x10,0x10,0x01,0x3E,0x40,0x80,0x70,0x00,
"油", 0x10,0x60,0x02,0x8C,0x00,0xF0,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x04,0x04,0x7E,0x01,0x00,0xFF,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0xFF,0x00,0x00,/*"油",0*/
"门", 0x00,0xF8,0x01,0x06,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,/*"门",1*/
"系", 0x00,0x00,0x22,0x32,0x2A,0xA6,0xA2,0x62,0x21,0x11,0x09,0x81,0x01,0x00,0x00,0x00,
0x00,0x42,0x22,0x13,0x0B,0x42,0x82,0x7E,0x02,0x02,0x0A,0x12,0x23,0x46,0x00,0x00,/*0*/
"统", 0x20,0x30,0xAC,0x63,0x30,0x00,0x88,0xC8,0xA8,0x99,0x8E,0x88,0xA8,0xC8,0x88,0x00,
0x22,0x67,0x22,0x12,0x12,0x80,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x40,0x71,0x00,/*1*/
"温", 0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,/*2*/
"度", 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,/*3*/
"℃", 0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,
0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00,/*0*/
};
typedef struct
{
char Index[1];
char Msk[16];
}typFNT_ASC16 ;
const typFNT_ASC16 ASC_16[] =
{
"1",0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,/*"1",0*/
"2",0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",0*/
"3",0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,/*"3",1*/
"4",0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,/*"4",2*/
"5",0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,/*"5",3*/
"6",0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,/*"6",4*/
"7",0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,/*"7",5*/
"8",0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",6*/
"9",0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,/*"9",7*/
"0",0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",8*/
"%",0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,/*"%",0*/
".",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,/*".",0*/
"a",0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,
"b",0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,
"c",0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,
"d",0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,
"e",0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,
"f",0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
"g",0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,
"h",0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,
"i",0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
"j",0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,
"k",0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,
"l",0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
"m",0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,
"n",0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,
"o",0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,
"p",0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,
"q",0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,
"r",0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,
"s",0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,
"t",0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,
"u",0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,
"v",0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,
"w",0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,
"x",0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,
"y",0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,
"z",0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,
"A",0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,/*0*/
"B",0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,/*1*/
"C",0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,/*2*/
"D",0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,/*3*/
"E",0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,/*4*/
"F",0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,/*5*/
"G",0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,/*6*/
"H",0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,/*7*/
"I",0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*8*/
"J",0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,/*9*/
"K",0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,/*10*/
"L",0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,/*11*/
"M",0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,/*12*/
"N",0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,/*13*/
"O",0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,/*14*/
"P",0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,/*15*/
"Q",0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,/*16*/
"R",0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,/*17*/
"S",0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,/*18*/
"T",0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,/*19*/
"U",0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,/*20*/
"V",0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,/*21*/
"W",0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,/*22*/
"X",0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,/*23*/
"Y",0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,/*24*/
"Z",0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,/*25*/
};
#endif
ST7565.c
#include "ST7565.h"
#include "fonts.h"
/*---------------------------延时函数----------------------------------------------*/
void Delayms(uint16_t ms)
{
//HAL_Delay(ms);
delay(ms);
}
/*---------------------------------------------------------------------------------*/
/*----------------------------写命令函数-------------------------------------------*/
void Comwrite(uint8_t cmd)
{
uint8_t i,j;
Reset_CS; //CS1=0;
Reset_R_S; //R_S=0;
Set_SCK; //SCK=1;
for(i=0;i<8;i++)
{
j=cmd;
Reset_SCK; // SCK=0;
if(cmd&0x80)Set_SDA; //SDA=cmd&0x80;
else Reset_SDA;
Set_SCK; //SCK=1;
cmd=j<<1;
}
Set_CS; // CS1=1;
SetR_S; //R_S=1;
}
/*---------------------------------------------------------------------------------*/
/*-------------------------写像素点函数【带反显】----------------------------------*/
void Datwrite_color(uint8_t dat,uint8_t Color)
{
uint8_t i,j;
Reset_CS; // CS1=0;
SetR_S; //R_S=1;
Set_SCK; // SCK=1;
if(Color==0)
{
for(i=0;i<8;i++)
{
j=dat;
Reset_SCK; // SCK=0;
if(dat&0x80)Set_SDA; //SDA=cmd&0x80; Set_SDA
else Reset_SDA; // Reset_SDA
Set_SCK; //SCK=1;
dat=j<<1;
}
}
else
{
for(i=0;i<8;i++)
{
j=dat;
Reset_SCK; // SCK=0;
if(dat&0x80)Reset_SDA; //SDA=cmd&0x80; Set_SDA
else Set_SDA; // Reset_SDA
Set_SCK; //SCK=1;
dat=j<<1;
}
}
Set_CS; //CS1=1;
Reset_R_S; // R_S=0;
}
/*---------------------------------------------------------------------------------*/
/*--------------------------设置地址函数--------------------------------------------*/
void Setadd(uint8_t xl,uint8_t yl)
{
uint8_t i;
xl+=4;
i=(xl+0)&0x0f;
xl=(xl>>4)+0x10;
Comwrite(0xb0+yl);
Comwrite(xl);
Comwrite(i);
}
/*---------------------------------------------------------------------------------*/
/*-------------------------清屏函数------------------------------------------------*/
void Clear(void)
{
uint8_t i,j;
for(i=0;i<8;i++)
{
Setadd(0,i);
for(j=0;j<128;j++)
Datwrite_color(0x00,0);
}
}
/*---------------------------------------------------------------------------------*/
/*-------------------------------初始化函数----------------------------------------*/
void LcdInit(void)
{
Reset_RES;//RES=0;
Delayms(50);
Set_RES; //RES=1;
Delayms(20);
Comwrite(0xe2); //复位
Comwrite(0xa1); // 左右 A0:反向 A1:正向
Comwrite(0xc0); // 上下 C0 正向,C8反向
// Comwrite(0xA0); // 左右 A0:反向 A1:正向
// Comwrite(0xc8); // 上下 C0 正向,C8反向
Comwrite(0x2f); //开关内部电源
Comwrite(0x27); // 27
Comwrite(0xaf); // 开启
Comwrite(0x40); // dizhi 设定显示起始坐标 用于上下滚屏使用
Comwrite(0xc8); // dizhi
Comwrite(0xa6); //A6正常显示 A7反白显示
Comwrite(0xa4); //A4正常模式? A5全屏显示
Comwrite(0xa2); //A3 1/7偏置设置 A21/9偏执设置 A3
Comwrite(0x81); //
Comwrite(0x06); //
Comwrite(0xf8); //
Comwrite(0x3);
Clear();
}
/*---------------------------------------------------------------------------------*/
void disp_ch_color(unsigned char c,uint8_t uCol,uint8_t uPage,uint8_t Color)
{
unsigned char k,j,ch_w;
unsigned char width;
unsigned char len;
len=sizeof(ASC_16)/sizeof(ASC_16[0]);
for(k=0;k<len;k++)
{
if(c == ASC_16[k].Index[0] ) break;
}
if(k<len)
{
if(c=='-'||c==':')
width=ASC_CHR_WIDTH-2;
else if(c=='|')
width=ASC_HZ_WIDTH-ASC_CHR_WIDTH;
else
width=ASC_CHR_WIDTH;
Setadd(uCol,uPage);
for(j=0;j<width;j++)
{
ch_w=ASC_16[k].Msk[j];
Datwrite_color(ch_w,Color);
}
Setadd(uCol,uPage+1);
for(j=0;j<width;j++)
{
ch_w=ASC_16[k].Msk[ASC_CHR_WIDTH+j];
Datwrite_color(ch_w,Color);
}
}
}
void disp_hz_color(uint8_t *hz,uint8_t uCol,uint8_t uPage,uint8_t Color)
{
unsigned char k,j,ch_w;
//sizeof 用来求一个变量或者一种类型所占用的字节数
for(k=0;k<sizeof(GB_16)/sizeof(GB_16[0]);k++)
{
if(hz[0] == GB_16[k].Index[0] && hz[1] == GB_16[k].Index[1])
break;
}
Setadd(uCol,uPage);
for(j=0;j<ASC_HZ_WIDTH;j++)
{
ch_w=GB_16[k].Msk[j];
Datwrite_color(ch_w,Color);
}
Setadd(uCol,uPage+1);
for(j=0;j<ASC_HZ_WIDTH;j++)
{
ch_w=GB_16[k].Msk[ASC_HZ_WIDTH+j];
Datwrite_color(ch_w,Color);
}
}
/*-----------------------------------------------------------------------------------
显示函数,可以解析中英文字符串,在fonts.h中寻找字模,如果不存在则显示空白
*p 字符串
uCol x轴坐标 0 - 127 【一个字占用32】
uPage y轴坐标 0 - 8 【一个字占用两个值】
Color 字体颜色 【0正显,1反显】
-----------------------------------------------------------------------------------*/
void disp_str_color(uint8_t *p,uint8_t uCol,uint8_t uPage,uint8_t Color)
{
unsigned char i=0;
while(p[i]>0)
{
if(p[i] < 128)
{
disp_ch_color(p[i],uCol,uPage,Color);
uCol+=8;
}
else
{
disp_hz_color(&p[i],uCol,uPage,Color);
uCol+=16;
i++;
}
// if(Flage1==1) Delayms(200);
i++;
}
}
void gpio_intit(void)
{
wiringPiSetup();
pinMode(SDA,OUTPUT);
pinMode(SCL,OUTPUT);
pinMode(RS,OUTPUT);
pinMode(CS,OUTPUT);
pinMode(RES,OUTPUT);
}
int main(void)
{
gpio_intit();
LcdInit();
disp_str_color("欢迎",0,0,0);
disp_str_color("Hello World",0,2,0);
}
ST7565.h
#ifndef __ST7565_H
#define __ST7565_H
#include <wiringPi.h>
#include <stdint.h>
#define SDA 25
#define SCL 24
#define RS 29
#define CS 28
#define RES 21
#define Set_SDA digitalWrite(SDA,1)
#define Reset_SDA digitalWrite(SDA,0)
#define Set_SCK digitalWrite(SCL,1)
#define Reset_SCK digitalWrite(SCL,0)
#define SetR_S digitalWrite(RS,1)
#define Reset_R_S digitalWrite(RS,0)
#define Set_CS digitalWrite(CS,1)
#define Reset_CS digitalWrite(CS,0)
#define Set_RES digitalWrite(RES,1)
#define Reset_RES digitalWrite(RES,0)
#define ASC_CHR_WIDTH 8
#define ASC_CHR_HEIGHT 12
#define ASC_HZ_WIDTH 16
extern void Clear(void);
extern void LcdInit(void);
extern void disp_str_color(uint8_t *p,uint8_t uCol,uint8_t uPage,uint8_t Color); //具备反显功能
#endif