当前位置:网站首页>[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);
}
}
}边栏推荐
- Is pytorch difficult to learn? How to learn pytorch well?
- [combinatorics] basic counting principle (addition principle | multiplication principle)
- Half of 2022 is over, so we must hurry up
- IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
- Read a paper_ ChineseBert
- 记一次 .NET 差旅管理后台 CPU 爆高分析
- Introduction to mongodb
- Hutool动态添加定时任务
- Introduction à mongodb
- Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
猜你喜欢

2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank

MongoDB简介

CEPH Shangwen network xUP Nange that releases the power of data

渤、黄海的潮汐特征

Role of JS No

Download and install captura and configure ffmpeg in captura

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

Recursion: one dimensional linked lists and arrays

ffmpeg下载安装教程及介绍

npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
随机推荐
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
FileZilla client download and installation
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
Commands related to the startup of redis under Linux server (installation and configuration)
What can learning pytorch do?
Open Visual Studio 2010 hangs when opening a SQL file sql file
Hi3536c v100r001c02spc040 cross compiler installation
错误 C2694 “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数
ffmpeg下载安装教程及介绍
Recursion: depth first search
The calculation of stripe, kernel and padding in CNN
递归:快速排序,归并排序和堆排序
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
Compare float with 0
Mongodb master profile
Use three JS make a simple 3D scene
静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
Ansible简介【暂未完成(半成品)】