当前位置:网站首页>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
边栏推荐
- [非线性控制理论]8_三种鲁棒控制器的比较
- si446使用记录(二):使用WDS3生成头文件
- PCL知识点——体素化网格方法对点云进行下采样
- AtCoder Beginner Contest 237 VP补题
- 售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
- 智能水电表能耗监测云平台
- 【网络是怎样连接的】第六章 请求到达服务器以及响应给客户端(完结)
- Update iteration of cloud communication interface -- the official launch of subail API V4
- 蓝牙技术|物联网的可穿戴设备新工作模式,蓝牙BLE助力新工作模式
- Laravel文档阅读笔记-Custom Authentication Login And Registration Using Laravel 8
猜你喜欢
MB10M-ASEMI整流桥MB10M
[how is the network connected] Chapter 4 explores access networks and network operators
VirtualLab基础实验教程-7.偏振(2)
pytorch支持32位吗?
[非线性控制理论]8_三种鲁棒控制器的比较
[非线性控制理论]7_High gain and High Frequency
Keras' deep learning practice -- gender classification based on vgg19 model
Platform management background and merchant menu resource management: merchant role management design
阿里天池SQL学习笔记——DAY3
freemarker+poi实现动态生成excel文件及解析excel文件
随机推荐
科班出身,面试小公司都进不去
Alibaba Tianchi SQL learning notes - Day3
每日一题——倒置字符串
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
JDBC
What is the experience of maintaining Wanxing open source vector database
牛客JS2 文件扩展名
Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
Atcoder beginer contest 237 VP supplement
Easyswoole3.2 restart failed
Niuke js3 separator
Microservice architecture practice: Construction of scalable distributed database cluster
Migrate your accelerator based SAP commerce cloud storefront to Spartacus
[target tracking] | data set summary
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)
Briefly introduce the use of base64encoder