#include #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
上一篇:51单片机串口通信的驱动程序
下一篇:单片机之矩阵键盘的驱动程序
设计资源 培训 开发板 精华推荐
- OP213FSZ-REEL7 多媒体声音编解码器耳机输出放大器典型应用
- LTC6360 演示板驱动 LTC2364-16 16 位、0.25Msps SAR ADC
- 【RA】瑞萨Mini开发板冰墩墩小夜灯-402304A
- LT1033CT 多跟踪线性稳压器的典型应用电路
- #第七届立创电赛#带pd的桌面电源控制板
- LT3970IMS-5 5V 降压转换器的典型应用
- LTC3630AIDHC 4V 至 63V 输入至 -12V 输出、正负转换器的典型应用电路
- 适用于 SPC56 D 系列的 SPC560D-DIS、SPC56D-Discovery 探索套件 - 带有 SPC56D40L1 MCU
- OP184FSZ-REEL7 2.5V 基准的典型应用在单 3V 电源上运行
- EVAL-AD5443-DBRDZ,使用 AD5443 的评估板,具有串行接口的 12 位高带宽乘法 DAC