当前位置:网站首页>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.
边栏推荐
- Difference between rest and WebServices
- Tp6 interface returns three elements
- JS to determine whether an element exists in the array (four methods)
- Power representation in go language
- ACWING/2004. Misspelling
- Uncaught typeerror cannot set properties of undefined (setting 'classname') reported by binding onclick event in jsfor loop
- How to realize the stable output of 3.3v/3.6v (1.2-5v) voltage of lithium battery by using the voltage rise and fall chip cs5517
- Comparison test of mono 120W high power class D power amplifier chip cs8683-tpa3116
- DataX tutorial (10) - hot plug principle of dataX plug-in
- [ACNOI2022]王校长的构造
猜你喜欢
Derivation of COS (a+b) =cosa*cosb-sina*sinb
Simple and complete steps of vivado project
Three laws of go reflection
SAP QM executes the transaction code qp01, and the system reports an error -material type food is not defined for task list type Q-
Comparison test of mono 120W high power class D power amplifier chip cs8683-tpa3116
Zero foundation wants to learn web security, how to get started?
Kubernetes cluster dashboard & kuboard installation demo
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"
How two hosts in different network segments directly connected communicate
Analysis on the output, market scale and development status of China's children's furniture industry in 2020 and the competition pattern of children's furniture enterprises [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"
[core content and derivation] the mystery of human memory system may be just like this
Message queue table structure for storing message data
Acwing / 2004. Mauvaise écriture
[ACNOI2022]王校长的构造
'how do I create an enumeration with constant values in rust?'- How can I create enums with constant values in Rust?
ACWING/2004. 錯字
How to chain multiple different InputStreams into one InputStream
ACWING2013. 三条线
【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》
Period to string [repeat] - period to string [duplicate]
Usage of STL map
Sleep quality today 67 points
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
What is cloud primordial?
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
Brief introduction and use of JSON
Three laws of go reflection
How to find happiness in programming and get lasting motivation?
Wan Yin revealed that he was rejected by MIT in this way: "the department doesn't like you". He confronted the principal and realized