回顾上期帖子:https://bbs.21ic.com/icview-3343774-1-1.html,咱们使用DS18B20作为外设,通过单线式通讯方式,采集周围环境的温度,并通过串口打印当前的温度值。今天周末,南方的室内温度还不算太低,不知道此时此刻的北方气温怎么样。
本节在上期的基础上,加入了驱动OLED显示部分的功能,硬件连接:GPIOB6--->SCL,GPIOB7--->SDA。借助“PCtoLCD2002”工具可以实现中文字符的显示,bmp单色位图图片的显示。参考的部分代码展示如下:
#include "oled.h"
#include "stdlib.h"
#include "string.h"
#include "at32f423.h"
#include "at32f423_board.h"
#include "string.h"
#include "oledfont.h"
#include "i2c_application.h"
#include "at32f423_conf.h"
#define I2Cx_ADDRESS 0x78
#define I2Cx_PORT I2C1
#define I2Cx_CLK CRM_I2C1_PERIPH_CLOCK
#define I2Cx_DMA DMA1
#define I2Cx_DMA_CLK CRM_DMA1_PERIPH_CLOCK
#define I2Cx_SCL_GPIO_CLK CRM_GPIOB_PERIPH_CLOCK
#define I2Cx_SCL_GPIO_PIN GPIO_PINS_6
#define I2Cx_SCL_GPIO_PinsSource GPIO_PINS_SOURCE6
#define I2Cx_SCL_GPIO_PORT GPIOB
#define I2Cx_SCL_GPIO_MUX GPIO_MUX_4
#define I2Cx_SDA_GPIO_CLK CRM_GPIOB_PERIPH_CLOCK
#define I2Cx_SDA_GPIO_PIN GPIO_PINS_7
#define I2Cx_SDA_GPIO_PinsSource GPIO_PINS_SOURCE7
#define I2Cx_SDA_GPIO_PORT GPIOB
#define I2Cx_SDA_GPIO_MUX GPIO_MUX_4
#define I2Cx_CLKCTRL 0x10F03C6A
i2c_handle_type hi2cx;
static unsigned char OLED_buffer[1024] = {0};
void OLED_WR_Byte(unsigned char dat,unsigned char cmd) {
if(cmd) {
Write_IIC_Data(dat);
} else {
Write_IIC_Command(dat);
}
}
void OLED_Set_Pos(unsigned char x, unsigned char y) {
OLED_WR_Byte(YLevel+y/PAGE_SIZE,OLED_CMD);
OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
OLED_WR_Byte((x&0x0f),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_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) {
if(color) {
OLED_buffer[(y/PAGE_SIZE)*WIDTH+x]|= (1<<(y%PAGE_SIZE))&0xff;
} else {
OLED_buffer[(y/PAGE_SIZE)*WIDTH+x]&= ~((1<<(y%PAGE_SIZE))&0xff);
}
}
void OLED_Display(void) {
uint8_t i,n;
for(i=0;i<(PAGE_SIZE);i++) {
OLED_WR_Byte (YLevel+i,OLED_CMD); //设置页地址(0~3)
OLED_WR_Byte (XLevelL,OLED_CMD); //设置显示位置—列低地址
OLED_WR_Byte (XLevelH,OLED_CMD); //设置显示位置—列高地址
for(n=0;n<WIDTH;n++) {
OLED_WR_Byte(OLED_buffer[i*WIDTH+n],OLED_DATA);
}
} //更新显示
}
void OLED_Clear(void) {
memset(OLED_buffer,0,sizeof(OLED_buffer));
OLED_Display();
}
void OLED_Init(void) {
II2CGpioInit();
delay_ms(200);
/**************初始化SSD1306*****************/
// OLED_Display_Off(); //power off
OLED_WR_Byte(0xAE,OLED_CMD);//--display off
OLED_WR_Byte(0x20,OLED_CMD);//---set low column address
OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
OLED_WR_Byte(0xb0,OLED_CMD);
OLED_WR_Byte(0xC8,OLED_CMD);//-not offset
OLED_WR_Byte(0x00,OLED_CMD);// contract control
OLED_WR_Byte(0x10,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);//--128
OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
OLED_WR_Byte(0xFF,OLED_CMD);
OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x3F,OLED_CMD);
OLED_WR_Byte(0xa4,OLED_CMD);//-set display offset
OLED_WR_Byte(0xd3,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
OLED_WR_Byte(0xF0,OLED_CMD);
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0x22,OLED_CMD);
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x12,OLED_CMD);
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x20,OLED_CMD);
OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
}
void i2c_lowlevel_init(i2c_handle_type* hi2c)
{
gpio_init_type gpio_init_structure;
if(hi2c->i2cx == I2Cx_PORT)
{
/* i2c periph clock enable */
crm_periph_clock_enable(I2Cx_CLK, TRUE);
crm_periph_clock_enable(I2Cx_SCL_GPIO_CLK, TRUE);
crm_periph_clock_enable(I2Cx_SDA_GPIO_CLK, TRUE);
/* gpio configuration */
gpio_pin_mux_config(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_GPIO_PinsSource, I2Cx_SCL_GPIO_MUX);
gpio_pin_mux_config(I2Cx_SDA_GPIO_PORT, I2Cx_SDA_GPIO_PinsSource, I2Cx_SDA_GPIO_MUX);
/* configure i2c pins: scl */
gpio_init_structure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_structure.gpio_mode = GPIO_MODE_MUX;
gpio_init_structure.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_structure.gpio_pull = GPIO_PULL_UP;
gpio_init_structure.gpio_pins = I2Cx_SCL_GPIO_PIN;
gpio_init(I2Cx_SCL_GPIO_PORT, &gpio_init_structure);
/* configure i2c pins: sda */
gpio_init_structure.gpio_pins = I2Cx_SDA_GPIO_PIN;
gpio_init(I2Cx_SDA_GPIO_PORT, &gpio_init_structure);
/* config i2c */
i2c_init(hi2c->i2cx, 0x0F, I2Cx_CLKCTRL);
i2c_own_address1_set(hi2c->i2cx, I2C_ADDRESS_MODE_7BIT, I2Cx_ADDRESS);
}
}
void II2CGpioInit(void)
{
#if 0
gpio_init_type gpio_init_struct;
/* enable gpioc periph clock */
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_init_struct);
/* gpio output config */
gpio_bits_write(GPIOC, IO_SCL_PIN | IO_SDA_PIN, TRUE);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = IO_SCL_PIN | IO_SDA_PIN;
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
gpio_init(GPIOC, &gpio_init_struct);
#else
gpio_init_type gpio_init_structure;
crm_periph_clock_enable(I2Cx_CLK, TRUE);
crm_periph_clock_enable(I2Cx_SCL_GPIO_CLK, TRUE);
crm_periph_clock_enable(I2Cx_SDA_GPIO_CLK, TRUE);
/* gpio configuration */
gpio_pin_mux_config(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_GPIO_PinsSource, I2Cx_SCL_GPIO_MUX);
gpio_pin_mux_config(I2Cx_SDA_GPIO_PORT, I2Cx_SDA_GPIO_PinsSource, I2Cx_SDA_GPIO_MUX);
/* configure i2c pins: scl */
gpio_init_structure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_structure.gpio_mode = GPIO_MODE_MUX;
gpio_init_structure.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_structure.gpio_pull = GPIO_PULL_UP;
gpio_init_structure.gpio_pins = I2Cx_SCL_GPIO_PIN;
gpio_init(I2Cx_SCL_GPIO_PORT, &gpio_init_structure);
/* configure i2c pins: sda */
gpio_init_structure.gpio_pins = I2Cx_SDA_GPIO_PIN;
gpio_init(I2Cx_SDA_GPIO_PORT, &gpio_init_structure);
hi2cx.i2cx = I2Cx_PORT;
/* i2c config */
i2c_config(&hi2cx);
#endif
}
void IIC_Start(void) {
OLED_SCL_SET();
OLED_SDA_SET();
OLED_SDA_CLR();
OLED_SCL_CLR();
}
void IIC_Stop(void) {
OLED_SCL_SET();
OLED_SDA_CLR();
OLED_SDA_SET();
}
void IIC_Wait_Ack(void) {
OLED_SCL_SET();
OLED_SCL_CLR();
}
void Write_IIC_Byte(uint8_t IIC_Byte) {
i2c_status_type i2c_status;
#if 0
uint8_t i;
uint8_t m,da;
da=IIC_Byte;
OLED_SCL_CLR();
for(i=0;i<8;i++) {
m=da;
m=m&0x80;
if(m==0x80) {
OLED_SDA_SET();
} else {
OLED_SDA_CLR();
}
da=da<<1;
OLED_SCL_SET();
OLED_SCL_CLR();
}
#else
uint8_t buff[2] = {0};
buff[0] = IIC_Byte;
i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, buff, 1, 1000);
if(i2c_status != I2C_OK)
{
printf("erro send %d",i2c_status);
}
#endif
}
void Write_IIC_Command(uint8_t IIC_Command) {
i2c_status_type i2c_status;
#if 0
IIC_Start();
Write_IIC_Byte(IIC_SLAVE_ADDR); //Slave address,SA0=0
IIC_Wait_Ack();
Write_IIC_Byte(0x00); //write command
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Command);
IIC_Wait_Ack();
IIC_Stop();
#else
uint8_t buff[2] = {0};
buff[0] = 0x00;
buff[1] = IIC_Command;
i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, buff, 2, 1000);
if(i2c_status != I2C_OK)
{
printf("erro send %d",i2c_status);
}
#endif
}
void Write_IIC_Data(uint8_t IIC_Data) {
i2c_status_type i2c_status;
#if 0
IIC_Start();
Write_IIC_Byte(IIC_SLAVE_ADDR); //D/C#=0; R/W#=0
IIC_Wait_Ack();
Write_IIC_Byte(0x40); //write data
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Data);
IIC_Wait_Ack();
IIC_Stop();
#else
uint8_t buff[2] = {0};
buff[0] = 0x40;
buff[1] = IIC_Data;
i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, buff, 2, 1000);
if(i2c_status != I2C_OK)
{
printf("erro send %d",i2c_status);
}
#endif
}
void GUI_DrawPoint(uint8_t x,uint8_t y,uint8_t color) {
OLED_Set_Pixel(x,y,color);
OLED_Display();
}
void GUI_Fill(uint8_t sx,uint8_t sy,uint8_t ex,uint8_t ey,uint8_t color) {
uint8_t i,j;
uint8_t width=ex-sx+1; //得到填充的宽度
uint8_t height=ey-sy+1; //高度
for(i=0;i<height;i++) {
for(j=0;j<width;j++) {
OLED_Set_Pixel(sx+j, sy+i,color);
}
}
OLED_Display();
}
void GUI_DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,uint8_t color) {
uint16_t t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; //计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0) {
incx=1; //设置单步方向
} else if(delta_x==0) {
incx=0;//垂直线
}else {
incx=-1;
delta_x=-delta_x;
}
if(delta_y>0) {
incy=1;
} else if(delta_y==0) {
incy=0;//水平线
} else{
incy=-1;delta_y=-delta_y;
}
if (delta_x>delta_y) {
distance=delta_x; //选取基本增量坐标轴
} else {
distance=delta_y;
}
//画线输出
for(t=0;t<=distance+1;t++ ) {
OLED_Set_Pixel(uRow,uCol,color);
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance) {
xerr-=distance;
uRow+=incx;
}
if(yerr>distance) {
yerr-=distance;
uCol+=incy;
}
}
OLED_Display();
}
void GUI_DrawRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,uint8_t color) {
GUI_DrawLine(x1,y1,x2,y1,color);
GUI_DrawLine(x1,y1,x1,y2,color);
GUI_DrawLine(x1,y2,x2,y2,color);
GUI_DrawLine(x2,y1,x2,y2,color);
}
void GUI_FillRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,uint8_t color) {
GUI_Fill(x1,y1,x2,y2,color);
}
void GUI_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size,uint8_t mode) {
unsigned char c=0,i=0,tmp,j=0;
c=chr-' ';//得到偏移后的值
if(x>WIDTH-1){x=0;y=y+2;}
if(Char_Size ==16) {
for(i=0;i<16;i++) {
if(mode) {
tmp = F8X16[c*16+i];
} else {
tmp = ~(F8X16[c*16+i]);
}
for(j=0;j<8;j++) {
if(tmp&(0x80>>j)) {
OLED_Set_Pixel(x+j, y+i,1);
} else {
OLED_Set_Pixel(x+j, y+i,0);
}
}
}
} else if(Char_Size==8) {
for(i=0;i<8;i++) {
if(mode) {
tmp = F6x8[c][i];
} else {
tmp = ~(F6x8[c][i]);
}
for(j=0;j<8;j++) {
if(tmp&(0x80>>j)) {
OLED_Set_Pixel(x+j, y+i,1);
} else {
OLED_Set_Pixel(x+j, y+i,0);
}
}
}
} else {
return;
}
}
void GUI_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size,uint8_t mode) {
unsigned char j=0,csize;
if(Char_Size == 16) {
csize = Char_Size/2;
} else if(Char_Size == 8) {
csize = Char_Size/2+2;
} else {
return;
}
while (chr[j]!='\0') {
GUI_ShowChar(x,y,chr[j],Char_Size,mode);
x+=csize;
if(x>120) {
x=0;
y+=Char_Size;
}
j++;
}
OLED_Display();
}
static uint32_t mypow(uint8_t m,uint8_t n) {
uint32_t result=1;
while(n--)result*=m;
return result;
}
void GUI_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t Size,uint8_t mode) {
uint8_t t,temp;
uint8_t enshow=0,csize;
if(Size == 16) {
csize = Size/2;
} else if(Size == 8) {
csize = Size/2+2;
} else {
return;
}
for(t=0;t<len;t++) {
temp=(num/mypow(10,len-t-1))%10;
if(enshow==0&&t<(len-1)) {
if(temp==0) {
GUI_ShowChar(x+csize*t,y,' ',Size,mode);
continue;
} else {
enshow=1;
}
}
GUI_ShowChar(x+csize*t,y,temp+'0',Size,mode);
}
OLED_Display();
}
void OLED_ShowFNum(u8 x,u8 y,float Fnum,u8 size1,u8 mode)
{
unsigned int i,flen;
unsigned char Data[sizeof(Fnum)]; //数据位数由sizeof(Fnum) 来判断,灵活创建数组大小
sprintf((char *)Data,"%.3f",Fnum); //保留小数点后3位小数,打印到Data数组中
flen = sizeof(Data)+1; //判断浮点数长度,方便后期打印输出
for(i=0;i<flen;i++){ //根据转后字符长度打印输出
x+=8; //每个字符占8位,向后占位
GUI_ShowChar(x,y,Data[i],size1,mode); //调用oled字符显示函数,在OLED屏上逐个显示
}
}
void GUI_ShowCHinese(uint8_t x,uint8_t y,uint8_t hsize,uint8_t *str,uint8_t mode) {
while(*str!='\0') {
if(hsize == 16) {
GUI_ShowFont16(x,y,str,mode);
} else if(hsize == 24) {
//GUI_ShowFont24(x,y,str,mode);
} else if(hsize == 32) {
//GUI_ShowFont32(x,y,str,mode);
} else if(hsize == 12) {
GUI_ShowFont12(x,y,str,mode);
} else {
return;
}
if (hsize==12) {
x+=16;
} else {
x+=hsize;
}
if(x>WIDTH-hsize) {
x=0;
y+=hsize;
}
str+=2;
}
OLED_Display();
}
void GUI_DrawBMP(uint8_t x,uint8_t y,uint8_t width, uint8_t height, uint8_t BMP[], uint8_t mode) {
uint8_t i,j,k;
uint8_t tmp;
for(i=0;i<height;i++) {
for(j=0;j<(width+7)/8;j++) {
if(mode) {
tmp = BMP[i*((width+7)/8)+j];
} else {
tmp = ~BMP[i*((width+7)/8)+j];
}
for(k=0;k<8;k++) {
if(tmp&(0x80>>k)) {
OLED_Set_Pixel(x+j*8+k, y+i,1);
} else {
OLED_Set_Pixel(x+j*8+k, y+i,0);
}
}
}
}
OLED_Display();
}
#ifndef __OLED_H
#define __OLED_H
#include "at32f423.h"
#define PAGE_SIZE 8
#define XLevelL 0x00
#define XLevelH 0x10
#define YLevel 0xB0
#define Brightness 0xFF
#define WIDTH 128
#define HEIGHT 64
#define OLED_CMD 0 //写命令
#define OLED_DATA 1 //写数据
#define IIC_SLAVE_ADDR 0x78
//IIC操作函数
void II2CGpioInit(void);
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Wait_Ack(void);
void Write_IIC_Byte(uint8_t IIC_Byte);
void Write_IIC_Command(uint8_t IIC_Command);
void Write_IIC_Data(uint8_t IIC_Data);
//OLED控制函数
void OLED_WR_Byte(unsigned char dat,unsigned char cmd);
void OLED_Display_On(void);
void OLED_Display_Off(void);
void OLED_Set_Pos(unsigned char x, unsigned char y);
void OLED_Init(void);
void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color);
void OLED_Display(void);
void OLED_DisplayBMP(unsigned char *datoid);
void OLED_Clear(void);
//void OLED_Clear(unsigned char dat);
//GUI画图函数
void GUI_DrawPoint(unsigned char x, unsigned char y, unsigned char color);
void GUI_Fill(unsigned char sx,unsigned char sy,unsigned char ex,unsigned char ey,unsigned char color);
void GUI_DrawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2,unsigned char color);
void GUI_DrawRectangle(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2,unsigned char color);
void GUI_FillRectangle(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2,unsigned char color);
void GUI_DrawCircle(unsigned char xc, unsigned char yc, unsigned char color, unsigned char r);
void GUI_FillCircle(unsigned char xc, unsigned char yc, unsigned char color, unsigned char r);
void GUI_DrawTriangel(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char color);
void GUI_FillTriangel(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char color);
void GUI_ShowChar(unsigned char x,unsigned char y,unsigned char chr,unsigned char Char_Size,unsigned char mode);
void GUI_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t Size,uint8_t mode);
void OLED_ShowFNum(u8 x,u8 y,float Fnum,u8 size1,u8 mode);
void GUI_ShowString(unsigned char x,unsigned char y,unsigned char *chr,unsigned char Char_Size,unsigned char mode);
void GUI_ShowFont16(unsigned char x,unsigned char y,unsigned char *s,unsigned char mode);
void GUI_ShowFont24(unsigned char x,unsigned char y,unsigned char *s,unsigned char mode);
void GUI_ShowFont32(unsigned char x,unsigned char y,unsigned char *s,unsigned char mode);
void GUI_ShowCHinese(unsigned char x,unsigned char y,unsigned char hsize,unsigned char *str,unsigned char mode);
void GUI_DrawBMP(unsigned char x,unsigned char y,unsigned char width, unsigned char height, unsigned char BMP[], unsigned char mode);
#endif
#include "at32f423_board.h"
#include "at32f423_clock.h"
#include "ds18b20.h"
#include "oled.h"
#include "bmp.h"
int main(void)
{
uint8_t i, DS18B20ID[8];
char str[50];
__IO char ch,count=0;
float temperature;
system_clock_config();
at32_board_init();
uart_print_init(115200);
OLED_Init();
OLED_Clear();
while (DS18B20_Init())
{
printf("DS18B20 Init Error\r\n");
delay_ms(1000);
}
DS18B20_ReadId(DS18B20ID);
printf("DS18B20的序列号是: 0x");
for ( i = 0; i < 8; i ++ )
printf ( "%.2X", DS18B20ID[i]);
printf("\n");
sprintf(str,"DS18B20的序列号是:0x%02X%02X%02X%02X%02X%02X%02X%02X",DS18B20ID[0],DS18B20ID[1],DS18B20ID[2],DS18B20ID[3],DS18B20ID[4],DS18B20ID[5],DS18B20ID[6],DS18B20ID[7]);
OLED_Clear();
GUI_ShowCHinese(26,10,16,(unsigned char *)"欢迎使用",0);
GUI_ShowCHinese(10,28,16,(unsigned char *)"雅特力开发板",0);
GUI_ShowString(10,46,(uint8_t *)"AT32F423VCT7",16,0);
delay_ms(1800);
while(1)
{
temperature=DS18B20_GetTemp_MatchRom(DS18B20ID);
/* 打印通过 DS18B20 序列号获取的温度值 */
printf("获取该序列号器件的温度:%.1f\n",temperature);
sprintf(str,"当前温度值为:%0.3f℃",temperature);
OLED_Clear();
GUI_ShowCHinese(10,10,16,(unsigned char *)"当前室内温度",0);
GUI_ShowString(106,10,(uint8_t *)":",16,0);
OLED_ShowFNum(32,28,temperature,16,0);
GUI_ShowCHinese(80,28,16,(unsigned char *)"℃",0);
GUI_ShowString(48,46,(uint8_t *)"2023-12-03",16,0);
delay_ms(800);
OLED_Clear();
GUI_DrawBMP(0,0,128,64,BMP2,0);
delay_ms(800);
}
}
制作的单色位图如下:
使用“PCtoLCD2002”的参数设置如下:
工程编译完成后,下载到开发板,OLED屏显示想关字符与图片,在此期间,将手指握住DS18B20模块,则采集的温度数值会迅速上升;然后将手指挪开,则采集的温度数值会缓慢回降。
https://v.youku.com/v_show/id_XNjIwOTE5Nzk2OA==.html
|
|