当前位置:网站首页>[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);
}
}
}
边栏推荐
- 900w+ data, from 17s to 300ms, how to operate
- Debug: CD cannot be used in kaggle
- Ffmpeg download and installation tutorial and introduction
- Recursion: quick sort, merge sort and heap sort
- Change and access of median value of listening object
- MongoDB簡介
- Basic operations of mongodb [add, delete, modify, query]
- TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
- Recursive use and multi-dimensional array object to one-dimensional array object
- Read a paper_ ChineseBert
猜你喜欢
Ansible introduction [unfinished (semi-finished products)]
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
Wechat applet + Alibaba IOT platform + Hezhou air724ug build a serverless IOT system (III) -- wechat applet is directly connected to Alibaba IOT platform aliiot
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr
在 .NET 6 项目中使用 Startup.cs
Makefile demo
MongoDB复制集【主从复制】
MySQL MAC download and installation tutorial
Web会话管理安全问题
随机推荐
Summary of electromagnetic spectrum
Leetcode: dynamic planning template
Separable bonds and convertible bonds
简易版 微信小程序开发之for指令、上传图片及展示效果优化
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
[combinatorics] basic counting principle (addition principle | multiplication principle)
105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
MongoDB基本操作【增、删、改、查】
[MySQL] the difference between left join, right join and join
docker安装及启动mysql服务
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
PHP generates PDF tcpdf
pytorch怎么下载?pytorch在哪里下载?
[national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
小程序获取用户头像和昵称
Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check