当前位置:网站首页>[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
2022-07-03 03:48:00 【The journey of a bald girl is the sea of stars】
The specific interpretation plans to record a video and put it on B Stand. , In the afternoon, I went to change my glasses and began to record , There are too many scratches on the lens QAQ
Press the key to make the nixie tube display the corresponding key value ,S4 Lighten up L1、L2,S8 Lighten up L3、L4,S12 Lighten up L5、L6,S16 Lighten up L7、L8
#include<stc15f2k60s2.h>
typedef unsigned char uchar;
typedef unsigned int uint;
uchar dsp_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar dsp_value[8]={0xff,0xff,0xff,0xff,0xff,0xff};
uchar value,count_key;
void Timer_Init()
{
AUXR|= 0x80;
TMOD&= 0xf0;
TL0=0xcd;
TH0=0xd4;
TR0=1;
ET0=1;
EA=1;
}
void serviceTimer() interrupt 1
{
static uchar dsp_com=0;
P0=0;P2=0xc0;P2=0;
P0=dsp_value[dsp_com];P2=0xe0;P2=0;
P0=1<<dsp_com;P2=0xc0;P2=0;
if(++dsp_com==8)dsp_com=0;
++count_key;
}
void scan_keyboard()
{
static uchar key_stat=0;
uchar key_val=0,key_x=0,key_y=0;
P3=0x0f;P4=0x00;
if(!P30) key_x=3;
else if(!P31) key_x=2;
else if(!P32) key_x=1;
else if(!P33) key_x=0;
P3=0xf0;P4=0xff;
if(!P34) key_y=4;
else if(!P35) key_y=3;
else if(!P42) key_y=2;
else if(!P44) key_y=1;
key_val=key_x+key_y*4;
switch(key_stat)
{
case 0:
if(key_val!=0) key_stat=1;
break;
case 1:
if(key_val==0) key_stat=0;
else
{
key_stat=2;
value=key_val;
switch(key_val)
{
case 4:P0=~0x03;P2=0x80;P2=0;break;
case 5:break;
case 6:break;
case 7:break;
case 8:P0=~0x0c;P2=0x80;P2=0;break;
case 9:break;
case 0:break;
case 11:break;
case 12:P0=~0x30;P2=0x80;P2=0;break;
case 13:break;
case 14:break;
case 15:break;
case 16:P0=~0xc0;P2=0x80;P2=0;break;
case 17:break;
case 18:break;
case 19:break;
case 2:
if(key_val==0) key_stat=0;
break;
}
}
}
}
void Initsystem()
{
P0=0xff;P2=0x80;P2=0;
P0=0x00;P2=0xa0;P2=0;
}
void main()
{
Initsystem();
Timer_Init();
while(1)
{
if(count_key>9)
{
count_key=0;
scan_keyboard();
}
if(value>9)
{
dsp_value[6]=dsp_code[value/10];
}
else
{
dsp_value[6]=0xff;
}
dsp_value[7]=dsp_code[value%10];
}
}But there will be the phenomenon of insensitive keys QAQ
Press down S7 Add one to the number displayed by the nixie tube , Press down S11 Reduce the displayed number by one , The range of numbers is 0~200, Turn on the buzzer when the number is odd 、 Turn off the relay 、L1 bright , When the number is even , Turn on the relay 、 Turn off the buzzer 、L2 bright
When the delay function is added, other lights will be on at low level , The delay function occasionally flashes .
*/
#include "stc15f2k60s2.h"
typedef unsigned char uchar;
typedef unsigned int uint;
uchar code smg_duanma[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
uchar smg_show[8]={0xff,0xff,0xff,0xff,0xff}; // initialization , Turn off the first five digital tubes
uchar count_key;
uchar number=0;
sbit buzzer=P0^6;
sbit relay=P0^4;
//**************************************************
void Timer0_Init()
{
AUXR|=0x80;
TMOD&=0xf0;
TH0=0xd4;
TL0=0xcd;
TR0=1;
ET0=1;
EA=1;
}
void Timer0_Service() interrupt 1
{
static uchar smg_com=0;
P0=0;P2=0xc0;P2=0;
P0=smg_show[smg_com];P2=0xe0;P2=0;
P0=1 << smg_com;P2=0xc0;P2=0;
if(++smg_com == 8) smg_com=0;
++count_key;
}
//****************************************************
void Delay(uint t)
{
while(t--);
}
void Scan_Key()
{
static uchar key_stat=0;
uchar key_val=0,key_x=0,key_y=0;
P3=0x0f;P4=0x00;
if(!P30) key_x=3;
else if(!P31) key_x=2;
else if(!P32) key_x=1;
else if(!P33) key_x=0;
P3=0xf0;P4=0xff;
if(!P34) key_y=4;
else if(!P35) key_y=3;
else if(!P42) key_y=2;
else if(!P44) key_y=1;
key_val=key_x + key_y*4;
switch(key_stat)
{
case 0:
if(key_val!=0) key_stat=1; // Check the key for the first time
break;
case 1:
if(key_val==0) key_stat=0;
else
{
key_stat=2; // Second detection key
switch(key_val)
{
case 6:
number=number+20;
break;
case 7:
if(number>=200)
{
number=200;
}
else
number++;
if(number%2==0)
{
relay=1;
buzzer=0;
P2=0xa0;
P2=0;
}
else
{
relay=0;
buzzer=1;
P2=0xa0;
P2=0;
}
break;
case 10:
number=number-20;
break;
case 11:
if(number==0)
{
number=0;
}
else
number--;
if(number%2==0)
{
relay=1;
buzzer=0;
P2=0xa0;
P2=0;
}
else
{
relay=0;
buzzer=1;
P2=0xa0;
P2=0;
}
break;
}
}
break;
case 2:
if(key_val == 0) key_stat=0; // Check the key for the third time
break;
}
}
void System_Init()
{
P0=0xff;P2=0x80;P2=0;
P0=0x00;P2=0xa0;P2=0;
}
void main()
{
System_Init();
Timer0_Init();
while(1)
{
if(count_key > 9)
{
count_key=0;
Scan_Key();
}
if(number<10)
{
smg_show[6]=0xff;
smg_show[5]=0xff;
}
else if(number<100)
{
smg_show[6]=smg_duanma[number/10%10];
smg_show[5]=0xff;
}
else
{
smg_show[6]=smg_duanma[number/10%10];
smg_show[5]=smg_duanma[number/100];
}
smg_show[7]=smg_duanma[number%10];
// smg_show[6]=smg_duanma[number/10%10];
// smg_show[5]=smg_duanma[number/100];
if(number%2==0)
{
P0=0xfe;P2=0x80;P2=0;
// Delay(10000);
}
else
{
P0=0xfd;P2=0x80;P2=0;
// Delay(10000);
}
}
}边栏推荐
- Wechat applet + Alibaba IOT platform + Hezhou air724ug built with server version system analysis
- docker安装及启动mysql服务
- Cnopendata China Customs Statistics
- Web会话管理安全问题
- [learning notes] seckill - seckill project - (11) project summary
- Open Visual Studio 2010 hangs when opening a SQL file sql file
- ffmpeg下载安装教程及介绍
- Docker install and start MySQL service
- Dynamic programming: Longest palindrome substring and subsequence
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
猜你喜欢

简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息

SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

CEPH Shangwen network xUP Nange that releases the power of data

The calculation of stripe, kernel and padding in CNN

TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥

Cnopendata China Customs Statistics

机械臂速成小指南(八):运动学建模(标准DH法)

Ansible简介【暂未完成(半成品)】

node,npm以及yarn下载安装
随机推荐
What is pytorch? Is pytorch a software?
2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
Error in compiled file: error: unmapped character encoding GBK
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
Pytoch lightweight visualization tool wandb (local)
Web session management security issues
【DRM】DRM bridge驱动调用流程简单分析
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
记一次 .NET 差旅管理后台 CPU 爆高分析
Ffmpeg one / more pictures synthetic video
递归:一维链表和数组
Shardingsphere dynamic data source
FileZilla client download and installation
Dynamic programming: Longest palindrome substring and subsequence
IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network
Recursion: quick sort, merge sort and heap sort
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
redis在服务器linux下的启动的相关命令(安装和配置)
简易版 微信小程序开发之for指令、上传图片及展示效果优化
SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode