我是靠谱客的博主 重要芹菜,最近开发中收集的这篇文章主要介绍用51实现码表,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include <reg52.h>
#include "./delay/delay.h"
#define KEYPORT P1
//P0口
#define TIMEPORT P0
//P0口
#define M_H_TIME 60
//1min = 60s, 1hour = 60min
#define DAY_TIME 24
//1day = 24h
sbit bit_select = P2^0;
//位选
sbit seg_select = P2^1;
//段选
sbit beep = P2^7;
unsigned char code freq[][2]={
0xD8,0xF7,//00440HZ 1
0xBD,0xF8,//00494HZ 2
0x87,0xF9,//00554HZ 3
0xE4,0xF9,//00587HZ 4
0x90,0xFA,//00659HZ 5
0x29,0xFB,//00740HZ 6
0xB1,0xFB,//00831HZ 7
0xEF,0xFB,//00880HZ `1
};
unsigned char star_star[42] = {
0,0,4,4,5,5,4,3,3,2,2,1,1,0,
4,4,3,3,2,2,1,4,4,3,3,2,2,1,
0,0,4,4,5,5,4,3,3,2,2,1,1,0
};
unsigned char happy_sing[12] = {
2,2,3,4,4,3,2,1,0,0,1,2
};
unsigned char High;
unsigned char Low;
unsigned char timedata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//存放显示数字
unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//存放位码
unsigned char tmpdata[8] = {0};
unsigned char second = 100;
//计秒
unsigned char minute = 9;
//计分
unsigned char hour = 0;
//计小时
void timer0_init(void)
{
EA = 1;
TMOD |= 0X01;
TH0 = (65536 - 200) / 256;
TL0 = (65536 - 200) % 256;
ET0 = 1;
TR0 = 1;
}
void timer1_init(void)
{
EA = 1;
TMOD |= 0X10;
TH1 = (65536 - 2000) / 256;
TL1 = (65536 - 2000) % 256;
ET1 = 1;
TR1 = 1;
}
void display_time(void)
{
static unsigned char i = 0;
TIMEPORT = 0x00;	//清空段选值
seg_select = 1;
seg_select = 0;
TIMEPORT = 0xff;	//清空位选值
bit_select = 1;
bit_select = 0;
TIMEPORT = bitdata[i];
//位选
bit_select = 1;
bit_select = 0;
TIMEPORT = tmpdata[i];	//段选
seg_select = 1;
seg_select = 0;
i++;
if(8 == i)
{
i = 0;
}
}
void main()
{
unsigned char j = 0;
unsigned char k = 0;
unsigned char num = 0;
timer0_init();
timer1_init();
while(1)
{
if(minute != 0)
{
for(j = 0; j < 10; j++)
{
beep = ~beep;
}
}
else
{
//
num = star_star[i];
num = happy_sing[k];
High = freq[num][1];
Low = freq[num][0];
TR0 = 1;
delay_ms(200);
delay_ms(200);
delay_ms(200);
TR0 = 0;
delay_ms(100);
k++;
if(10 == k)
{
k = 0;
}
}
}
}
void timer0_ist() interrupt 1
{
if(minute != 0)
{
static unsigned char i = 0;
TH0 = (65536 - 100) / 256;
TL0 = (65536 - 100) % 256;
i--;
if(10 == i)
{
i = 0;
second--;
if(0 == second)
//秒数 == 100 时
{
second = 100;
minute--;
if(0 == minute)
{
minute = 0;
TR1 = 0;
}
}
}
}
else
{
TH0 = High;
TL0 = Low;
beep = ~beep;
}
tmpdata[0] = timedata[hour / 10];
tmpdata[1] = timedata[hour % 10];
tmpdata[2] = 0x40;
tmpdata[3] = timedata[minute / 10];
tmpdata[4] = timedata[minute % 10];
tmpdata[5] = 0x40;
tmpdata[6] = timedata[second / 10];
tmpdata[7] = timedata[second % 10];
}
void timer1_ist() interrupt 3
{
TH1 = (65536 - 1000) / 256;
TL1 = (65536 - 1000) % 256;
display_time();
}

最后

以上就是重要芹菜为你收集整理的用51实现码表的全部内容,希望文章能够帮你解决用51实现码表所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部