当前位置:网站首页>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
边栏推荐
猜你喜欢

L2-3 浪漫侧影 (25 分)

Test your machine learning pipeline

idea配置连接远程数据库MySQL,或者是Navicat连接远程数据库失败问题(已解决)

Introduction to GUI programming swing

OneFlow學習筆記:從Functor到OpExprInterpreter

Knowledge points and problem solutions related to information collection

Chris LATTNER, father of llvm: the golden age of compilers

使用flask和h5搭建网站/应用的简要步骤

xctf刷题小记

After a circle, I sorted out this set of interview questions..
随机推荐
共享办公室,提升入驻体验
Consensus Token:web3. 0 super entrance of ecological flow
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
Harbor企业级镜像管理系统实战
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
STM32F103ZET6【标准库函数开发】----库函数介绍
DOM learning - add + - button
使用flask和h5搭建网站/应用的简要步骤
Reference passing 1
Illegal character in scheme name at index 0:
PgSQL wants to implement all kinds of column sub query operations of MySQL
正点原子携手OneOS直播 OneOS系统教程全面上线
Let the earth have less "carbon" and rest on the road
Introduction to protobuf
Swagger document export custom V2 / API docs interception
Misunderstanding of flush () method of OutputStream class
四张图弄懂matplotlib的一些基本用法
求简单类型的矩阵和
ESP32程序下载失败,提示超时
虚拟线上展会-线上vr展馆实现24h沉浸式看展