青年是整个社会力量中的一部分最积极最有生气的力量。他们最肯学习,最少保守思想,在社会主义时代尤其是这样。——毛泽东
被朋友委托研究了新大陆的lora-nb通用库文件,在这里给大家分享一下,研究后的代码,考虑到朋友的学生,对软件和代码理解不深。先交大家两个在Keil uVision5中非常好用的方法。
方法一:跳转到对应的库文件,只需要双击全选函数或者头文件,然后点击键盘上的F12键或者右键选择"Open ....."或“Go To.....”(开头的选项就行)就能跳转到对应的库文件中,新大陆的库中都有注释。都要靠知己去找。去理解而不是一味的抄。
方法二:代码提示选项,其他的工具都有代码提示,比如java,python,php......等等。新大陆默认把代码提示给关闭掉了,一个字,恶心。现在教大家怎么操作。
上面看不懂的朋友,这个网址非常详细https://blog.csdn.net/sinat_26528193/article/details/113769716
接下来都是代码了
/**
******************************************************************************
* File Name : main.c
* Description : Main program body
******************************************************************************
*/
#include <string.h>
#include "board.h"
#include "hal_key.h"
#include "tim-board.h"
#include "timer_handles.h"
///////////////////////////////////////////////////////////////////////////
#include "sht3x.h"//温湿度函数使用必要头文件
#include "adc_reader.h"//ADC函数使用必要头文件
int x=16;
//中文定义
char guang[]={0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,0x40,0xC0,0x50,0x48,0x46,0x40,0x40,0x00,
0x80,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,};
char zhao[]={0x00,0xFE,0x42,0x42,0x42,0xFE,0x00,0x42,0xA2,0x9E,0x82,0xA2,0xC2,0xBE,0x00,0x00,
0x80,0x6F,0x08,0x08,0x28,0xCF,0x00,0x00,0x2F,0xC8,0x08,0x08,0x28,0xCF,0x00,0x00,};
char wen[]={0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,};
char shi[]={0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00,};
char du[]={0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,};
//////////////////////////////////////////////////////////////////////////
void Init() {
BoardInitMcu();
BoardInitPeriph();
keys_init();//按键初始化
setTimer2Callback(Time2Handler);
Tim2McuInit(1);//定时器初始化,设置定时中断1ms中断一次
////////////////////////////////////////////////////////////////////////
OLED_Init();//屏幕初始化
OLED_Clear();//清空屏幕
hal_temHumInit();//温湿度初始化
ADCS_Init();//ADC初始化
GpioWrite( &Led1, 1 );//默认关灯 LED1 LED2 低电平点亮将1改为0即可
GpioWrite( &Led2, 1 );
////////////////////////////////////////////////////////////////////////
}
float wd,sd,gz;
char gzsj[11],wdsj[11],sdsj[11];
/**
* Main application entry point.
*/
int main( void )
{
Init();
OLED_ShowCHineseArray(0*x,0,guang);
OLED_ShowCHineseArray(1*x,0,zhao);
OLED_ShowCHineseArray(0*x,2,wen);
OLED_ShowCHineseArray(1*x,2,du);
OLED_ShowCHineseArray(0*x,4,shi);
OLED_ShowCHineseArray(1*x,4,du);
OLED_ShowString(2*x,0,":");
OLED_ShowString(2*x,2,":");
OLED_ShowString(2*x,4,":");
//基础显示
while( 1 )
{
AdcScanChannel();//获取ADC数据
call_sht11(&wd,&sd);//获取温湿度数据和赋值
gz=AdcReadCh0();//赋值
sprintf(gzsj,"%0.2f",gz);
sprintf(wdsj,"%0.2f",wd);
sprintf(sdsj,"%0.2f",sd);
OLED_ShowString(3*x,0," ");
OLED_ShowString(3*x,2," ");
OLED_ShowString(3*x,4," ");
OLED_ShowString(3*x,0,gzsj);//光照数据
OLED_ShowString(3*x,2,wdsj);//温度数据
OLED_ShowString(3*x,4,sdsj);//湿度数据
HAL_Delay(100);
if(isKey2Pressed()){//按键一
resetKey2();
GpioToggle(&Led1);//电平翻转
}
if(isKey3Pressed()){//按键二
resetKey3();
GpioToggle(&Led1);//电平翻转
}
if(isKey4Pressed()){//按键三
resetKey4();
GpioToggle(&Led2);//电平翻转
}
}
}
将代码复制下来粘贴进main文件里面就行然后烧写就行,代码主要还是要靠知己理解,库多翻翻就会简单,现在是显示图片。显示图片也是非常的简单。
/**
******************************************************************************
* File Name : main.c
* Description : Main program body
******************************************************************************
*/
#include <string.h>
#include "board.h"
#include "hal_key.h"
#include "tim-board.h"
#include "timer_handles.h"
void Init() {
BoardInitMcu();
BoardInitPeriph();
keys_init();//按键初始化
setTimer2Callback(Time2Handler);
Tim2McuInit(1);//定时器初始化,设置定时中断1ms中断一次
OLED_Init();
OLED_Clear();
}
unsigned char tu1[]={0x00,0x00,0x80,0x80,0xC0,0xC0,0x60,0xFC,0x60,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,
0x00,0x01,0x01,0x00,0x00,0x10,0x18,0x1F,0x18,0x10,0x00,0x00,0x01,0x01,0x00,0x00,/图片定义
};
/**
* Main application entry point.
*/
int main( void )
{
Init();
OLED_DrawBMP(0,0,16,16,tu1);//显示图片 函数含义库里有写
while( 1 )
{
}
}
OK今天就分享到这了。下一期是折线图。折线图也非常简单,他库中本来有函数可以调用的,结果代码好像被删掉了,或者被注释掉了,自己写一个也不难30行搞定。