资源简介
STM8L低功耗应用实例,每隔30S读取一次18B20数据并通过串口发出,其它时间都处于等待模式以降低功耗
代码片段和文件信息
/**
******************************************************************************
* @file project\main.c
* @brief This file contains the firmware main function.
* @author STMicroelectronics - MCD Application Team
* @version V1.1.0
* @date 09/14/2009
******************************************************************************
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* © COPYRIGHT 2009 STMicroelectronics
* @image html logo.bmp
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include “stm8l10x.h“
#include “board.h“
#define USE_FULL_ASSERT
//#define WATCHDOG
#define WORK_TO_WAKE_RATIO 1 //工作与唤醒次数比例,每WORK_TO_WAKE_RATIO次唤醒(一般为30s)进行一次采集与上传,设置值1到32767
#define USE_SEC_ADDR //定义使用地址设置第二方案-串口设置地址,如采用IO口地址设置方式,请注释掉此句
//#define SETTING_PANID 4372 //PANID,范围1到65535,注释掉此句则不设置
//#define SETTING_TX_POWER 19 //TX_POWER,范围0~19(13.3.6后可能到21),注释掉此句则不设置
//#define SETTING_CHANNEL 8192 //CHANNEL,范围2048到134215680,注释掉此句则不设置
//#define SETTING_POLL_RATE 3000 //POLL_RATE,范围0到65535,注释掉此句则不设置
/* Private defines -----------------------------------------------------------*/
volatile u8 i;
u16 Temprature;
u8 THTLConfig;
u8 AddrHiAddrLo;
u16 AddrSettingTemp;
u8 UARTSendDataBuf[32];
s32 WakeCount=-1; //用于统计唤醒次数以实现每WORK_TO_WAKE_RATIO次唤醒一次采集上传
/* Private function prototypes -----------------------------------------------*/
void Delay(uint16_t nCount);
void DS18B20_Init(void);
u8 DS18B20_Read(void);
void DS18B20_Write(u8 Data);
void UART_Send_Data(u8 DataBuf[] u8 DataLength);
/* Private functions ---------------------------------------------------------*/
void main(void)
{
/*----------IO口设置----------*/
GPIO_Init(ADDR_LOW_PORT GPIO_Pin_All GPIO_Mode_Out_PP_Low_Slow); //8位地址
GPIO_Init(ADDR_HIGH_PORT0 ADDR_HIGH_PIN0 GPIO_Mode_Out_PP_Low_Slow); //未使用口设置为输出低电平
//P1.3/mode0 - 模块输入睡眠,stm8输出睡眠
GPIO_Init( MODE0_PORT MODE0_PIN GPIO_Mode_Out_PP_Low_Slow);
//P1.5/mode1 - 模块输出睡眠,stm8输入睡眠
//Zigbee透传模块输出给stm8的唤醒信号为高电平,并在10ms后开始发送串口信号
//由于stm8输入无内部下拉选项,因此只能设置为浮动输入
//当不接Zigbee模块单独进行stm8程序调试时,浮动输入将可能导致持续发生中断,所以请务必接入Zigbee模块或在不接入模块时改为输入上拉
GPIO_Init( MODE1_PORT MODE1_PIN GPIO_Mode_In_FL_IT);
EXTI_SetPinSensitivity(EXTI_Pin_3 EXTI_Trigger_Rising);
GPIO_Init(SENSOR_DATA_PORT SENSOR_DATA_PIN GPIO_Mode_Out_PP_High_Fast); //传感器数据口拉高
//等效为如下配
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2796 2012-05-04 11:32 18B20SensorV1_11\board.h
文件 32576 2013-03-08 14:32 18B20SensorV1_11\EWSTM8\Project.dep
文件 5701 2012-04-27 17:38 18B20SensorV1_11\EWSTM8\Project.ewd
文件 23541 2012-05-08 18:40 18B20SensorV1_11\EWSTM8\Project.ewp
文件 161 2011-11-16 17:10 18B20SensorV1_11\EWSTM8\Project.eww
文件 3435 2011-11-18 10:10 18B20SensorV1_11\EWSTM8\readme.txt
文件 1041 2013-03-08 12:17 18B20SensorV1_11\EWSTM8\settings\Project.cspy.bat
文件 8644 2013-03-08 14:32 18B20SensorV1_11\EWSTM8\settings\Project.dbgdt
文件 709 2013-03-08 14:32 18B20SensorV1_11\EWSTM8\settings\Project.dni
文件 6866 2013-03-08 14:32 18B20SensorV1_11\EWSTM8\settings\Project.wsdt
目录 0 2013-03-08 14:34 18B20SensorV1_11\EWSTM8\settings
文件 56023 2012-04-28 11:30 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x.h
文件 5116 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_awu.h
文件 3625 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_beep.h
文件 5357 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_clk.h
文件 9776 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_comp.h
文件 7222 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_exti.h
文件 7288 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_flash.h
文件 6481 2012-05-04 09:47 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_gpio.h
文件 15039 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_i2c.h
文件 2211 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_irtim.h
文件 6449 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_itc.h
文件 4804 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_iwdg.h
文件 3036 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_rst.h
文件 11161 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_spi.h
文件 26924 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_tim2.h
文件 27147 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_tim3.h
文件 10550 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_tim4.h
文件 12349 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_usart.h
文件 4408 2009-09-14 15:41 18B20SensorV1_11\EWSTM8\STM8L10x_StdPeriph_Driver\inc\stm8l10x_wfe.h
............此处省略30个文件信息
- 上一篇:TTF字体查看软件
- 下一篇:Genesis-10.05说明档
评论
共有 条评论