mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
[update] 增加STM32智慧宿舍基础代码
This commit is contained in:
215
firmware/stm32/smart_dormitory/User/oled/oled.c
Normal file
215
firmware/stm32/smart_dormitory/User/oled/oled.c
Normal file
@@ -0,0 +1,215 @@
|
||||
/****************************************Copyright (c)****************************************************
|
||||
**
|
||||
** File name: lcd.c
|
||||
** Created by: XiaoYi
|
||||
** Created date: 2020-10-16
|
||||
** Version: v1.0
|
||||
** Descriptions: The original
|
||||
** Link address: https://blog.csdn.net/weixin_45006076
|
||||
**
|
||||
*********************************************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
#include "i2c.h"
|
||||
#include "oled.h"
|
||||
#include "codetab.h"
|
||||
|
||||
void oled_write_cmd(unsigned char cmd)//д<><D0B4><EFBFBD><EFBFBD>
|
||||
{
|
||||
HAL_I2C_Mem_Write(&hi2c1 ,0x78,0x00,I2C_MEMADD_SIZE_8BIT,&cmd,1,0x100);
|
||||
}
|
||||
|
||||
void oled_write_data(unsigned char data)//д<><D0B4><EFBFBD><EFBFBD>
|
||||
{
|
||||
HAL_I2C_Mem_Write(&hi2c1 ,0x78,0x40,I2C_MEMADD_SIZE_8BIT,&data,1,0x100);
|
||||
}
|
||||
|
||||
void oled_set_pos(unsigned char x, unsigned char y) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
oled_write_cmd(0xb0+y);
|
||||
oled_write_cmd(((x&0xf0)>>4)|0x10);
|
||||
oled_write_cmd((x&0x0f)|0x01);
|
||||
}
|
||||
|
||||
void oled_fill(unsigned char fill_Data)//ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
unsigned char m,n;
|
||||
for(m=0;m<8;m++)
|
||||
{
|
||||
oled_write_cmd(0xb0+m); //page0-page1
|
||||
oled_write_cmd(0x00); //low column start address
|
||||
oled_write_cmd(0x10); //high column start address
|
||||
for(n=0;n<128;n++)
|
||||
{
|
||||
oled_write_data(fill_Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void oled_clear_screen(void)//<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
oled_fill(0x00);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Prototype : void oled_wakeup(void)
|
||||
// Calls :
|
||||
// Parameters : none
|
||||
// Description : <20><>OLED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD>
|
||||
//--------------------------------------------------------------
|
||||
void oled_wakeup(void)
|
||||
{
|
||||
oled_write_cmd(0X8D); //<2F><><EFBFBD>õ<EFBFBD><C3B5>ɱ<EFBFBD>
|
||||
oled_write_cmd(0X14); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>
|
||||
oled_write_cmd(0XAF); //OLED<45><44><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Prototype : void oled_sleep(void)
|
||||
// Calls :
|
||||
// Parameters : none
|
||||
// Description : <20><>OLED<45><44><EFBFBD><EFBFBD> -- <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>,OLED<45><44><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>10uA
|
||||
//--------------------------------------------------------------
|
||||
void oled_sleep(void)
|
||||
{
|
||||
oled_write_cmd(0X8D); //<2F><><EFBFBD>õ<EFBFBD><C3B5>ɱ<EFBFBD>
|
||||
oled_write_cmd(0X10); //<2F>رյ<D8B1><D5B5>ɱ<EFBFBD>
|
||||
oled_write_cmd(0XAE); //OLED<45><44><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Prototype : void OLED_ShowChar(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize)
|
||||
// Calls :
|
||||
// Parameters : x,y -- <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(x:0~127, y:0~7); ch[] -- Ҫ<><D2AA>ʾ<EFBFBD><CABE><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>; TextSize -- <20>ַ<EFBFBD><D6B7><EFBFBD>С(1:6*8 ; 2:8*16)
|
||||
// Description : <20><>ʾcodetab.h<>е<EFBFBD>ASCII<49>ַ<EFBFBD>,<2C><>6*8<><38>8*16<31><36>ѡ<EFBFBD><D1A1>
|
||||
//--------------------------------------------------------------
|
||||
void oled_show_string(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize)
|
||||
{
|
||||
unsigned char c = 0,i = 0,j = 0;
|
||||
switch(TextSize)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
while(ch[j] != '\0')
|
||||
{
|
||||
c = ch[j] - 32;
|
||||
if(x > 126)
|
||||
{
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
oled_set_pos(x,y);
|
||||
for(i=0;i<6;i++)
|
||||
oled_write_data(F6x8[c][i]);
|
||||
x += 6;
|
||||
j++;
|
||||
}
|
||||
}break;
|
||||
case 2:
|
||||
{
|
||||
while(ch[j] != '\0')
|
||||
{
|
||||
c = ch[j] - 32;
|
||||
if(x > 120)
|
||||
{
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
oled_set_pos(x,y);
|
||||
for(i=0;i<8;i++)
|
||||
oled_write_data(F8X16[c*16+i]);
|
||||
oled_set_pos(x,y+1);
|
||||
for(i=0;i<8;i++)
|
||||
oled_write_data(F8X16[c*16+i+8]);
|
||||
x += 8;
|
||||
j++;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Prototype : void oled_show_chinese(unsigned char x, unsigned char y, unsigned char N)
|
||||
// Calls :
|
||||
// Parameters : x,y -- <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(x:0~127, y:0~7); N:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>codetab.h<>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
// Description : <20><>ʾcodetab.h<>еĺ<D0B5><C4BA><EFBFBD>,16*16<31><36><EFBFBD><EFBFBD>
|
||||
//--------------------------------------------------------------
|
||||
void oled_show_chinese(unsigned char x, unsigned char y, unsigned char N)
|
||||
{
|
||||
unsigned char wm=0;
|
||||
unsigned int adder=32*N;
|
||||
oled_set_pos(x , y);
|
||||
for(wm = 0;wm < 16;wm++)
|
||||
{
|
||||
oled_write_data(F16x16[adder]);
|
||||
adder += 1;
|
||||
}
|
||||
oled_set_pos(x,y + 1);
|
||||
for(wm = 0;wm < 16;wm++)
|
||||
{
|
||||
oled_write_data(F16x16[adder]);
|
||||
adder += 1;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Prototype : void oled_draw_bmp(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char BMP[]);
|
||||
// Calls :
|
||||
// Parameters : x0,y0 -- <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(x0:0~127, y0:0~7); x1,y1 -- <20><><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(x1:1~128,y1:1~8)
|
||||
// Description : <20><>ʾBMPλͼ
|
||||
//--------------------------------------------------------------
|
||||
void oled_draw_bmp(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char *bmp)
|
||||
{
|
||||
unsigned int j=0;
|
||||
unsigned char x,y;
|
||||
|
||||
if(y1%8==0)
|
||||
y = y1/8;
|
||||
else
|
||||
y = y1/8 + 1;
|
||||
for(y=y0;y<y1;y++)
|
||||
{
|
||||
oled_set_pos(x0,y);
|
||||
for(x=x0;x<x1;x++)
|
||||
{
|
||||
oled_write_data(bmp[j++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void oled_init(void)
|
||||
{
|
||||
delay_ms(100); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ҫ
|
||||
|
||||
oled_write_cmd(0xAE); //display off
|
||||
oled_write_cmd(0x20); //Set Memory Addressing Mode
|
||||
oled_write_cmd(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
|
||||
oled_write_cmd(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
|
||||
oled_write_cmd(0xc8); //Set COM Output Scan Direction
|
||||
oled_write_cmd(0x00); //---set low column address
|
||||
oled_write_cmd(0x10); //---set high column address
|
||||
oled_write_cmd(0x40); //--set start line address
|
||||
oled_write_cmd(0x81); //--set contrast control register
|
||||
oled_write_cmd(0xff); //<2F><><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD> 0x00~0xff
|
||||
oled_write_cmd(0xa1); //--set segment re-map 0 to 127
|
||||
oled_write_cmd(0xa6); //--set normal display
|
||||
oled_write_cmd(0xa8); //--set multiplex ratio(1 to 64)
|
||||
oled_write_cmd(0x3F); //
|
||||
oled_write_cmd(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
|
||||
oled_write_cmd(0xd3); //-set display offset
|
||||
oled_write_cmd(0x00); //-not offset
|
||||
oled_write_cmd(0xd5); //--set display clock divide ratio/oscillator frequency
|
||||
oled_write_cmd(0xf0); //--set divide ratio
|
||||
oled_write_cmd(0xd9); //--set pre-charge period
|
||||
oled_write_cmd(0x22); //
|
||||
oled_write_cmd(0xda); //--set com pins hardware configuration
|
||||
oled_write_cmd(0x12);
|
||||
oled_write_cmd(0xdb); //--set vcomh
|
||||
oled_write_cmd(0x20); //0x20,0.77xVcc
|
||||
oled_write_cmd(0x8d); //--set DC-DC enable
|
||||
oled_write_cmd(0x14); //
|
||||
oled_write_cmd(0xaf); //--turn on oled panel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user