当前位置:网站首页>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
边栏推荐
- OpenHarmony如何启动FA(本地和远程)
- 选择 SAP Spartacus 作为 SAP Commerce Cloud Storefront 实现框架的五个理由
- 每日一题——倒置字符串
- Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service
- 一日2篇Nature!中科大校友段镶锋团队纳米材料新成果,曾是贝尔比奖章第三位华人得主...
- vector的底层模拟实现
- RK1126平台项目总结
- Keras' deep learning practice -- gender classification based on vgg19 model
- Common SQL statements (complete example)
- Linux中,mysql设置job任务自动启动
猜你喜欢
Modbus协议通信异常
阿里天池SQL学习笔记——DAY3
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
科班出身,面试小公司都进不去
【历史上的今天】7 月 2 日:BitTorrent 问世;商业系统 Linspire 被收购;索尼部署 PlayStation Now
Keras深度学习实战——基于VGG19模型实现性别分类
wps插入图片后使图片完整显示
[nonlinear control theory]8_ Comparison of three robust controllers
2 juillet: BitTorrent est sorti; L'acquisition du système commercial linspire; Sony Deployment PlayStation now
si446使用记录(二):使用WDS3生成头文件
随机推荐
什么是软件开发中的 green field 和 brown field 模式 - 绿地开发和棕地开发
义隆EM78P153K DIP14单片机 MCU
泡椒凤爪制作教程
嵌入式开发板 ~ 说明
【网络是怎么连接的】第四章 探索接入网和网络运营商
蓝牙技术|物联网的可穿戴设备新工作模式,蓝牙BLE助力新工作模式
helm kubernetes包管理工具
Configure lamp+supervisor
外包干了五年,废了...
uva1169
嵌入式 ~ 介绍
Virtual lab basic experiment tutorial -7 Polarization (1)
Helm kubernetes package management tool
VirtualLab基础实验教程-7.偏振(1)
Easyswoole3.2 restart failed
List summation [dummy+ tail interpolation + function processing list reference common pit]
Daily question - xiaolele changes the number
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
Solving simple differential equations
HDU - 1114 Piggy-Bank(完全背包)