51单片机温度计LCD1602显示成功,于是又挑战了OLED显示
main.c
#include"oled.h"
#include"ds18b20_1.h"
void Timer0Init(void);
//void Gao_Wen(void);
//void GaoDiInit(void);
sbit Deng=P1^0; //LED灯
sbit FengMing=P1^1; //蜂鸣器
sbit GD=P3^0; //两个功能:高限温减小,关闭LED灯
sbit GF=P3^1; //两个功能:低限温增加,关闭蜂鸣器
sbit GW=P3^2; //高限温增加
sbit DW=P3^3; //低限温减小
//unsigned char GaoWen_Y[]={"GW:"}; //高限温显示
//unsigned char DiWen_Y[]={"DW:"}; //低限温显示
int GaoWen=40; //高限温
int DiWen=-20; //低限温
char flag=0; //一秒标志位
char b=0; //定时器内部标志位;
/*******************************主程序区域********************************/
int main()
{
bit ack;
bit k=1; //决定超出限温后,关闭灯和蜂鸣器后不再响,而低于限温后再次超出限温后,依然能响标志位;
int Zhen=0,Xiao=0;
unsigned char temp[10];
char len=0;
int wenDu=0; //接收温度
// LCD_Init();
Deng=0; //LCD初始化
OLED_Init();
Start18B20(); //温度传感器初始化
Timer0Init(); //T0定时器初始化
Delay10ms();
// LCD_WeiZhi(1,0);
// LCD_XianShi(GaoWen_Y);
// LCD_WeiZhi(1,9);
// LCD_XianShi(DiWen_Y);
// GaoDiInit();
OLED_ShowChinese(0,0,10,16);
OLED_ShowChinese(18,0,13,16);
OLED_ShowChar(36,0,':',16);
OLED_ShowChinese(0,2,8,16);
OLED_ShowChinese(18,2,10,16);
OLED_ShowChinese(36,2,11,16);
OLED_ShowChinese(54,2,12,16);
OLED_ShowChar(70,2,':',16);
OLED_ShowChinese(0,4,9,16);
OLED_ShowChinese(18,4,10,16);
OLED_ShowChinese(36,4,11,16);
OLED_ShowChinese(54,4,12,16);
OLED_ShowChar(70,4,':',16);
// OLED_ShowString(0,2,"GW:",16);
// OLED_ShowString(64,2,"DW:",16);
OLED_Num(78,2,GaoWen,3,16);
OLED_Num(78,4,DiWen,3,16);
while(1)
{
if(flag==1) //1秒刷新温度
{
flag=0;
ack=Read18B20(&wenDu);
if(ack)
{
Zhen=wenDu>>4;
Xiao=wenDu&0x0f;
len=OLED_Xian_Zheng(Zhen,temp);
temp[len++]='.';
Xiao=(Xiao*100)*0.0625;
temp[len++]=Xiao/10+'0';
// temp[len++]=Xiao%10+'0';
while(len<5)
{
temp[len++]=' ';
}
temp[len]='