当前位置:网站首页>PMS150C应广单片机开发案例
PMS150C应广单片机开发案例
2022-07-02 15:50:00 【深圳市泛海微电子有限公司】
PMS150C应广单片机开发案例
应广单片机价格美丽,性价比高,mini-c好用,适用于消费电子开发。但是案例demo太少了,为了方便大家能够快速入门。这里贴出了一份经典PMS150C的点灯程序代码。不是Hello world!那种,是偏向于实际产品的那种。
涉及到的内容有不少,包括应广单片机PMS150C:
1.端口输入输出配置
2.Tmr16中断配置(systick),倒计时
3.按键检测,包括防抖,可以用于长按键检测
4.低功耗,睡眠配置
5.唤醒
6.系统时钟配置,系统时钟切换
7.看门狗应用
8.状态机应用
其他比如PMS152,PMS132设置也类似,希望大家喜欢!
#include "extern.h"
#define HIGH 1
#define LOW 0
#define DISABLE 0
#define ENABLE 1
#define EMPTY 0
#define FULL 1
#define ON 1
#define OFF 0
#define LED_OPEN 0
#define LED_FLASH 1
#define LED_BREATH 2
#define LED_CLOSE 3
//#define RUN_TMR 60000
/*单位 ms*/
#define RUN_TMR 15000
#define LOW_POW_TIMING_TMR 3000
BIT LED_G : PA.3;
BIT KEY_HIT : PA.4;
#define KEY_DEBOUNCE_CNT 20
#define KEY_LONG_PRESS_TIMER 1200
#define GRE_LED_FLASH {if(LED_G){LED_G=0;}else{ LED_G=1;}}
/*计数值Cinit*/
word ucFlashTmrCnt;
/*cinit*/
BIT ubMsFlag;
/*cinit*/
BIT ubEnLedFlash;
/*cinit*/
bit ubMod;
byte ucSysSt;
//byte ucLedPwmDt;
/*定时时间是否到了cinit*/
bit FLAG_NMS;
/*计数值cinit*/
byte count;
/*定时器初始化cinit*/
word T16COUNTER;
Eword ueLowPowAltTm;
byte ucKeyHitHigtCnt;
byte ucKeyHitLowCnt;
byte ucKeyHitSt;
byte ucKeyHitBak;
word usKeyHitLoPreCnt;
word usKeyHitLoPreCntSet;
bit ucKeyHitPreSt;
byte ucLedSt;
void UpDateLedSt(void);
/***************************************/
void TIME16_Init(void)
{
/*计数值清零*/
T16COUNTER =488;
/*ms标记reset*/
FLAG_NMS =0;
/*使能定时器*/
$ INTEN T16;
/*关中断*/
INTRQ = 0;
/*停止定时器*/
T16M.5 =0;
STT16 T16COUNTER;
/*计算方法16M/*/
$ T16M IHRC,/1,BIT11;
}
void StartLowPowTmr(void)
{
ueLowPowAltTm=RUN_TMR;
}
/*低功耗*/
void LowPow(void)
{
/*退出功能则进入低功耗*/
if((!ueLowPowAltTm) )
{
ubEnLedFlash=0;
GRE_LED_OFF;
wdreset;
/*IHRC ->ILRC,关看门狗*/
CLKMD=0xf4;
/*禁用IHRC*/
CLKMD.4=0;
while(1)
{
/*低功耗*/
STOPSYS;
/*有按键按下,充电和按键唤醒*/
if(KEY_HIT==0)
{
/*退出低功耗*/
break;
}
}
/*ILRC->IHRC ,
b7:[email protected]=IHRC/8,
[email protected]=IHRC
[email protected]=模式1
[email protected] 1=ILRC启动
[email protected] 1=看门狗开启
[email protected] 0=Pa5;
模式口1;开看门狗*/
CLKMD=0b001_1_1110;
ucLedSt=1;
ucSysSt=LED_CLOSE;
StartLowPowTmr();
}
}
void UpdateLedTmr(void)
{
/*使能,闪灯*/
if(ubEnLedFlash)
{
/*1ms进行一次计数*/
ucFlashTmrCnt++;
if(ucFlashTmrCnt>250)
{
ucFlashTmrCnt=0;
/*标记*/
ubMsFlag=1;
}
}
}
/*闪灯*/
void FlashLed(void)
{
/*定时时间到*/
if(ubMsFlag)
{
/*闪灯*/
GRE_LED_FLASH;
ubMsFlag=0;
}
}
/*端口检测*/
void ResetKeyTmr(void)
{
if(KEY_HIT)
{
ucKeyHitHigtCnt=KEY_DEBOUNCE_CNT;
}
/*当前状态为0*/
else
{
ucKeyHitLowCnt=KEY_DEBOUNCE_CNT;
}
}
/*1ms任务函数*/
void UpDateKeyTmr(void)
{
/*重新设置计数值*/
ResetKeyTmr();
/*KeyHit高电平计数值*/
if(ucKeyHitHigtCnt)
{
ucKeyHitHigtCnt--;
if(!ucKeyHitHigtCnt)
{
/*高电平倒计时完成说明当前为低*/
ucKeyHitSt=LOW;
}
}
/*高电平计数值为0*/
else
{
usKeyHitLoPreCnt++;
/*做饱和加*/
if(usKeyHitLoPreCnt>20000)
{
usKeyHitLoPreCnt=20000;
}
if(usKeyHitLoPreCnt==usKeyHitLoPreCntSet)
{
/*10s 钟定信号*/
ucKeyHitPreSt=1;
}
}
/*KeyHit低电平计数值*/
if(ucKeyHitLowCnt)
{
ucKeyHitLowCnt--;
if(!ucKeyHitLowCnt)
{
/*低电平倒计时完成,说明当前为高*/
ucKeyHitSt=HIGH;
usKeyHitLoPreCnt=0;
ucKeyHitPreSt=0;
}
}
}
void MsTask(void)
{
/*按键*/
UpDateKeyTmr();
UpdateLedTmr();
FlashLed();
/*低功耗定时器*/
if(ueLowPowAltTm)
{
ueLowPowAltTm--;
}
LowPow();
}
void UpDateLedSt(void)
{
ucSysSt++;
if(ucSysSt>1)
{
ucSysSt=0;
}
switch(ucSysSt)
{
/*开闪烁*/
case 0:
ubEnLedFlash=1;
break;
/*关灯*/
case 1:
ueLowPowAltTm=LOW_POW_TIMING_TMR;
ubEnLedFlash=0;
/*关灯,关闪烁*/
GRE_LED_OFF;
/*关灯*/
break;
default:
break;
}
}
/*状态切换*/
void GetKeySt(void)
{
/*状态有变化*/
if(ucKeyHitSt!=ucKeyHitBak)
{
/*保存当前状态*/
ucKeyHitBak=ucKeyHitSt;
if(!ucKeyHitSt)
{
/*更新倒计时*/
StartLowPowTmr();
/*状态切换*/
UpDateLedSt();
}
}
}
/*端口状态初始化*/
void KeyAppInit(void)
{
if(KEY_HIT)
{
ucKeyHitSt=HIGH;
ucKeyHitBak=HIGH;
}
else
{
ucKeyHitSt=LOW;
ucKeyHitBak=LOW;
}
ucKeyHitHigtCnt=KEY_DEBOUNCE_CNT;
ucKeyHitLowCnt=KEY_DEBOUNCE_CNT;
usKeyHitLoPreCnt=0;
ucKeyHitPreSt=0;
}
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/8, IHRC=16MHz, VDD=3.0V;
$ CLKMD IHRC/8,En_IHRC,En_ILRC,En_WatchDog;
/**/
.delay 40000;
$ LED_G OUT,HIGH;
$ KEY_HIT IN,PULL;
TIME16_Init();
KeyAppInit();
ucLedSt=1;
ubMsFlag=0;
ubEnLedFlash=0;
/*长按键时间*/
usKeyHitLoPreCntSet=3000;
ucSysSt=LED_CLOSE;
engint;
while (1)
{
wdreset;
/*1ms定时时间到*/
if ( FLAG_NMS )
{
MsTask();
/*清除标记*/
FLAG_NMS=0;
}
/*取得按键状态*/
GetKeySt();
}
}
void Interrupt ( void )
{
pushaf;
if ( Intrq.T16 )
{
Intrq.T16 = 0;
STT16 T16COUNTER;
if ( count>0 )
{
count--;
}
else
{
count = 9;
/*1ms*/
FLAG_NMS= 1;
}
}
popaf;
}
/*end create by zhongvv
————————————————
版权声明:本文为CSDN博主「zhongvv」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhongvv/article/details/103430996
边栏推荐
- SAP commerce Cloud Architecture Overview
- 台风来袭,多景区暂时关闭,省文旅厅提醒注意安全!
- uniapp H5页面调用微信支付
- 【網絡是怎樣連接的】第六章 請求到達服務器以及響應給客戶端(完結)
- Making tutorial of chicken feet with pickled peppers
- ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
- Keras' deep learning practice -- gender classification based on vgg19 model
- Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
- Si446 usage record (I): basic data acquisition
- vector的底层模拟实现
猜你喜欢
si446使用记录(一):基本资料获取
Virtual lab basic experiment tutorial -7 Polarization (1)
Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Alibaba Tianchi SQL learning notes - Day3
线性规划例题 投资的收益与风险
List summation [dummy+ tail interpolation + function processing list reference common pit]
每日一题——倒置字符串
智能水电表能耗监测云平台
RK1126平台项目总结
随机推荐
牛客JS2 文件扩展名
Navigateur Chrome pour un accès rapide au stackoverflow
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
[nonlinear control theory]8_ Comparison of three robust controllers
POJ - 1458 Common Subsequence(最长公共子序列)
si446使用记录(二):使用WDS3生成头文件
Introduce the scrollintoview() method attribute in detail
easyAI笔记——深度学习
POJ - 1458 common subsequence (longest common subsequence)
SAP commerce cloud storefront framework selection: accelerator or Spartacus?
freemarker+poi实现动态生成excel文件及解析excel文件
常用SQL语句(完整范例)
售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
SAP Commerce Cloud 架构概述
链表求和[dummy+尾插法+函数处理链表引用常见坑位]
阿里云子账户 - 权限策略 - 授权给某个账户某个 OSS Bucket 的完全控制权限
Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service
Keras' deep learning practice -- gender classification based on vgg19 model
Briefly introduce the use of base64encoder
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer