当前位置:网站首页>LED, nixie tube and key of single chip microcomputer
LED, nixie tube and key of single chip microcomputer
2022-07-28 00:44:00 【*Black heart radish three bars*】
key.h file
#include "intrins.h"
#include "STC15F2K60S2.H"
#ifndef _KEY_H
#define _KEY_H
#define kbd_io P3
#define state_0 0 // Whether to press
#define state_1 1 // Is it jitter
#define state_2 2 // Judge whether it bounces
#define kbd_maskrow 0x0f // Shield unwanted IO
#define u8 unsigned char
#define u16 unsigned int
sbit relay=P0^4;//
sbit buzzer=P0^6;// Buzzer pin
// Although the following three variables are global variables , But in fact, the definition is not here , When compiling, you need to find the definition
extern unsigned int key_num;// Key value
extern unsigned int segbuff[];// It can control the position of the nixie tube display
extern unsigned int segtab[];// The number displayed by the nixie tube
extern unsigned int ledtab[];//led The location of
void Delay1us0();
void delay_us0(unsigned int us);
void scanbtn();// Independent key function
void scankbd();// Matrix key function
void segs(void);// Nixie tube new time function
void SysInit(unsigned char x);// initialization , close LED, Digital tube segment selection , Buzzer , It can also control whether the buzzer works
void LED_Select(unsigned char n);//LED Selection function
#endifkey.c file
// Including matrix key function 、 Independent key function 、 Nixie tube display function 、LED Show function 、 Initialization function
#include "key.h"
// The following definitions are all global variables
unsigned int key_num=16;// The value obtained from the position of the key
// Nixie tube display position tube 1 tube 2 tube 3 tube 4 tube 5 tube 6 tube 7 tube 8
unsigned int segbuff[]={10, 10, 10, 10, 10, 10, 10, 10};// It can be equivalent to the bit selection of digital tube
// Display value 0 1 2 3 4 5 6 7 8 9 - Extinguish
unsigned int segtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xBF,0xFF,// Gongyang digital tube segment band selection value display
// Show 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. - Extinguish
0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xBF,0xFF};// Display with decimal point
//led Display position Total destruction L1 L2 L3 L4 L5 L6 L7 L8 All bright
unsigned int ledtab[] = {0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00};
// Initialization shutdown LED、 Buzzer 、 Nixie tube
void SysInit(unsigned char x)
{
// close LED
P2=P2&0x1f|0x80;P0=0xff;P2&=0x1f;// First the P2 The three positions of mouth height are set forcibly 0, Or the upper value , Force selection Y4C Output , Then close all LED, Re removal P2 Upper three digit value
// Turn off the buzzer
P2=P2&0x1f|0xa0;relay=0;buzzer=x;P2&=0x1f;// First the P2 The three positions of mouth height are set forcibly 0, Or the upper value , Force selection Y5C Output ,
// Post emissary P0^4 It works , Turn off the buzzer , Re removal P2 Upper three digit value
// Turn off the segment selection of the nixie tube
P2=P2&0x1f|0xe0;P0=0xff;P2&=0x1f; // First the P2 The three positions of mouth height are set forcibly 0, Or the upper value , Force selection Y7C Output ,
// Post emissary P0 Both mouth are effective , Turn off Gongyang digital tube segment selection , Re removal P2 Upper three digit value
// Turn off the bit selection of the nixie tube
P2=P2&0x1f|0xc0;P0=0x00;P2&=0x1f;// First the P2 The three positions of mouth height are set forcibly 0, Or the upper value , Force selection Y6C Output ,
// Post emissary P0 Words are invalid , Turn off the position selection of Gongyang digital tube , Re removal P2 Upper three digit value
}
// Time delay
void Delay1us0() //@12.000MHz
{
_nop_();
_nop_();
_nop_();
_nop_();
}
// Time delay
void delay_us0(unsigned int us)
{
while(us--)
{
Delay1us0();
}
}
//LED Select blink
void LED_Select(unsigned char n)
{
P2 = ( P2& 0x1f ) | 0x80;// First the P2 The upper three digits of the are forced to be set 0, The last or previous number is forced to select Y4C mouth
P0 = n;// Enter the desired light LED
P2 = P2 & 0x8e;
delay_us0(50000);// Time delay 5 millisecond
P2 = ( P2& 0x1f ) | 0x80;// First the P2 The upper three digits of the are forced to be set 0, The last or previous number is forced to select Y4C mouth
P0 = 0xff;// Close all LED The lamp
P2 = P2 & 0x8e;
delay_us0(50000);// Time delay
}
// Matrix key
void scankbd()
{
static char kbd_state = 0;// Three states defined
unsigned char kbd_press;
char row;// Determine the line of the key
switch(kbd_state)
{
case state_0: // Whether to press
kbd_io=0x0f; P42=0; P44=0;
kbd_press = kbd_io;
if(kbd_press != kbd_maskrow)
kbd_state = state_1;// explain key_press It's not equal to 0x0f, Jump to 1 state
break;
case state_1: // Is it jitter kbd_io-P3
kbd_press = kbd_io;
if(kbd_press != kbd_maskrow)
{// The key is not in the state of shielding
// Determine which line the key belongs to
if((kbd_io&0x08)==0) row=0;
if((kbd_io&0x04)==0) row=1;
if((kbd_io&0x02)==0) row=2;
if((kbd_io&0x01)==0) row=3;
kbd_io=0xf0; P42=1;P44=1; // Force four columns to be invalid , Then judge the number of columns of keys
// Determine which column the key belongs to
if(P44==0) key_num=row;
if(P42==0) key_num=row+4;
if((kbd_io&0x20)==0) key_num=row+8;
if((kbd_io&0x10)==0) key_num=row+12;
kbd_state = state_2;// Jump to 2 state
}else{// The keys are shielded , Jump 0 state
kbd_state = state_0;
}
break;
case state_2: // Judge whether it bounces
kbd_io=0x0f; P42=0; P44=0;// Force the key to be valid
kbd_press =kbd_io;// Then get the value of the port
if(kbd_press == 0x0f) kbd_state = state_0;// It is a state that needs to be shielded , Need to jump to 0 state
break;
default: // Shield unwanted IO
break;
}
}
// The nixie tube shows
void segs(void)
{
static unsigned char segaddr=0;
// First of all, total extinction is to eliminate the shadow
P2=(0x1f&P2)|0xe0;// First the P2 Mouth height three position zero , Then force the choice Y7C, Segment selection control
P0=0xff;// Force all segments to be invalid
P2=0x1f&P2;// eliminate P2 The influence of three positions of mouth height
P2=(0x1f&P2)|0xc0;// First the P2 Mouth height three position zero , Then force the choice Y6C, Bit selection control
P0=1<<segaddr; // Change the real position of the nixie tube
P2=0x1f&P2;// eliminate P2 The influence of three positions of mouth height
P2=(0x1f&P2)|0xe0;// First the P2 Mouth height three position zero , Then force the choice Y7C, Segment selection control
P0=segtab[segbuff[segaddr]];// Display the value to be displayed
P2=0x1f&P2;// Eliminate the influence of the high three digits of the nixie tube
if(++segaddr==8)
segaddr=0;// Let the nixie tube display on only eight nixie tubes at a time
}
// Independent buttons
void scanbtn(){
static char kbd_state = 0;// Three states defined
unsigned char kbd_press;// Determine the line of the key
switch(kbd_state)
{
case state_0: // Whether to press
kbd_io=0x0f;
kbd_press =kbd_io;
if(kbd_press != kbd_maskrow)
kbd_state = state_1;// explain key_press It's not equal to 0x0f, Jump to 1 state
break;
case state_1: // Is it jitter kbd_io-P3
kbd_press =kbd_io;
if(kbd_press != kbd_maskrow)
{// The key is not in the state of shielding
// Determine which line the key belongs to
if((kbd_io&0x08)==0) key_num=0;
if((kbd_io&0x04)==0) key_num=1;
if((kbd_io&0x02)==0) key_num=2;
if((kbd_io&0x01)==0) key_num=3;
kbd_state = state_2;// Jump to 2 state
}
else// The keys are shielded , Jump 0 state
kbd_state = state_0;
break;
case state_2: // Judge whether it bounces
kbd_io=0x0f;// Force the key to be valid
kbd_press =kbd_io;// Then get the value of the port
if(kbd_press == 0x0f) kbd_state = state_0;// It is a state that needs to be shielded , Need to jump to 0 state
break;
default: // Shield unwanted IO
break;
}
}main function
#include "key.h"
void Timer0Init(void);
void main()
{
SysInit(0);// close LED The lamp , Nixie tube , Buzzer
Timer0Init();// Turn on timer
while(1)
{
segbuff[0]=key_num/10;
segbuff[1]=key_num%10;
if(key_num%8 == 0) LED_Select(ledtab[1]);
if(key_num%8 == 1) LED_Select(ledtab[2]);
if(key_num%8 == 2) LED_Select(ledtab[3]);
if(key_num%8 == 3) LED_Select(ledtab[4]);
if(key_num%8 == 4) LED_Select(ledtab[5]);
if(key_num%8 == 5) LED_Select(ledtab[6]);
if(key_num%8 == 6) LED_Select(ledtab[7]);
if(key_num%8 == 7) LED_Select(ledtab[8]);
}
}
// interrupt 1
void time0() interrupt 1
{
scankbd();
segs();
}
// Timer 0
void Timer0Init(void) //1 millisecond @12.000MHz
{
AUXR &= 0x7F; // Timer clock 12T Pattern
TMOD &= 0xF0; // Set timer mode
TL0 = 0x18; // Set the initial timing value
TH0 = 0xFC; // Set the initial timing value
TF0 = 0; // eliminate TF0 sign
TR0 = 1; // Timer 0 Start timing
EA = 1;
ET0 = 1;
}
边栏推荐
- 基本初等函数
- MATLAB如何将k线图设置为经典红绿配色?
- Volkswagen China invested 8billion yuan and became the largest shareholder of GuoXuan high tech
- Overview of construction site selection of Yongzhou analytical laboratory
- Jin's thinking
- 冲量在线出席2022数据要素安全流通论坛—政务领域专场,助力行业政务大数据建设创新发展
- 半导体测试设备市场现状:国产化率仍不足10%!
- How does matlab set the K-line diagram to classic red and green color matching?
- 数据可视化-《白蛇2:青蛇劫起》(3)
- 【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发
猜你喜欢
![[must read for new products] valuation analysis of Meishi technology, distributed audio-visual products and Solutions](/img/40/bf3e992e363dbd6600805775058310.jpg)
[must read for new products] valuation analysis of Meishi technology, distributed audio-visual products and Solutions

The server is poisoned - the dish is the original sin

Set data constructor

The influence of head zeroing and tail zeroing on FFT output

迷惑的单片机矩阵按键

See how well-known enterprises use Web3 to reshape their industries

这种动态规划你见过吗——状态机动态规划之股票问题(中)
![[meetup preview] openmldb + ONEFLOW: link feature engineering to model training to accelerate machine learning model development](/img/29/f31fa3af18198754d2433f47c0c556.jpg)
[meetup preview] openmldb + ONEFLOW: link feature engineering to model training to accelerate machine learning model development

几行代码轻松实现对于PaddleOCR的实时推理,快来get!

Matlab | those matlab tips you have to know (3)
随机推荐
Matlab | those matlab tips you have to know (4)
Remote solution of Internet of things system in Mechanical Engineering
公司7月来了个软件测试工程师,一副毛头小子的样儿,哪想到是新一代卷王...
The server is poisoned - the dish is the original sin
Is there a general formula for tens of millions of players? B station is underestimated as a hot money opportunity!
Y79. Chapter IV Prometheus' monitoring system and practice -- Prometheus' service discovery mechanism (10)
Precautions for site selection of Yongzhou clean animal laboratory
LeetCode_位运算_中等_137.只出现一次的数字 II
HarmonyOS 3纯净模式可限制华为应用市场检出的风险应用获取个人数据
JVM memory model
相应通道无电压但ADC的值却在大幅变化且不等于0的可能原因
递归求解迷宫问题
MySQL limit使用及超大分页问题解决
Jmeter 如何解决乱码问题?
Applet helps smart home ecological platform
In the first quarter of 2020, the wearable market shipped 72.6 million units, with apple occupying nearly 30% of the market share
҈ straight ҈ Broadcast ҈ Pre ҈ Report ҈ |҈ In hot summer, let's cross the high temperature and "bake" with nono!
Redis learning and understanding of three special data types
Buildforge materials
C event related exercise code.