当前位置:网站首页>Blue Bridge Cup SCM module code (matrix key) (code + comments)
Blue Bridge Cup SCM module code (matrix key) (code + comments)
2022-06-25 06:44:00 【tuygre】
/* The explanation in the previous chapter will not be repeated */
#include "STC15F2K60S2.H"
typedef unsigned char u8;
typedef unsigned int u16;
u8 org[9],tran[9],old,new,wei;
u16 count;
void close()
{
P0=0;
P2=P2&0X1F|0XA0;
P2=P2&0X1F;
P0=0XFF;
P2=P2&0X1F|0X80;
P2=P2&0X1F;
}
void Timer0Init(void)
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0x20;
TH0 = 0xD1;
TF0 = 0;
TR0 = 1;
}
void open()
{
EA=1;
ET0=1;
}
void translate(u8 org[],u8 tran[])
{
u8 tran1,j,k;
for(j=0,k=0;k<8;j++,k++)
{
switch(org[j])
{
case '0': tran1 = 0xc0; break;
case '1': tran1 = 0xf9; break;
case '2': tran1 = 0xa4; break;
case '3': tran1 = 0xb0; break;
case '4': tran1 = 0x99; break;
case '5': tran1 = 0x92; break;
case '6': tran1 = 0x82; break;
case '7': tran1 = 0xf8; break;
case '8': tran1 = 0x80; break;
case '9': tran1 = 0x90; break;
case 'A': tran1 = 0x88; break;
case 'B': tran1 = 0x83; break;
case 'C': tran1 = 0xc6; break;
case 'D': tran1 = 0xa1; break;
case 'E': tran1 = 0x86; break;
case 'F': tran1 = 0x8E; break;
default: tran1 = 0xff;
}
if(org[j+1]=='.')
{
tran1&=0x7f;
j++;
}
tran[k]=tran1;
}
}
void display(u8 tran[],u8 wei)
{
P0=0XFF;
P2=P2&0X1F|0XE0;
P2=P2&0X1F;
P0=1<<wei;
P2=P2&0X1F|0XC0;
P2=P2&0X1F;
P0=tran[wei];
P2=P2&0X1F|0XE0;
P2=P2&0X1F;
}
u8 search()
{
u16 key;
u8 key_return;
P44=0;P42=1;P35=1;P34=1;
key=key|(P3&0X0F);
P44=1;P42=0;P35=1;P34=1;
key=(key<<4)|(P3&0X0F);
P44=1;P42=1;P35=0;P34=1;
key=(key<<4)|(P3&0X0F);
P44=1;P42=1;P35=1;P34=0;
key=(key<<4)|(P3&0X0F);
/* According to the schematic diagram , We control P44、P42、P35、P34 Four pins , Set any one of them 0, The implementation of a matrix key
Column by column scanning , Then through observation P30、P31、P32、P33 Four pins , Determine which line the pressed key is on . That's a little
abstract , for instance : Such as P44=0;P42=1;P35=1;P34=1; What is being scanned is S7、S6、S5、S4 This column , Such as P32 by 0,
It means S5 Where the circuit is connected ,S5 Pressed . Parameters key The result of the scan is recorded , adopt switch function , Confirm the pressed press
key . notes :J5 To put 2,3 Connect , Scanning will work ; At the same time, according to the user manual 3.3 We are here ,P3 The initial value of 1111 11
11, therefore P30、P31、P32、P33 Change with the external state , Specific learnable 《 Single chip microcomputer principle and interface technology 》*/
switch(~key)
{
case 0x8000: key_return = 4; break; // S4
case 0x4000: key_return = 5; break; // S5
case 0x2000: key_return = 6; break; // S6
case 0x1000: key_return = 7; break; // S7
case 0x0800: key_return = 8; break; // S8
case 0x0400: key_return = 9; break; // S9
case 0x0200: key_return = 10; break; // S10
case 0x0100: key_return = 11; break; // S11
case 0x0080: key_return = 12; break; // S12
case 0x0040: key_return = 13; break; // S13
case 0x0020: key_return = 14; break; // S14
case 0x0010: key_return = 15; break; // S15
case 0x0008: key_return = 16; break; // S16
case 0x0004: key_return = 17; break; // S17
case 0x0002: key_return = 18; break; // S18
case 0x0001: key_return = 19; break; // S19
default: key_return = 0;
}
return key_return;
}
/* The return value of this function is the number of the key pressed . Do not consider the case that two keys are pressed at the same time ,
Because the MCU runs very fast , Even if the visual inspection is simultaneously pressed , For MCU
There are still two different moments */
void key_translate()
{
new=search();
/* Collect key information */
if(new!=old&&new!=0)
/* Each time you press a key, you only acknowledge it once and rule out the case that no key is pressed */
{
if(new>=14)
org[7]=new-14+'A';
else org[7]=new-4+'0';
/* The array records ASCII value */
}
old=new;
/* Don't forget */
}
void main()
{
close();
open();
Timer0Init();
while(1)
{
translate(org,tran);
key_translate();
}
}
void time0() interrupt 1
{
display(tran,wei);
if(++wei==8) wei=0;
}
Official schematic diagram , The download address of the user manual is as follows :
link :https://pan.baidu.com/s/1y8lRYHxLKojL4_r0PZPYRw
Extraction code :19so
Note cannot insert picture , Relevant information readers themselves look for in the folder .
Study notes for undergraduate students of Nanjing University of Information Engineering , For your reference .
If there is a mistake , contact QQ3182097183.
边栏推荐
- Unity get resource path
- Your local changes to the following files would be overwritten by merge: .vs/slnx.sqlite
- Go language library management restful API development practice
- Zhinai's database
- Preliminary practice of niuke.com (summary)
- With a younger brother OCR, say no to various types of verification codes!
- Sleep quality today 67 points
- 3dmax软件的制作木桶过程:三步流程
- [learn shell programming easily]-5. Plan tasks
- Is the number of indexes in a table the more the better?
猜你喜欢

Are you still doing the dishes yourself? Teach you how to make dishwasher controller with single chip microcomputer

アルマ / 炼金妹

ACWING/2004. 錯字

With a younger brother OCR, say no to various types of verification codes!

sin(a+b)=sina*cosb+sinb*cosa的推导过程

Esp8266 & sg90 steering gear & Lighting Technology & Arduino

Understand ZBrush carving software and game modeling analysis

Ht7180 3.7V L 12v/2a built in MOS high current boost IC solution

Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things

Want to self-study SCM, do you have any books and boards worth recommending?
随机推荐
Analysis on the scale of China's smart airport industry in 2020: there is still a large space for competition in the market [figure]
2022 biological fermentation Exhibition (Jinan), which is a must read before the exhibition. The most comprehensive exhibition strategy will take you around the "fermentation circle"
集群常用群起脚本
What is VLAN
Modify the default log level
Why can't GC () free memory- Why does gc() not free memory?
Hongmeng learning notes: creating layouts using XML
cos(a-b)=cosa*cosb+sina*sinb的推导过程
Keil debug view variable prompt not in scope
Ht7180 3.7V L 12v/2a built in MOS high current boost IC solution
Kubernetes core components etcd details
Acwing / 2004. Mauvaise écriture
父爱的表达方式
Meta universe is over, Web 3.0 will be fooled again?
Derivation of COS (a-b) =cosa*cosb+sina*sinb
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
[200 opencv routines of youcans] 104 Motion blur degradation model
Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
Ht81293 built in adaptive dynamic boost 20W mono class D power amplifier IC solution
Why did Yanjing Beer come here?