代码拉取完成,页面将自动刷新
/*
* ST7567.c
*
* Created on: 22/07/2016
* Author: fleite
*/
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include "ss_gpio.h"
#include "ss_mspi.h"
#include "ST7567.h"
#define ST7567_TFT_WIDTH 128
void ST7567init(void){
ST7567reset();
// ST7567sendCommand(ST7567_EXIT_SOFTRST);
// ST7567sendCommand(ST7567_BIAS_1_7);
// ST7567sendCommand(ST7567_DISPON);
// ST7567sendCommand(SSD1305_MAPCOL0);
// ST7567sendCommand(ST7567_SETCOMREVERSE);
// ST7567sendCommand(ST7567_REG_RES_RR1);
// ST7567sendCommand(ST7567_SETEV);
// ST7567sendCommand(0x08);
// ST7567sendCommand(ST7567_POWERCTRL);
// ST7567sendCommand(ST7567_SETSTARTLINE);
// ST7567sendCommand(ST7567_SETPAGESTART);
// ST7567sendCommand(ST7567_SETCOLH);
// ST7567sendCommand(ST7567_SETCOLL);
// ST7567sendCommand(ST7567_DISPINVERSE);
// ST7567sendCommand(ST7567_DISPON);
// ST7567sendCommand(ST7567_DISPRAM);
ST7567sendCommand(0xE2);
ST7567sendCommand(0xAF);
ST7567sendCommand(0xA2);
ST7567sendCommand(0xA1); // set SEG direction : reverse
ST7567sendCommand(0xC8); // set COM direction : reverse
ST7567sendCommand(0xA4);
ST7567sendCommand(0xA6);
ST7567sendCommand(0x2F);
ST7567sendCommand(0x24);
ST7567sendCommand(0x40);
ST7567sendCommand(0x24);
ST7567sendCommand(0x81);
ST7567sendCommand(0x30);
ST7567sendCommand(0xB0);
ST7567sendCommand(0x10);
ST7567sendCommand(0);
}
void ST7567reset(void){
ss_gpio_set_value(LCD_RST, 0);
usleep(200*1000);
ss_gpio_set_value(LCD_RST, 1);
usleep(100*1000);
// int j;
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV0, 17, 1, 0);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV1, 30, 1, 0);
// for(j=0;j<50000;j++);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV0, 17, 1, 1);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV1, 30, 1, 1);
}
void ST7567printDataBegin(void){
ss_gpio_set_value(LCD_DC, 1);
// ss_mspi_open();
// //SET A0 to send Data
// mq55_spi_ss0_enable(MQ55_SPI_DEV1);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV0, 16, 1, 1);
// /* Outro LCD na SPI2 */
// mq55_spi_ss0_enable(MQ55_SPI_DEV2);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV1, 31, 1, 1);
}
void ST7567printDataEnd(void){
// ss_mspi_close();
// mq55_spi_ss0_disable(MQ55_SPI_DEV1);
// /* Outro LCD na SPI2 */
// mq55_spi_ss0_disable(MQ55_SPI_DEV2);
}
void ST7567sendData(char data){
uint8_t buf = (uint8_t)data;
ss_mspi_write(&buf, 1);
// char temp = data;
// mq55_spi_transmit(MQ55_SPI_DEV1, &temp, 1);
// /* Outro LCD na SPI2 */
// temp = data;
// mq55_spi_transmit(MQ55_SPI_DEV2, &temp, 1);
}
void ST7567sendCommand(char command){
uint8_t buf = (uint8_t)command;
ss_gpio_set_value(LCD_DC, 0);
ss_mspi_write(&buf, 1);
// char temp = command;
// mq55_spi_ss0_enable(MQ55_SPI_DEV1);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV0, 16, 1, 0);
// mq55_spi_transmit(MQ55_SPI_DEV1, &temp, 1);
// mq55_spi_ss0_disable(MQ55_SPI_DEV1);
// /* Outro LCD na SPI2 */
// temp = command;
// mq55_spi_ss0_enable(MQ55_SPI_DEV2);
// mq55_gpio_write_bit_pattern(MQ55_GPIO_DEV1, 31, 1, 0);
// mq55_spi_transmit(MQ55_SPI_DEV2, &temp, 1);
// mq55_spi_ss0_disable(MQ55_SPI_DEV2);
}
void ST7567_clear(void){
int page, j;
int col = 0;
for(page = 0; page < 8; page++){
ST7567sendCommand(ST7567_SETPAGESTART+page);
ST7567sendCommand(ST7567_SETCOLL + (col & 0x0f));
ST7567sendCommand(ST7567_SETCOLH + (col >> 4));
ST7567printDataBegin();
for(j=0;j<132;j++){
ST7567sendData(0xFF);
}
ST7567printDataEnd();
}
}
void ST7567_Fill(uint8_t uiByte)
{
int page, j;
int col = 0;
for(page = 0; page < 8; page++){
ST7567sendCommand(ST7567_SETPAGESTART+page);
ST7567sendCommand(ST7567_SETCOLL + (col & 0x0f));
ST7567sendCommand(ST7567_SETCOLH + (col >> 4));
ST7567printDataBegin();
for(j=0;j<132;j++){
ST7567sendData(uiByte);
}
ST7567printDataEnd();
}
}
void ST7567_SetPosition(uint8_t uiColumn, uint8_t uiPage)
{
// SSD1306_WriteCommand(0xB0 | uiPage);
// SSD1306_WriteCommand(((uiColumn & 0xF0)>>4)|0x10);
// SSD1306_WriteCommand((uiColumn & 0x0F));
ST7567sendCommand(ST7567_SETPAGESTART+uiPage);
ST7567sendCommand(ST7567_SETCOLL + (uiColumn & 0x0f));
ST7567sendCommand(ST7567_SETCOLH + (uiColumn >> 4));
}
void ST7567_WriteData(uint8_t uiData)
{
// SPI_SSD1306_MODE_DAT();
// SPI_SSD1306_CS_LOW();
// SSD1306_WriteByte(uiData);
// SPI_SSD1306_CS_HIGH();
ST7567printDataBegin();
ST7567sendData(uiData);
ST7567printDataEnd();
}
void ST7567_test(void)
{
int page, j;
int col = 0;
for(page = 0; page < 8; page++){
ST7567sendCommand(ST7567_SETPAGESTART+page);
ST7567sendCommand(ST7567_SETCOLL + (col & 0x0f));
ST7567sendCommand(ST7567_SETCOLH + (col >> 4));
ST7567printDataBegin();
for(j=0;j<132;j++){
ST7567sendData(0x55);
}
ST7567printDataEnd();
}
}
#if 0
void ST7567_write_character(unsigned short x, unsigned short y, int character, const Font *font, unsigned char backgroundColor, unsigned char foregroundColor)
{
char column = 0, row = 0; /* Loop indices */
unsigned char width = 0 ;
unsigned short position = 0;
unsigned char index = 0;
unsigned char bytesByColumn = 0;
unsigned char page, col, data;
page = y >> 3;
col = x;
ST7567sendCommand(ST7567_SETPAGESTART+page);
ST7567sendCommand(ST7567_SETCOLL + (col & 0x0f));
ST7567sendCommand(ST7567_SETCOLH + (col >> 4));
ST7567printDataBegin();
bytesByColumn = font->descriptorArray[character - font->startCharacter].width / 8;
if(font->descriptorArray[character - font->startCharacter].width % 8)
bytesByColumn += 1;
for(col = 0; col < font->descriptorArray[character - font->startCharacter].width; col++){
position = font->descriptorArray[character - font->startCharacter].position + (col * bytesByColumn);
data = font->bitmapArray[position];
ST7567sendData(~data);
}
ST7567printDataEnd();
}
unsigned long ST7567_write_string(unsigned short x, unsigned short y, const char *text, const Font *font, unsigned short backgroundColor, unsigned short foregroundColor)
{
unsigned long count = 0;
while(*text)
{
if((x + font->descriptorArray[text[0] - font->startCharacter].width) > ST7567_TFT_WIDTH) /* Verifico se e possivel imprimir o caracter */
return count; // number of characters printed
ST7567_write_character(x, y, *text, font, backgroundColor, foregroundColor); /* Envia o caracter. */
x = x + font->descriptorArray[text[0] - font->startCharacter].width; /* Desloco a posicao para o proximo caracter. */
text++; /* Seleciona o proximo caracter. */
count++;
}
return count; /* Number of characters printed */
}
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。