当前位置:网站首页>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.
边栏推荐
- How to realize hierarchical management of application and hardware in embedded projects
- What is cloud primordial?
- You can see the classification of SQL injection. SQL injection point /sql injection type /sql injection has several /sql injection point classifications
- MSG_ OOB MSG_ PEEK
- TCP BBR as rate based
- Simple and complete steps of vivado project
- Derivation of COS (a+b) =cosa*cosb-sina*sinb
- Three laws of go reflection
- 'how do I create an enumeration with constant values in rust?'- How can I create enums with constant values in Rust?
- Derivation of sin (a+b) =sina*cosb+sinb*cosa
猜你喜欢

Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals

From file system to distributed file system

3dmax软件的制作木桶过程:三步流程

Non-contact infrared temperature measurement system for human body based on single chip microcomputer

Following the last minor upgrade of nodemcu (esp8266)

Baidu map - introductory tutorial

Navicat prevent new query from being deleted by mistake

Cs5092 5V USB input boost two section lithium battery charging management IC, SOT23-6 miniature package

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

Ht513 I2S input 2.8W mono class D audio power amplifier IC
随机推荐
Kubernetes cluster dashboard & kuboard installation demo
燕京啤酒何以至此?
Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution
Analysis of common interview questions in redis
Preliminary practice of niuke.com (summary)
Want to self-study SCM, do you have any books and boards worth recommending?
Common cluster scripts
System dilemma and software complexity: Why are our systems so complex?
Following the last minor upgrade of nodemcu (esp8266)
Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution
Non-contact infrared temperature measurement system for human body based on single chip microcomputer
Fastadmin cascade clear data
How to deploy locally developed SAP ui5 applications to ABAP servers
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
Cs5092 5V USB input boost two section lithium battery charging management IC, SOT23-6 miniature package
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars
Navicat防止新建查询误删
Microsoft issued a document to celebrate Net 20th anniversary!
The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config