当前位置:网站首页>STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
2022-07-02 05:52:00 【不知何人】
按键允许按键计数(利用下降沿中断控制)
一、题目
编程实现数码管显示SW17按钮按下的次数,要求SW18控制启动和停止,即单数次按下SW18前提下,开始记录SW17按下的次数,偶数次按下SW18按键,则将计数值清零,重新开始对SW17 按键次数计数。
二、代码
#include <stc8h.h>
#include <intrins.h>
void Delay1ms() //@24.000MHz
{
unsigned char i, j;
_nop_();
i = 32;
j = 40;
do
{
while (--j);
} while (--i);
}
void gpio() //gpio初始化为准双向口,刚开始除了P30,P31其他均为高阻态
{
P0M1 = 0x00; P0M0 = 0x00; //设置为准双向口
P1M1 = 0x00; P1M0 = 0x00; //设置为准双向口
P2M1 = 0x00; P2M0 = 0x00; //设置为准双向口
P3M1 = 0x00; P3M0 = 0x00; //设置为准双向口
P4M1 = 0x00; P4M0 = 0x00; //设置为准双向口
P5M1 = 0x00; P5M0 = 0x00; //设置为准双向口
P6M1 = 0x00; P6M0 = 0x00; //设置为准双向口
P7M1 = 0x00; P7M0 = 0x00; //设置为准双向口
}
u8 code t_display[]={
//标准字库
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; //0. 1. 2. 3. 4. 5. 6. 7. 8. 9. -1
u8 code T_COM[]={
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //位码
unsigned int n=0 ;//因为n后面取值在1000,不能是unsigned char型
void Nixie(u8 i, u16 j)
{
P7=~T_COM[i];
P6=~t_display[j];
Delay1ms();
P6 = 0xFF;
}
void Init()
{
EA=1;//开启cpu总中断
IT0=1;//跳沿触发
IT1=1;//跳沿触发
EX0=1;
EX1=1;
PX0=0; //外部中断0为高优先级
PX1=1; //外部中断1为低优先级
}
u8 flag=0; //flag为1的时候sw17才有效
u8 count[2]; //设置了最大计数上限为99
void main()
{
gpio();
Init();
while(1)
{
Nixie(0,count[0]); //显示个位十位
Nixie(1,count[1]);
}
}
void INT1() interrupt 2
{
Nixie(0,count[0]); //显示个位十位
Nixie(1,count[1]);
flag++; //sw18按下后flag值改变,初始flag为0,按下单次开启,偶次关闭
if(flag==2)flag=0;
ET1=0;
}
void INT0() interrupt 0
{
Nixie(0,count[0]); //显示个位十位
Nixie(1,count[1]);
count[0]++; //每按下一次就加1
if(count[0]==10)
{
count[0]=0;
count[1]++;
if(count[1]==10)
{
count[1]=0;
}
}
ET0=0;
}
非常感谢各位观看!!!
系列文章——STC8H8K系列汇编51实战
基于ESP8266与STC单片机的天气时钟(包括DS18B20、TFT、串口、外部中断、ESP8266、STC、API等)
STC8H8K系列汇编和C51实战——实现键控不同方式数码管动态显示(C51版与汇编版)
STC8H8K系列汇编和C51实战——开关控制定时器秒表(C51版)
STC8H8K系列汇编和C51实战——开关控制定时器秒表(汇编版)
STC8H8K系列汇编和C51实战——双中断控制定时器流水灯
STC8H8K系列汇编和C51实战——秒倒计时器(可自行设定初值)(51版)
STC8H8K系列汇编和C51实战——按键允许按键计数(51版)
STC8H8K系列汇编和C51实战——按键允许按键计数(汇编版)
STC8H8K系列汇编和C51实战——按键允许按键计数(定时器去抖动51版)
STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
STC8H8K系列汇编和C51实战——计算机串口控制单片机LED
边栏推荐
- Typora installation (no need to enter serial number)
- With an amount of $50billion, amd completed the acquisition of Xilinx
- Alibaba: open source and self-developed liquid cooling data center technology
- I want to understand the swift code before I learn it. I understand it
- Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders
- 深度学习分类网络--VGGNet
- Win10 copy files, save files... All need administrator permission, solution
- Unity Shader 学习笔记(3)URP渲染管线带阴影PBR-Shader模板(ASE优化版本)
- 5g market trend in 2020
- Software testing learning - day 4
猜你喜欢
PHP development and testing WebService (soap) -win
Fundamentals of software testing
The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market
Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP
File contains vulnerabilities (II)
文件包含漏洞(二)
Record sentry's path of stepping on the pit
死磕大屏UI,FineReport开发日记
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
随机推荐
3D printer G code command: complete list and tutorial
PHP gets CPU usage, hard disk usage, and memory usage
c语言中的几个关键字
Cube magique infini "simple"
all3dp. All Arduino projects in com website (2022.7.1)
How to change the IP address of computer mobile phone simulator
文件包含漏洞(一)
Generics and generic constraints of typescript
软件测试答疑篇
php父类(parent)
servlet的web.xml配置详解(3.0)
使用sha256文件验证下载的文件
Practice C language advanced address book design
492.构造矩形
深度学习分类网络--Network in Network
Win10 copy files, save files... All need administrator permission, solution
Basic use of form
"Simple" infinite magic cube
php内类名称与类内方法名相同
Alibaba: open source and self-developed liquid cooling data center technology