It uses a 7-pin OLED, the kind that Bao bought. I don't know if it uses the Zhongjingyuan program. The chip should be SSD1306, but the SSD1306 in the simulation is always wrong. I tried SSD1308 and it worked! The
microcontroller source program is as follows
#include "xianshispi.h"
#include "oledfont.h"
void delay_ms(unsigned int ms)
{
unsigned int a;
while(ms)
{
a=1800;
while(a--);
ms--;
}
return;
}
void OLED_WR_Byte(unsigned char dat,unsigned char cmd) //write data or command
{ // Data instruction
unsigned char i;
if(cmd) {OLED_DC(1);}
else {OLED_DC(0); }
OLED_CS(0);
for(i=0;i<8;i++)
{
OLED_SCL(0);
if(dat&0x80)
{
OLED_SDIN(1);
}
else
OLED_SDIN(0);
OLED_SCL(1);
dat<<=1;
}
OLED_CS(1);
OLED_DC(1);
}
void OLED_Set_Pos(unsigned char x, unsigned char y) // Positioning - (axis)
{
OLED_WR_Byte(0xb0+y,OLED_CMD);
OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
}
void OLED_Display_On(void)
{
OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC??
OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON
OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON
}
void OLED_Display_Off(void)
{
OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC??
OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF
}
void OLED_Clear(void) //Clear screen (full)
{
unsigned char i,n;
for(i=0;i<8;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD);
OLED_WR_Byte (0x02,OLED_CMD);
OLED_WR_Byte (0x10,OLED_CMD);
for(n=0;n<128;n++)OLED_WR_Byte(0x00,OLED_DATA);
}
}
void OLED_Clear2(void) //Clear screen (general)
{
unsigned char i,n;
for(i=0;i<2;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD);
OLED_WR_Byte (0x02,OLED_CMD);
OLED_WR_Byte (0x10,OLED_CMD);
for(n=0;n<128;n++)OLED_WR_Byte(0xff,OLED_DATA);
}
}
void OLED_ShowChar(unsigned char x,unsigned char y,unsigned int chr) //Character inversion (background and data)
{
unsigned int c=0,i=0;
c=chr-' ';
if(x>Max_Column-1){x=0;y=y+2;}
if(SIZE==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
}
else
{
OLED_Set_Pos(x,y+1);
for(i=0;i<6;i++)
{
OLED_WR_Byte(F6x8[c][i],OLED_DATA);
}
}
}
void OLED_ShowChar111(unsigned char x,unsigned char y,unsigned int chr) //Character inversion (background and data)
{
unsigned int c=0,i=0;
c=chr-' ';
if(x>Max_Column-1){x=0;y=y+2;}
if(SIZE==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(~F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(~F8X16[c*16+i+8],OLED_DATA);
}
else
{
OLED_Set_Pos(x,y+1);
for(i=0;i<6;i++)
{
OLED_WR_Byte(~F6x8[c][i],OLED_DATA);
}
}
}
unsigned int oled_pow(unsigned char m,unsigned char n)
{
unsigned int result=1;
while(n--)result*=m;
return result;
}
void OLED_ShowNum(unsigned char x,unsigned char y,unsigned int num,unsigned char len,unsigned char size)
{
unsigned char t,temp;
unsigned char enshow=0;
for(t=0;t temp=(num/oled_pow(10,len-t-1))%10; if(enshow==0&&t<(len-1)) { if(temp==0) { OLED_ShowChar(x+(size/2)*t,y,' '); continue; }else enshow=1; } OLED_ShowChar(x+(size/2)*t,y,temp+'0'); } } //???????? void OLED_ShowString(unsigned char x,unsigned char y,unsigned char *chr,unsigned char no) //显示字符串 { unsigned int j=0; while (chr[j]!='') { if(no) {OLED_ShowChar(x,y,chr[j]);} else{OLED_ShowChar111(x,y,chr[j]);} x+=8; if(x>120){x=0;y+=2;} j++; } } void OLED_ShowCHinese(unsigned char x,unsigned char y,unsigned char *z,unsigned char no1) //显示中文 { unsigned char t,i,adder=0; while(*z != '') { for(t=0;t<20;t++) { if(Hzk[t].hzk_2[0]==*z && Hzk[t].hzk_2[1]==*(z+1)) { if(no1 == 1) { OLED_Set_Pos(x,y); for(i=0;i<16;i++){OLED_WR_Byte(Hzk[t].hzk_32[i],OLED_DATA);adder+=1;} OLED_Set_Pos(x,y+1); for(i=0;i<16;i++){OLED_WR_Byte(Hzk[t].hzk_32[i+16],OLED_DATA);adder+=1;} } else{ OLED_Set_Pos(x,y); for(i=0;i<16;i++){OLED_WR_Byte(~Hzk[t].hzk_32[i],OLED_DATA);adder+=1;} OLED_Set_Pos(x,y+1); for(i=0;i<16;i++){OLED_WR_Byte(~Hzk[t].hzk_32[i+16],OLED_DATA);adder+=1;} } } } x+=16; with+=2; } } //void OLED_ShowCHinese1(unsigned char x,unsigned char y,unsigned char z,unsigned char no) //{ // unsigned char t,i,adder=0; // for(i=0;i // // OLED_Set_Pos(x+i*16,y); for(t=0;t<16;t++){OLED_WR_Byte(Hzk1[2*no+i*2][t],OLED_DATA);adder+=1;} // OLED_Set_Pos(x+i*16,y+1); for(t=0;t<16;t++){OLED_WR_Byte(Hzk1[2*no+i*2+1][t],OLED_DATA);adder+=1;} // } //} void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char *p) //显示图片 { unsigned int j=0; unsigned char x,y; if(y1%8==0) y=y1/8; else y=y1/8+1; for(y=y0;y OLED_Set_Pos(x0,y); for(x=x0;x OLED_WR_Byte(*p++,OLED_DATA); } } } void OLED_Init(void) { delay_ms(1); OLED_RST(1); delay_ms(1); OLED_RST(0); delay_ms(1); OLED_RST(1); delay_ms(1); OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel OLED_WR_Byte(0x02,OLED_CMD);//---set low column address OLED_WR_Byte(0x10,OLED_CMD);//---set high column address ……………………
Previous article:51 MCU OLED12864 I2C interface usage tutorial
Next article:51 single chip microcomputer automatic water vending machine program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- 【NUCLEO-L552ZE Review】+ Planning & Preparation
- After cc2530 successfully creates a network, p1_0 immediately becomes low level
- RF and Microwave Passive Component Design Considerations and Limitations
- Let's see! Detailed explanation of the components of a switching power supply
- SCI Interface and Hardware Implementation of TMS320C6711D
- Non-magnetic AC/DC Power Supplies
- S5PV210 Timer
- [CY8CKIT-149 PSoC 4100S Evaluation] + Create a blank project (taking Key-LED as an example)
- The difference between IPV4 and IPV6 of TCP/IP protocol
- How to set numpy floating point precision?