一、硬件
STM8S103K6、0.96寸OLED
二、代码
#include "stm8s.h"
#include "OLED.h"
#include "lib.h"
u8 number[7];
int main(void)
{
float Temp;
unsigned int realtemp;
disableInterrupts();
CLKInit();
LED1_Init();
TIM2_Init();
ADC_Init();
OLED_Port_Init();
OLED_Reset();
enableInterrupts();
while(1)
{
LED1ON();
Tmp_Change(); //数据开始转换
DelaynUs(1000); //延时等待
Temp = tmp(); //读取数据
realtemp = (unsigned int)(Temp * 10.0);
number[0] = realtemp % 10;
number[1] = realtemp % 100 / 10;
number[2] = realtemp / 100;
number[3] = ADCData / 1000;
number[4] = (ADCData / 100) % 10; // 百位
number[5] = (ADCData % 100) /10; // 十位
number[6] =ADCData % 10; // 个位
//显示温度
OLED_ShowNum16X32(10 , 4 , number[2]);
OLED_ShowNum16X32(26 , 4 , number[1]);
OLED_ShowNum16X32(42 , 4 , 10);
OLED_ShowNum16X32(58 ,4 , number[0]);
OLED_ShowNum32X32(74, 4 , 0);
OLED_ShowNum(10 , 0 , number[3],5,10);
OLED_ShowNum(26 , 0 , number[4],4,10);
OLED_ShowNum(58 ,0 , number[5],3,10);
OLED_ShowNum(76 ,0 , number[6],2,10);
LED1OFF();
//等待1s
delay(800);
}
}