1 Star 0 Fork 16

inmen/pellet stove controll

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
风之羽 提交于 2015-10-24 11:48 . 10.24 11:40
#include "mbed.h"
#include "rtos.h"
#include "BusOut.h"
#include "BusInOut.h"
#include "keypad.h"
#include "RTC8563.h"
#include "ds1820.h"
#include "sh1106.h"
Keypad keypad(PA_11,PA_12, PC_2, PC_3, PC_1, PC_15, PC_13, PE_5); // 4*4矩阵键盘
Serial serial(PA_2, PA_3); // Serial (PinName tx, PinName rx)
RTC8563 rtc(I2C2_SDA, I2C2_SCL); // PCF8563 时钟
DS1820 ds18b20(PE_2); // ds18b20 传感器
/* OLED:
*GND:电源地
*VCC:供电电源3.3V、5V都可以
*SCK:串行输入时钟CLKD1:串行输入数据 PA_5
*SDA: MOSI PA_7
*RES:复位 PC_14
*CS: 片选 PA_8
*DC: 控制输入数据/命令(高电平(1)为数据,低电平(0)为命令) PC_15
*/
//SH1106: cs-PB_12, rs-PE_4, dc-PE_6, clk-PB_13, data-PB_15
SH1106 oled(SPI2_CS, PE_4, PE_6 , SPI2_SCK, SPI2_MOSI);
//线程: 键盘扫描
void keypad_thread_callback(void const *argument) {
while(1){
keypad.Scan_Keyboard();
KeyPressed key_pressed = keypad.getKey();
switch(key_pressed) {
case Key_Up:
serial.printf("Up, 0x%2x\r\n", key_pressed);
oled.set_font(standard_font, 16);
break;
case Key_Down:
serial.printf("Down, 0x%2x\r\n", key_pressed);
oled.set_font(standard_font, 8);
break;
case Key_On:
serial.printf("On, 0x%2x\r\n", key_pressed);
break;
default:
if ( key_pressed != Key_None)
serial.printf("any key, 0x%2x\r\n", key_pressed);
}
if ( key_pressed != Key_None){
oled.clear();
oled.set_cursor(2,3);
oled.printf("风雨无阻");
oled.update();
}
Thread::wait(10);
}
}
//线程: 读取时间
void readtime_thread_callback(void const *argument) {
TIME *time;
while(1){
time = rtc.rtc_read();
serial.printf("%4d,%2d,%2d,%2d:%2d:%2d\r\n", time->year, time->month,time->day,
time->hour, time->minute, time->second);
Thread::wait(1000);
}
}
int main()
{
// serial
serial.baud(9600);
serial.format();
serial.printf("Hellow, world!\r\n");
//Thread readtime_thread(readtime_thread_callback, NULL, osPriorityHigh); //启动rtc线程
Thread keypad_thread(keypad_thread_callback);
float temp;
//oled
oled.initialise();
oled.clear();
oled.set_font(standard_font, 6);
oled.printf("hellow, world!");
oled.update();
while (1) {
// ds18b20
if(!ds18b20.isPresent())
ds18b20.begin();
if (ds18b20.isPresent()) {
ds18b20.startConversion();
temp = ds18b20.read(); // 读取温度 1,放在主线程里
serial.printf("Temp. is %4.2f\r\n", temp);
}
Thread::wait(2000);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hugewave/pellet-stove-controll.git
git@gitee.com:hugewave/pellet-stove-controll.git
hugewave
pellet-stove-controll
pellet stove controll
master

搜索帮助