当前位置:网站首页>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;
}
}
边栏推荐
- Jar批量管理小工具
- 股票账户佣金怎么调低,炒股佣金怎么调低网上开户安全吗
- Intelligence test to see idioms guess ancient poems wechat applet source code
- Pytoch --- use pytoch to realize linknet for semantic segmentation
- 取得PMP证书需要多长时间?
- C language to quickly solve the reverse linked list
- 快解析内网穿透帮助企业快速实现协同办公
- 微服务(Microservice)那点事儿
- 端口映射和端口转发区别是什么
- [JS] - [dynamic planning] - Notes
猜你喜欢
Pytoch --- use pytoch to realize linknet for semantic segmentation
Application of multi loop instrument in base station "switching to direct"
「运维有小邓」域密码策略强化器
[JS] - [sort related] - Notes
取得PMP證書需要多長時間?
XML的解析
Design of emergency lighting evacuation indication system for urban rail transit station
45岁教授,她投出2个超级独角兽
What is the difference between port mapping and port forwarding
Observable time series data downsampling practice in Prometheus
随机推荐
Etcd database source code analysis - brief process of processing entry records
如何将自己的代码作品快速存证,已更好的保护自己劳动成果
The Chinese output of servlet server and client is garbled
【kotlin】第三天
Business implementation - the log is written to the same row of data
JS 将伪数组转换成数组
Solve the problem that the virtual machine cannot be remotely connected through SSH service
CTF competition problem solution STM32 reverse introduction
CTF競賽題解之stm32逆向入門
QT addition calculator (simple case)
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
[binary tree] the maximum difference between a node and its ancestor
How to reduce the stock account Commission and stock speculation commission? Is it safe to open an online account
如果炒股开华泰证券的户,在网上开户安全吗?
使用快解析搭建自己的minecraft服务器
如何用快解析自制IoT云平台
[Peking University] tensorflow2.0-1-opening
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
How to save your code works quickly to better protect your labor achievements
积分商城游戏设置的基本要点