当前位置:网站首页>Nine Qi single chip microcomputer ny8b062d single key control four LED States
Nine Qi single chip microcomputer ny8b062d single key control four LED States
2022-07-04 23:51:00 【51CTO】
/* =========================================================================
* Project: Single key control 4 Kind of LED state
* File: Single key control 4 Kind of LED state
* Description: Single key control 4 Kind of LED state
*
*
* 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; // Define the control operator
__sbit key = PORTB:0;
__sbit light1 = PORTA:7;
__sbit light2 = PORTA:6;
unchar Mod; // Define the lighting mode
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() // Initialization function
{
IOSTA = ~IOSTA; // Set up A The mouth is the output
PORTA = 0xFF;
IOSTB = C_PB0_Input;
flag = 1;
key = 1;
Mod = 0;
light1 = 0;
light2 = 0;
}
void lnit_Timer() // Interrupt initialization
{
DISI(); // Disable interrupt
PCON1 = C_TMR0_Dis;
TMR0 = 0;
T0MD = C_PS0_TMR0 | C_PS0_Div8; // Pre frequency division is allocated to TMR0
INTE = C_INT_TMR0;
ENI(); // Enable interrupt
}
void delay(unint z) // The time delay function ms
{
unint x,y;
for(x = z;x > 0;x--)
for(y = 100;y > 0;y--);
}
void lnput_Mod() // State mode marker function
{
if(Mod == 4)
Mod = 0;
if(key == 0)
{
delay(5);
if(key == 0) // Delay chattering
Mod++; // The number of keystrokes is marked
}
while(!key) // Let go of the test
{;;}
}
void run() //4 Execution in three modes
{
switch(Mod)
{
case 0:{PCON1 = C_TMR0_Dis;light1 = 0;light2 = 0;}break; // All bright
case 1:{PCON1 = C_TMR0_En;}break; // Synchronous flashing
case 2:{PCON1 = C_TMR0_Dis;light1 = 1;light2 = 1;}break; // Total destruction
case 3:{PCON1 = C_TMR0_Dis;light1 = 0;light2 = 1;PCON1 = C_TMR0_En;}break; // Asynchronous flash
}
}
void main(void)
{
lnit_Mod();
lnit_Timer();
while(1)
{
lnput_Mod();
if(flag == 1) // control RUN function
{
run();
if(Mod == 1||Mod == 3)
flag = 0;
}
if(Mod == 0||Mod == 2)
flag = 1;
}
}
边栏推荐
- Paddleocr tutorial
- 取得PMP證書需要多長時間?
- 打新债开户注册安全吗?有没有风险的?靠谱吗?
- 解决无法通过ssh服务远程连接虚拟机
- French scholars: the explicability of counter attack under optimal transmission theory
- 业务场景功能的继续修改
- 壁仞科技研究院前沿技术文章精选
- Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
- go踩坑——no required module provides package : go.mod file not found in current directory or any parent
- In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi
猜你喜欢
Galera cluster of MariaDB - dual active and dual active installation settings
机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
蓝天NH55系列笔记本内存读写速度奇慢解决过程记录
C language to quickly solve the reverse linked list
圖解網絡:什麼是網關負載均衡協議GLBP?
取得PMP證書需要多長時間?
In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi
他做国外LEAD,用了一年时间,把所有房贷都还清了
The caching feature of docker image and dockerfile
【雅思阅读】王希伟阅读P3(Heading)
随机推荐
Application of fire fighting system based on 3D GIS platform
Qualcomm WLAN framework learning (30) -- components supporting dual sta
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
[kotlin] the third day
In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database
跨域请求
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
积分商城游戏设置的基本要点
How to do the project of computer remote company in foreign Internet?
Etcd database source code analysis - brief process of processing entry records
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
js正则表达式之中文验证(转)
How to use fast parsing to make IOT cloud platform
人脸识别5- insight-face-paddle-代码实战笔记
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
The pit of sizeof operator in C language
高配笔记本使用CAD搬砖时卡死解决记录
Solution record of jamming when using CAD to move bricks in high configuration notebook