树莓派linux c语言编程,ST7775R c语言代码 树莓派 linux

这个代码片段展示了如何使用STM32微控制器初始化并操作ST7775R液晶显示屏。程序包含了初始化函数、数据传输函数以及清屏函数,使用了wiringPi库进行GPIO操作。通过配置引脚和发送指令来设置屏幕参数,如分辨率、颜色模式等。
摘要由CSDN通过智能技术生成

ST7775R.c

#include "ST7775R.h"

// LED Pin - wiringPi pin 0 是 BCM_GPIO 17。

//利用 wiringPiSetupSys 进行初始化时必须使用 BCM 编号

//选择其他 pin 编号时,请同时使用 BCM 编号

//更新 Property Pages - Build Events - Remote Post-Build Event 命令

//它使用 gpio 导出进行 wiringPiSetupSys 的设置

//以上是VS 自动生成

// wringPi 使用wringPiSetupSys 无法完成端口初始化!!!

#defineLED17

int bus_arr[5] = { RS, CS, SCL, SDI, RST };

void Delay(int t) {

delay(t);

}

void WriteComm(unsigned int cmd) {

digitalWrite(RS, LOW);

digitalWrite(CS, LOW);

for (int bitStep = 0; bitStep < 8; bitStep++) {

digitalWrite(SCL, LOW);

if ((cmd & 0x80) == 0x80) {

digitalWrite(SDI, HIGH);

}else{

digitalWrite(SDI, LOW);

}

digitalWrite(SCL, HIGH);

cmd = (cmd << 1);

}

digitalWrite(CS, HIGH);

}

void port_init() {

wiringPiSetup();

for (int index = 0; index < 5; index++) {

pinMode(bus_arr[index], OUTPUT);

}

}

void port_init_sys() {

wiringPiSetupSys();

for (int index = 0; index < 5; index++) {

pinMode(bus_arr[index], OUTPUT);

}

}

void all_set_high() {

for (int index = 0; index < 5; index++) {

digitalWrite(bus_arr[index], HIGH);

}

}

void all_set_low() {

for (int index = 0; index < 5; index++) {

digitalWrite(bus_arr[index], LOW);

}

}

void WriteData(unsigned int dat) {

int datL = dat & 0xff;

int datH = dat >> 8;

// 01011100 11010111

// H 01001100 L 11010111

// 01001100 & 10000000 = 00000000

//01001100 << 1 = 10011000 & 10000000 = 10000000

//10011000<<1 = 00110000 &10000000==00000000

// 00110000 << 1 == 01100000 & 10000000 = 00000000

// 01100000 << 1 = 11000000 & 10000000 == 10000000

// 11000000 << 1 = 10000000 & 10000000 == 10000000

//...

digitalWrite(RS, HIGH);

digitalWrite(CS, LOW);

for (int bitStep = 0; bitStep < 8; bitStep++) {

digitalWrite(SCL, LOW);

if ((datH & 0x80) == 0x80) {

digitalWrite(SDI, HIGH);

}

else {

digitalWrite(SDI, LOW);

}

digitalWrite(SCL, HIGH);

datH = datH << 1;

}

for (int bitStep = 0; bitStep < 8; bitStep++) {

digitalWrite(SCL, LOW);

if ((datL & 0x80) == 0x80) {

digitalWrite(SDI, HIGH);

}

else {

digitalWrite(SDI, LOW);

}

digitalWrite(SCL, HIGH);

datL = datL << 1;

}

digitalWrite(CS, HIGH);

}

void TFT_Init() {

digitalWrite(RST, HIGH);

Delay(400);

digitalWrite(RST, LOW);

Delay(400);

digitalWrite(RST, HIGH);

Delay(400);

WriteComm(0xd0); WriteData(0x0003); // set SS and NL bit

WriteComm(0xeb); WriteData(0x0b00); // set 1 line inversion

WriteComm(0xec); WriteData(0x000f); // set GRAM write direction and

WriteComm(0xc7); WriteData(0x030f); // set GRAM write direction and

WriteComm(0x01); WriteData(0x011C); // set SS and NL bit

WriteComm(0x02); WriteData(0x0100); // set 1 line inversion

WriteComm(0x03); WriteData(0x1030); //

WriteComm(0x07); WriteData(0x0000);

WriteComm(0x08); WriteData(0x0808); //

WriteComm(0x0F); WriteData(0x0601); //

WriteComm(0x10); WriteData(0x0A00); //

WriteComm(0x11); WriteData(0x1B41); //

Delay(50);

WriteComm(0x12); WriteData(0x200E); //

WriteComm(0x13); WriteData(0x0020); // Set GVDD 52 30

WriteComm(0x14); WriteData(0x4A5F); // Set VCOMH/VCOML voltage 5f60

WriteComm(0x30); WriteData(0x0000);

WriteComm(0x31); WriteData(0x00DB);

WriteComm(0x32); WriteData(0x0000);

WriteComm(0x33); WriteData(0x0000);

WriteComm(0x34); WriteData(0x00DB);

WriteComm(0x35); WriteData(0x0000);

WriteComm(0x36); WriteData(0x00AF);

WriteComm(0x37); WriteData(0x0000);

WriteComm(0x38); WriteData(0x00DB);

WriteComm(0x39); WriteData(0x0000);

WriteComm(0x50); WriteData(0x0000);

WriteComm(0x51); WriteData(0x0803);

WriteComm(0x52); WriteData(0x0C07);

WriteComm(0x53); WriteData(0x0501);

WriteComm(0x54); WriteData(0x070C);

WriteComm(0x55); WriteData(0x0308);

WriteComm(0x56); WriteData(0x0000);

WriteComm(0x57); WriteData(0x0105);

WriteComm(0x58); WriteData(0x1100);

WriteComm(0x59); WriteData(0x0011);

WriteComm(0x20); WriteData(0x0000); // Set GRAM Address

WriteComm(0x21); WriteData(0x0000); // Set GRAM Address

WriteComm(0x07); WriteData(0x1017);

WriteComm(0x22);

}

void TFT_SetWindow(unsigned int xStart, unsigned int yStart, unsigned int xEnd, unsigned int yEnd)

{

//ILI9163C

WriteComm(0x36); WriteData(xEnd); //HEA7-0

WriteComm(0x37); WriteData(xStart); // HSA7-0

WriteComm(0x38); WriteData(yEnd); // VEA7-0

WriteComm(0x39); WriteData(yStart); // VSA7-0

WriteComm(0x20); WriteData(xStart);

WriteComm(0x21); WriteData(yStart);

WriteComm(0x22);

}

void TFT_ClearScreen(unsigned int color)

{

unsigned int i, j;

TFT_SetWindow(0, 0, TFT_XMAX, TFT_YMAX);

for (i = 0; i

ST7775R.h

#include

#include

//---定义屏的大小---// #define TFT_XMAX 175// //设置TFT屏的大小 #define TFT_YMAX 219// //定义数据总线 #define RS 27 #define SCL 28 #define CS 29 #define SDI 4 #define RST 5 #define PCM_RS 16 #define PCM_SCL 20 #define PCM_CS 21 #define PCM_SDI 23 #define PCM_RST 24 #define WHITE 0xFFFF #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define MAGENTA 0xF81F #define GREEN 0x07E0 #define CYAN 0x7FFF #define YELLOW 0xFFE0 //定义颜色的宏 void all_set_low(); void all_set_high(); void port_init(void); void Delay(int t); void WriteComm(unsigned int cmd); //void WriteStart(); //void WriteComm(unsigned char cmd); void WriteData(unsigned int dat); void TFT_Init(void); void TFT_SetWindow(unsigned int xStart, unsigned int yStart, unsigned int xEnd, unsigned int yEnd); void TFT_ClearScreen(unsigned int color);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值