当前位置:网站首页>Single chip microcomputer nixie tube stopwatch
Single chip microcomputer nixie tube stopwatch
2022-04-23 08:46:00 【Teenagers don't know programming】
Single chip microcomputer operation : Using the timer of single chip microcomputer to design a 0-99 Stop watch , Press the button S1 The stopwatch starts counting from zero , Press the button S2 The stopwatch stops , And display the final second timing value . Run the video in seconds ( We can pay attention to the official account MCU Learning notes reply Nixie tube stopwatch Get job engineering ):
Stopwatch
-
Interface information
The code breaking terminal of nixie tube is connected with the of single chip microcomputer P0 mouth , Bit selective termination is connected to the of single chip microcomputer P2.4、P2.5、P2.6、P2.7. The thousand and hundred bits of the nixie tube display the second count , Ten bit timer interrupt count .
2. Program code
The timer is initialized to the working mode 1, The timer timing time is 20ms, That is, the time of each overflow of the timer is 20ms, Then overflow 50 The second is the second 1 Second . By querying the value of the overflow flag bit .
void timer_inial()
{
TMOD = 0X01;//
TH0=0XB8;// timing 0.02s
TL0=0X00;
}
Timer overflow handler : After each overflow , To manually clear the overflow flag bit , Then reinstall the initial value . At the same time, the second count value is added 1, Add up 50 Once in a second .
void second_cal_show()
{
if(TF0==1)
{
TF0=0;
TH0=0XB8;
TL0=0X00;
time_count++;
if(time_count>=50)//50 One second at a time
{
time_count=0;
time_S++;
}
}
}
The main function : Mainly timer initialization , Then cycle the key to start 、 Key stop 、 Timer overflow processing and refresh nixie tube display function .
void main()
{
timer_inial();
while(1)
{
start();
stop();
second_cal_show();
LEDdisplay(time_S*100+time_count*2);
}
}
The following is the full code of the job :
#include <reg52.h>
#include <stdio.h>
// Define two bit variables , Corresponding to the start button and stop reset button respectively
sbit key_set=P3^2;
sbit key_reset=P3^3;
unsigned char time_count=0;
unsigned int time_S=0;
#define LED_PORT P0
sbit wela_1 = P2^4;
sbit wela_2 = P2^5;
sbit wela_3 = P2^6;
sbit wela_4 = P2^7;
sbit dp=P0^7;
//LED Display font 0-F Gongyang mode
unsigned code table[]= {0Xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void timer_inial();// Timer initialization
void delay(unsigned int i);// The time delay function
void start();
void stop();
void second_cal_show();
/*******************************************************************************
* Letter Count name :Delayms
* The functionality : Realization ms Level delay
* transport Enter into :ms
* transport Out : nothing
*******************************************************************************/
void Delay_ms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
#if FOSC == 11059200L
for(j=0;j<114;j++);
#elif FOSC == 12000000L
for(j=0;j<123;j++);
#elif FOSC == 24000000L
for(j=0;j<249;j++);
#else
for(j=0;j<114;j++);
#endif
}
/*******************************************************************************
* Letter Count name :LEDdisplay
* The functionality : Cycle the data on each bit
* transport Enter into :num Data to display
* transport Out : nothing
*******************************************************************************/
void LEDdisplay(unsigned int num)
{
unsigned char qian,bai,shi,ge;
qian=num/1000;
bai=num%1000/100;
shi=num%100/10;
ge=num%10;
wela_1 = 1; // Turn off all nixie tubes
wela_2 = 1;
wela_3 = 1;
wela_4 = 1;
wela_4=0; // Display thousands
LED_PORT=table[qian];
Delay_ms(1);
LED_PORT = 0xff;
wela_4=1;
wela_3=0; // Display hundreds
LED_PORT=table[bai];
Delay_ms(1);
LED_PORT = 0xff;
//dp=0;
wela_3=1;
wela_3=0; // Display hundreds
dp=0;
Delay_ms(1);
LED_PORT = 0xff;
wela_3=1;
wela_2=0; // Show ten
LED_PORT=table[shi];
Delay_ms(1);
LED_PORT = 0xff;
wela_2=1;
wela_1=0; // Display a bit
LED_PORT=table[ge];
Delay_ms(1);
LED_PORT = 0xff;
}
void main()
{
timer_inial();
while(1)
{
start();
stop();
second_cal_show();
LEDdisplay(time_S*100+time_count);
}
}
void timer_inial()
{
TMOD = 0X01;//
TH0=0XB8;// timing 0.02s
TL0=0X00;
}
// The time delay function
void delay(unsigned int i)
{
unsigned int k;
for(k=0;k<i;k++);
}
void start()
{
if(0==key_set)
{
delay(1200);//10ms Desquamation
if(0==key_set)// Check whether the key is pressed again
{
while(!key_set);// Wait for the key to release
TR0=1;
time_S=0;
time_count=0;
}
}
}
void stop()
{
if(0==key_reset)
{
delay(1200);//10ms Desquamation
if(0==key_reset)// Check whether the key is pressed again
{
while(!key_reset);// Wait for the key to release
TR0=0;
}
}
}
void second_cal_show()
{
if(TF0==1)
{
TF0=0;
TH0=0XB8;
TL0=0X00;
time_count++;
if(time_count>=50)//50 One second at a time
{
time_count=0;
time_S++;
}
}
}
版权声明
本文为[Teenagers don't know programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230840173082.html
边栏推荐
- 在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
- 洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別
- 《深度学习》学习笔记(八)
- synchronized 锁的基本用法
- K210 learning notes (II) serial communication between k210 and stm32
- Automatic differentiation and higher order derivative in deep learning framework
- Detailed description of self feeling of auricular point weight loss 0422
- Consensus Token:web3. 0 super entrance of ecological flow
- 洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
- Large amount of data submitted by form post
猜你喜欢
STM32 uses Hal library. The overall structure and function principle are introduced
HAL库的RCC简介
'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...
洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別
JVM工具之Arthas使用
L2-024 部落 (25 分)(并查集)
SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
After a circle, I sorted out this set of interview questions..
MATLAB 画五星红旗
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
随机推荐
Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board
Get the absolute path of the class according to the bytecode
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
Copy array in JS
关于数组复制问题
四张图弄懂matplotlib的一些基本用法
PLC的点表(寄存器地址和点表定义)破解探测方案--方便工业互联网数据采集
MATLAB入门资料
Study notes of deep learning (8)
JVM工具之Arthas使用
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
00后最关注的职业:公务员排第二,第一是?
正点原子携手OneOS直播 OneOS系统教程全面上线
HAL库的RCC简介
OneFlow學習筆記:從Functor到OpExprInterpreter
共享办公室,提升入驻体验
测试你的机器学习流水线
Let the earth have less "carbon" and rest on the road
tsdf +mvs
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解