当前位置:网站首页>九齐单片机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;
}
}
边栏推荐
- Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
- Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world
- Key rendering paths for performance optimization
- B2B mall system development of electronic components: an example of enabling enterprises to build standardized purchase, sale and inventory processes
- SSRS筛选器的IN运算(即包含于)用法
- Write it down once Net analysis of thread burst height of an industrial control data acquisition platform
- Matrix flip (array simulation)
- 紫光展锐完成全球首个 5G R17 IoT NTN 卫星物联网上星实测
- How is the entered query SQL statement executed?
- Lingyun going to sea | Wenhua online & Huawei cloud: creating a new solution for smart teaching in Africa
猜你喜欢
Employment prospects of neural network Internet of things application technology [welcome to add]
abc229 总结(区间最长连续字符 图的联通分量计数)
什么叫内卷?
实战模拟│JWT 登录认证
Detailed explanation of Audi EDI invoice message
解密函数计算异步任务能力之「任务的状态及生命周期管理」
原来这才是 BGP 协议
In operation (i.e. included in) usage of SSRs filter
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Actual combat simulation │ JWT login authentication
随机推荐
c# .net mvc 使用百度Ueditor富文本框上传文件(图片,视频等)
Talking about cookies of client storage technology
[graduation season] green ant new fermented grains wine, red mud small stove. If it snows late, can you drink a cup?
Creation of JVM family objects
Prometheus installation
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
MySQL中的日期时间类型与格式化方式
上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?
多表操作-外连接查询
C language - Introduction - Foundation - grammar - process control (VII)
Cbcgptabwnd control used by BCG (equivalent to MFC TabControl)
泰山OFFICE技术讲座:关于背景(底纹和高亮)的顺序问题
kotlin 类和对象
What is involution?
Niuke Xiaobai month race 7 who is the divine Archer
Niuke Xiaobai month race 7 F question
node强缓存和协商缓存实战示例
1003 emergency (25 points) (PAT class a)
PHP pseudo original API docking method
HDU 1097 A hard puzzle