当前位置:网站首页>[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);
}
}
}边栏推荐
- ffmpeg之 一张/多张图片合成视频
- Wechat applet + Alibaba IOT platform + Hezhou air724ug build a serverless IOT system (III) -- wechat applet is directly connected to Alibaba IOT platform aliiot
- Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
- golang xxx. Go code template
- In Net 6 project using startup cs
- Ffmpeg download and installation tutorial and introduction
- sigaction的使用
- MongoDB簡介
- Is pytorch open source?
- docker安装及启动mysql服务
猜你喜欢

Some preliminary preparations for QQ applet development: make an appointment for a development account, download and install developer tools, and create QQ applet

没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥

Hutool dynamically adds scheduled tasks

Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11

Hi3536c v100r001c02spc040 cross compiler installation

How does the pytorch project run?

Wechat applet + Alibaba IOT platform + Hezhou air724ug build a serverless IOT system (III) -- wechat applet is directly connected to Alibaba IOT platform aliiot

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

How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo

Mongodb installation & Deployment
随机推荐
Write it down once Net travel management background CPU Explosion Analysis
Téléchargement et installation du client Filezilla
Ffmpeg download and installation tutorial and introduction
Lvgl usage experience
[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 |
Summary of electromagnetic spectrum
Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check
2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
Hutool动态添加定时任务
【学习笔记】seckill-秒杀项目--(11)项目总结
[mathematical logic] propositional logic (propositional logic reasoning | formal structure of reasoning | inference law | additional law | simplification law | hypothetical reasoning | refusal | disju
MongoDB安装 & 部署
Basic operations of mongodb [add, delete, modify, query]
pytorch项目怎么跑?
[combinatorics] basic counting principle (addition principle | multiplication principle)
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
【DRM】DRM bridge驱动调用流程简单分析
Filter
Separable bonds and convertible bonds
[mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)