单片机之秒表
来源:互联网 发布:南风知我意1免费阅读 编辑:程序博客网 时间:2024/05/18 00:03
用单片机控制数码管实现秒表功能
要求:秒表跑到10s时停止,蜂鸣器响一声,秒表精度为0.01s
代码张贴:
#include <reg52.h>
#define SEGPORT P0
sbit dula=P1^1;
sbit wela=P1^0;
sbit deep = P1^2;
unsigned char code wei_table[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char tempdata[4];
unsigned char p_table[10] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
unsigned char code table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char miao,m_miao;
void display_seg()
{
static unsigned char i = 0;
SEGPORT=0xff;
wela = 1;
wela = 0;
SEGPORT =0x0;
dula = 1;
dula = 0;
SEGPORT=wei_table[i];
wela = 1;
wela = 0;
SEGPORT = tempdata[i];
dula = 1;
dula = 0;
i++;
if(4 == i)
{
i = 0;
}
}
void timer0_init()
{
EA = 1;
TMOD = 0x01;
TH0 = (65536 - 3000)/256;
TL0 = (65536 - 3000)%256;
ET0 = 1;
TR0 = 1;
}
void timer1_init()
{
EA = 1;
TMOD |= 0x10;
TH1 = (65536 - 10000)/256;
TL1 = (65536 - 10000)%256;
ET1 = 1;
TR1 = 1;
}
void timer0_isr() interrupt 1
{
TH0 = (65536 - 3000)/256;
TL0 = (65536 - 3000)%256;
display_seg();
}
void timer1_isr() interrupt 3
{
unsigned char i,j;
TH1 = (65536 - 10000)/256;
TL1 = (65536 - 10000)%256;
m_miao++;
if(100 == m_miao)
{
m_miao = 0;
miao++;
if(10 == miao)
{
ET1 = 0;
tempdata[0] = table[miao/10];
tempdata[1] = p_table[miao%10];
tempdata[2] = table[m_miao/10];
tempdata[3] = table[m_miao%10];
for(j=0;j<200;j++)
{
i=50;
deep = ~deep;
while(i--);
}
}
}
tempdata[0] = table[miao/10];
tempdata[1] = p_table[miao%10];
tempdata[2] = table[m_miao/10];
tempdata[3] = table[m_miao%10];
}
void main()
{
timer0_init();
timer1_init();
while(1);
}
- 单片机之秒表
- 【单片机】秒表
- 单片机之数码管秒表的动态显示
- 单片机秒表计时器
- 单片机实现秒表功能
- 10.1 单片机数字秒表程序
- 单片机设计的计数器(秒表)
- 单片机秒表程序(自动切换时间
- 利用 51 单片机实现 0.0 ~ 10 秒表
- 单片机——矩阵键盘秒表
- 基于MSP430f149单片机的简单秒表
- IOS之秒表计时器
- 秒表
- 秒表
- 秒表
- 秒表
- Swing小程序之秒表
- 51单片机学习(三)数码管秒表完成啦!
- supervisord简介
- 开源日志log4cplus-1.2.0使用1
- 【计算机视觉】【并行计算与CUDA开发】GPU硬解码---DXVA
- 解决DEV C++编译时出现的“ undefined reference to `___dyn_tls_init_callback'...”问题
- 开源app之MyHearts
- 单片机之秒表
- JSP属性范围
- 牛顿迭代法(Newton's Method)
- 从零开始学JDBC--1.9 代码抽取--使用Properties读取配置文件
- 初识IntelliJ
- Mysql必知必会(笔记)【存储过程】
- Elasticsearch.The.Definitive.Guide学习笔记 -- 3. Data in, Data in
- 浅谈Java集合
- **[Lintcode]Majority Number III