概述
#include <reg52.h>
#include "./delay/delay.h"
#define SEGPORT P0
sbit start = P1^0;
sbit end = P1^1;
sbit seg_select = P2^1;
sbit bit_select = P2^0;
unsigned char flag = 1;
unsigned char duanma[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char weima[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char TempData[8];
unsigned char shi = 0, fen = 0, miao = 0;
void display()
{
static unsigned char i = 0;
SEGPORT = 0x0;
seg_select = 1;
seg_select = 0;
SEGPORT = 0xff;
bit_select = 1;
bit_select = 0;
SEGPORT = TempData[i];
seg_select = 1;
seg_select = 0;
SEGPORT = weima[i];
bit_select = 1;
bit_select = 0;
i++;
if(8 == i)
{
i = 0;
}
}
void time0_init(void)
{
EA = 1;
TMOD |= 0x01;
TH0 = (65536 - 2000) / 256;
TL0 = (65536 - 2000) % 256;
ET0 = 1;
TR0 = 1;
}
void time0_isr() interrupt 1
{
static unsigned char i = 0;
TH0 = (65536 - 200) / 256;
TL0 = (65536 - 200) % 256;
i++;
if(flag)
{
if(50 == i)
{
i = 0;
miao++;
if(60 == miao)
{
miao = 0;
fen++;
if(60 == fen)
{
fen = 0;
shi++;
if(24 == shi)
{
shi = 0;
}
}
}
}
}
TempData[0] = duanma[shi / 10];
TempData[1] = duanma[shi % 10];
TempData[2] = 0x40;
TempData[3] = duanma[fen / 10];
TempData[4] = duanma[fen % 10];
TempData[5] = 0x40;
TempData[6] = duanma[miao / 10];
TempData[7] = duanma[miao % 10];
}
void time1_init(void)
{
EA = 1;
TMOD |= 0x10;
TH1 = (65536 - 2000) / 256;
TL1 = (65536 - 2000) % 256;
ET1 = 1;
TR1 = 1;
}
void time1_isr() interrupt 3
{
TH1 = (65536 - 2000) / 256;
TL1 = (65536 - 2000) % 256;
display();
}
void main()
{
time1_init();
time0_init();
while(1)
{
if(0 == start)
{
while(!start);
//È¥¶¶¶¯
delay_ms(10);
while(!start);
if(0 == flag)
{
flag = 1;
}
else
{
flag = 0;
}
}
if(0 == end)
{
while(!end);
//È¥¶¶¶¯
delay_ms(10);
while(!end);
shi = 0;
fen = 0;
miao = 0;
}
}
}
/*****delay.c***********/
void delay_us(unsigned char t)
{
while(--t);
}
void delay_ms(unsigned char t)
{
while(t--)
{
delay_us(245);
delay_us(245);
}
}
void delay_s(unsigned char t)
{
while(t--)
{
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
}
}
/****delay.h*******/
#ifndef _DELAY_H_
#define _DELAY_H_
extern void delay_us(unsigned char t);
extern void delay_ms(unsigned char t);
extern void delay_s(unsigned char t);
#endif
最后
以上就是安详大炮为你收集整理的单片机码表的驱动程序的全部内容,希望文章能够帮你解决单片机码表的驱动程序所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复