当前位置:网站首页>九齐单片机NY8B062D单按键控制4种LED状态
九齐单片机NY8B062D单按键控制4种LED状态
2022-07-04 18:45:00 【51CTO】
/* =========================================================================
* Project: 单按键控制4种LED状态
* File: 单按键控制4种LED状态
* Description: 单按键控制4种LED状态
*
*
* Author: Jimp
* Version: V1.0
* Date: 2020/05/22
=========================================================================*/
//--------------- File Include ---------------------------------------------
//--------------------------------------------------------------------------
#include <ny8.h>
#include <stdint.h>
#include "ny8_constant.h"
#define UPDATE_REG(x) __asm__("MOVR _" #x ",F")
#define unchar unsigned char
#define unint unsigned int
uint8_t myvar;
__sbit flag = myvar:0; //定义控制运行符
__sbit key = PORTB:0;
__sbit light1 = PORTA:7;
__sbit light2 = PORTA:6;
unchar Mod; //定义亮灯模式
void isr(void) __interrupt(0)
{
if(INTFbits.T0IF)
{
static unsigned int cnt= 0;
TMR0 = 0;
INTF= (unsigned char)~(C_INT_TMR0); // Clear T0IF flag bit
cnt ++;
if(cnt >= 250)
{
cnt = 0;
light1 = ~light1;
light2 = ~light2;
}
}
}
void lnit_Mod() //初始化函数
{
IOSTA = ~IOSTA; //设置A口为输出
PORTA = 0xFF;
IOSTB = C_PB0_Input;
flag = 1;
key = 1;
Mod = 0;
light1 = 0;
light2 = 0;
}
void lnit_Timer() //中断初始化
{
DISI(); //禁用中断
PCON1 = C_TMR0_Dis;
TMR0 = 0;
T0MD = C_PS0_TMR0 | C_PS0_Div8; //预分频分配给TMR0
INTE = C_INT_TMR0;
ENI(); //启用中断
}
void delay(unint z) //延时函数ms
{
unint x,y;
for(x = z;x > 0;x--)
for(y = 100;y > 0;y--);
}
void lnput_Mod() //状态模式标记函数
{
if(Mod == 4)
Mod = 0;
if(key == 0)
{
delay(5);
if(key == 0) //延时消抖
Mod++; //按键次数标记
}
while(!key) //松手检测
{;;}
}
void run() //4种模式下的执行
{
switch(Mod)
{
case 0:{PCON1 = C_TMR0_Dis;light1 = 0;light2 = 0;}break; //全亮
case 1:{PCON1 = C_TMR0_En;}break; //同步闪烁
case 2:{PCON1 = C_TMR0_Dis;light1 = 1;light2 = 1;}break; //全灭
case 3:{PCON1 = C_TMR0_Dis;light1 = 0;light2 = 1;PCON1 = C_TMR0_En;}break; //异步闪
}
}
void main(void)
{
lnit_Mod();
lnit_Timer();
while(1)
{
lnput_Mod();
if(flag == 1) //控制RUN运行
{
run();
if(Mod == 1||Mod == 3)
flag = 0;
}
if(Mod == 0||Mod == 2)
flag = 1;
}
}
边栏推荐
猜你喜欢
What is the application technology of neural network and Internet of things
同事的接口文档我每次看着就头大,毛病多多。。。
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
Qt编写物联网管理平台38-多种数据库支持
上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?
On communication bus arbitration mechanism and network flow control from the perspective of real-time application
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Introduction to ACM combination counting
Cbcgpprogressdlg progress bar used by BCG
In operation (i.e. included in) usage of SSRs filter
随机推荐
node强缓存和协商缓存实战示例
Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
Basic use of kotlin
Jetpack compose tutorial
Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Dark horse programmer - software testing - stage 07 2-linux and database -09-24-linux command learning steps, wildcards, absolute paths, relative paths, common commands for files and directories, file
Dynamic memory management
Cbcgpprogressdlg progress bar used by BCG
Detailed explanation of Audi EDI invoice message
TCP waves twice, have you seen it? What about four handshakes?
Template_ Judging prime_ Square root / six prime method
Lingyun going to sea | Wenhua online & Huawei cloud: creating a new solution for smart teaching in Africa
Write it down once Net analysis of thread burst height of an industrial control data acquisition platform
1002. A+b for Polynomials (25) (PAT class a)
BCG 使用之CBCGPProgressDlgCtrl進度條使用
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
Niuke Xiaobai month race 7 e applese's super ability
c# .net mvc 使用百度Ueditor富文本框上传文件(图片,视频等)
Employment prospects and current situation of Internet of things application technology