当前位置:网站首页>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
边栏推荐
- cookie插件和localForage离线储存插件
- [PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
- Unity Shader 学习笔记(3)URP渲染管线带阴影PBR-Shader模板(ASE优化版本)
- Nacos 启动报错 Error creating bean with name ‘instanceOperatorClientImpl‘ defined in URL
- all3dp. All Arduino projects in com website (2022.7.1)
- 页面打印插件print.js
- Fundamentals of software testing
- Go language web development is very simple: use templates to separate views from logic
- How vite is compatible with lower version browsers
- 1036 Boys vs Girls
猜你喜欢
Vite打包后的dist不能直接在浏览器打开吗
Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
Summary of MySQL constraints
Lantern Festival gift - plant vs zombie game (realized by Matlab)
vite如何兼容低版本浏览器
MySQL transaction and isolation level
A collection of commonly used plug-ins for idea development tools
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP
Oled12864 LCD screen
Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan
随机推荐
Small and medium-sized projects to achieve certification and authorization of hand filter
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
1035 Password
15 C language advanced dynamic memory management
“簡單”的無限魔方
File contains vulnerabilities (II)
PHP parent
Technologists talk about open source: This is not just using love to generate electricity
1037 Magic Coupon
1037 Magic Coupon
Regular expression summary
如何写出好代码 — 防御式编程指南
Appnuim environment configuration and basic knowledge
PHP development and testing WebService (soap) -win
cookie插件和localForage离线储存插件
Addchild() and addattribute() functions in PHP
Yyds dry inventory what is test driven development
Opencv LBP features
mock-用mockjs模拟后台返回数据
Matplotlib double Y axis + adjust legend position