当前位置:网站首页>Pms150c Yingguang MCU development case
Pms150c Yingguang MCU development case
2022-07-02 17:49:00 【Shenzhen Oceanwide Microelectronics Co., Ltd】
PMS150C Yingguang MCU development case
The price of Yingguang single chip microcomputer is beautiful , High cost performance ,mini-c To use , Suitable for consumer electronics development . But the case demo It's too short , In order to facilitate everyone to get started quickly . A classic is posted here PMS150C Lighting program code . No Hello world! That kind of , It's the kind that favors the actual product .
There are many contents involved , It should include: PMS150C:
1. Port I / O configuration
2.Tmr16 Interrupt configuration (systick), count down
3. Key detection , Including anti shake , It can be used for long key detection
4. low power consumption , Sleep configuration
5. Wake up the
6. System clock configuration , System clock switching
7. Watchdog application
8. State machine application
Others like PMS152,PMS132 The settings are similar , Hope you enjoy it !
#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
/* Company 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;}}
/* Count value Cinit*/
word ucFlashTmrCnt;
/*cinit*/
BIT ubMsFlag;
/*cinit*/
BIT ubEnLedFlash;
/*cinit*/
bit ubMod;
byte ucSysSt;
//byte ucLedPwmDt;
/* Whether it's time cinit*/
bit FLAG_NMS;
/* Count value cinit*/
byte count;
/* Timer initialization 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)
{
/* The count value is cleared */
T16COUNTER =488;
/*ms Mark reset*/
FLAG_NMS =0;
/* Enable timer */
$ INTEN T16;
/* Close the interrupt */
INTRQ = 0;
/* Stop timer */
T16M.5 =0;
STT16 T16COUNTER;
/* computing method 16M/*/
$ T16M IHRC,/1,BIT11;
}
void StartLowPowTmr(void)
{
ueLowPowAltTm=RUN_TMR;
}
/* low power consumption */
void LowPow(void)
{
/* Exit function will enter low power consumption */
if((!ueLowPowAltTm) )
{
ubEnLedFlash=0;
GRE_LED_OFF;
wdreset;
/*IHRC ->ILRC, Shut the watchdog */
CLKMD=0xf4;
/* Ban IHRC*/
CLKMD.4=0;
while(1)
{
/* low power consumption */
STOPSYS;
/* There are buttons to press , Charging and key wakeup */
if(KEY_HIT==0)
{
/* Exit low power */
break;
}
}
/*ILRC->IHRC ,
b7:[email protected]=IHRC/8,
[email protected]=IHRC
[email protected]= Pattern 1
[email protected] 1=ILRC start-up
[email protected] 1= The watchdog opens
[email protected] 0=Pa5;
Mode port 1; Open the watchdog */
CLKMD=0b001_1_1110;
ucLedSt=1;
ucSysSt=LED_CLOSE;
StartLowPowTmr();
}
}
void UpdateLedTmr(void)
{
/* Can make , flash light */
if(ubEnLedFlash)
{
/*1ms Make a count */
ucFlashTmrCnt++;
if(ucFlashTmrCnt>250)
{
ucFlashTmrCnt=0;
/* Mark */
ubMsFlag=1;
}
}
}
/* flash light */
void FlashLed(void)
{
/* Time to */
if(ubMsFlag)
{
/* flash light */
GRE_LED_FLASH;
ubMsFlag=0;
}
}
/* Port detection */
void ResetKeyTmr(void)
{
if(KEY_HIT)
{
ucKeyHitHigtCnt=KEY_DEBOUNCE_CNT;
}
/* The current state is 0*/
else
{
ucKeyHitLowCnt=KEY_DEBOUNCE_CNT;
}
}
/*1ms Task function */
void UpDateKeyTmr(void)
{
/* Reset the count value */
ResetKeyTmr();
/*KeyHit High level count value */
if(ucKeyHitHigtCnt)
{
ucKeyHitHigtCnt--;
if(!ucKeyHitHigtCnt)
{
/* The completion of the high-level countdown indicates that it is currently low */
ucKeyHitSt=LOW;
}
}
/* The high level count value is 0*/
else
{
usKeyHitLoPreCnt++;
/* Do saturation plus */
if(usKeyHitLoPreCnt>20000)
{
usKeyHitLoPreCnt=20000;
}
if(usKeyHitLoPreCnt==usKeyHitLoPreCntSet)
{
/*10s Clock setting signal */
ucKeyHitPreSt=1;
}
}
/*KeyHit Low level count value */
if(ucKeyHitLowCnt)
{
ucKeyHitLowCnt--;
if(!ucKeyHitLowCnt)
{
/* The low level countdown is completed , Indicates that the current is high */
ucKeyHitSt=HIGH;
usKeyHitLoPreCnt=0;
ucKeyHitPreSt=0;
}
}
}
void MsTask(void)
{
/* Key */
UpDateKeyTmr();
UpdateLedTmr();
FlashLed();
/* Low power timer */
if(ueLowPowAltTm)
{
ueLowPowAltTm--;
}
LowPow();
}
void UpDateLedSt(void)
{
ucSysSt++;
if(ucSysSt>1)
{
ucSysSt=0;
}
switch(ucSysSt)
{
/* On blink */
case 0:
ubEnLedFlash=1;
break;
/* Turn off the lights */
case 1:
ueLowPowAltTm=LOW_POW_TIMING_TMR;
ubEnLedFlash=0;
/* Turn off the lights , Off flashing */
GRE_LED_OFF;
/* Turn off the lights */
break;
default:
break;
}
}
/* State switching */
void GetKeySt(void)
{
/* There is a change in state */
if(ucKeyHitSt!=ucKeyHitBak)
{
/* Save current state */
ucKeyHitBak=ucKeyHitSt;
if(!ucKeyHitSt)
{
/* Update countdown */
StartLowPowTmr();
/* State switching */
UpDateLedSt();
}
}
}
/* Port status initialization */
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;
/* Long press time */
usKeyHitLoPreCntSet=3000;
ucSysSt=LED_CLOSE;
engint;
while (1)
{
wdreset;
/*1ms Time to */
if ( FLAG_NMS )
{
MsTask();
/* Clear the mark */
FLAG_NMS=0;
}
/* Get the key status */
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
————————————————
Copyright notice : This paper is about CSDN Blogger 「zhongvv」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/zhongvv/article/details/103430996
边栏推荐
- 辉芒微IO单片机FT60F011A-RB
- ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
- 售价仅40元,树莓派Pico开发板加入WiFi模块,刚上市就脱销
- The bottom simulation implementation of vector
- Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service
- Si446 usage record (II): generate header files using wds3
- Edgenext hit a mixed punch: a lightweight architecture integrating CNN and transformer
- Income and risk of linear programming example investment
- JDBC
- 从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
猜你喜欢
![[非线性控制理论]7_High gain and High Frequency](/img/e5/6c5ca4a89c97d9613cddccb281b35b.png)
[非线性控制理论]7_High gain and High Frequency

Chrome browser quick access stackoverflow

Virtual lab basic experiment tutorial -7 Polarization (1)

PFC232-SOP8/14/16应广一级可带烧录程序编带

【Zuul】com.netflix.zuul.exception.ZuulException: Hystrix Readed time out

Chapter 15 string localization and message Dictionary (1)

From collection to output: inventory those powerful knowledge management tools - inventory of excellent note taking software (4)

每日一题——“水仙花数”

RK1126平台项目总结

freemarker+poi实现动态生成excel文件及解析excel文件
随机推荐
【历史上的今天】7 月 2 日:BitTorrent 问世;商业系统 Linspire 被收购;索尼部署 PlayStation Now
HDU - 1114 Piggy-Bank(完全背包)
【GAMES101】作业4 Bézier 曲线
Daily question - xiaolele changes the number
PMS132B单片机TWS数码管蓝牙充电仓方案开发
Daily question - inverted string
微信小程序 —— 上下浮动的箭头
把xshell連接服務器關掉,運行的jar包就自動停止的解决方案
Longest non repeating subarray
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
easyAI笔记——机器学习
辉芒微IO单片机FT60F010A-URT
应广单片机开发 工规 PMC131 带AD芯片检测电池电压单片机SOP8/14
No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
链表求和[dummy+尾插法+函数处理链表引用常见坑位]
Virtual lab basic experiment tutorial -7 Polarization (1)
Alibaba Tianchi SQL learning notes - Day3
泡椒凤爪制作教程
USB interface powered Bluetooth color light strip controller
Common SQL statements (complete example)