当前位置:网站首页>九齐单片机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;
}
}
边栏推荐
- Cbcgpprogressdlgctrl progress bar used by BCG
- 1007 maximum subsequence sum (25 points) (PAT class a)
- 多表操作-内连接查询
- Find the nth power of 2
- 解密函数计算异步任务能力之「任务的状态及生命周期管理」
- Detailed explanation of Audi EDI invoice message
- 15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
- How is the entered query SQL statement executed?
- 实战模拟│JWT 登录认证
- C # use stopwatch to measure the running time of the program
猜你喜欢
Niuke Xiaobai month race 7 who is the divine Archer

关于联邦学习和激励的相关概念(1)

多表操作-外连接查询

Cbcgptabwnd control used by BCG (equivalent to MFC TabControl)

做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!

什么叫内卷?

【历史上的今天】7 月 4 日:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生

What are the consequences of closing the read / write channel?

c# .net mvc 使用百度Ueditor富文本框上传文件(图片,视频等)

CANN算子:利用迭代器高效实现Tensor数据切割分块处理
随机推荐
JVM系列之对象的创建
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
Template_ Judging prime_ Square root / six prime method
Pointnext: review pointnet through improved model training and scaling strategies++
水晶光电:长安深蓝SL03的AR-HUD产品由公司供应
Huawei cloud store homepage banner resource bit application
Optimize if code with policy mode [policy mode]
kotlin 类和对象
TCP waves twice, have you seen it? What about four handshakes?
Prometheus installation
多表操作-外连接查询
1009 product of polynomials (25 points) (PAT class a)
Detailed explanation of Audi EDI invoice message
Lingyun going to sea | Murong Technology & Huawei cloud: creating a model of financial SaaS solutions in Africa
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
Kotlin cycle control
@Data source connection pool exhaustion caused by transactional abuse
Wireshark network packet capture
Development and construction of DFI ecological NFT mobile mining system
C # use stopwatch to measure the running time of the program