当前位置:网站首页>[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);
}
}
}
边栏推荐
- [MySQL] the difference between left join, right join and join
- Tidal characteristics of the Bohai Sea and the Yellow Sea
- docker安装及启动mysql服务
- The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post
- 阿洛对自己的思考
- Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
- Recursion: depth first search
- [national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
- sigaction的使用
- [DRM] simple analysis of DRM bridge driver call process
猜你喜欢
Recursion: one dimensional linked lists and arrays
900w+ data, from 17s to 300ms, how to operate
Ansible简介【暂未完成(半成品)】
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
Some preliminary preparations for QQ applet development: make an appointment for a development account, download and install developer tools, and create QQ applet
105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
Recursion: depth first search
What is pytorch? Is pytorch a software?
FileZilla Client下载安装
随机推荐
Basic operations of mongodb [add, delete, modify, query]
[national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
在 .NET 6 项目中使用 Startup.cs
Nce detail of softmax approximation
403 error displayed when vs cloning
How to download pytorch? Where can I download pytorch?
pytorch怎么下载?pytorch在哪里下载?
【DRM】DRM bridge驱动调用流程简单分析
FileZilla client download and installation
Makefile demo
Web会话管理安全问题
SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode
递归:快速排序,归并排序和堆排序
Ansible introduction [unfinished (semi-finished products)]
105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
机械臂速成小指南(八):运动学建模(标准DH法)
[mathematical logic] propositional logic (judgment of the correctness of propositional logic reasoning | formal structure is eternal truth - equivalent calculus | deduction from premise - logical reas
PHP generates PDF tcpdf
Write it down once Net travel management background CPU Explosion Analysis
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11