seg显示时间——51程序
2016-09-11 10:52
459 查看
#include #define SEGPORT P0 sbit bit_select = P2 ^ 0; //p2 ^ 0控制位选锁存器,位选锁存器选定 数码管 sbit seg_select = P2 ^ 1; //p2 ^ 1控制段选锁存器,段选锁存器选定 数码管的内容(并显示内容)。 unsigned char segdata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char tempdata[8] = 0x0; unsigned char shi = 23; unsigned char fen = 59; unsigned char miao = 50; unsigned int count = 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 = bitdata[i]; //选定并显示特定数码管的内容 bit_select = 1; bit_select = 0; SEGPORT = tempdata[i]; seg_select = 1; seg_select = 0; i++; if(i == 8) { i = 0; } } void timer0_init(void) //定时器中断0,计算时间,优先级大于中断1 { EA = 1; TMOD = 0x01; TH0 = (65536 - 2000) / 256; TL0 = (65536 - 2000) % 256; ET0 = 1; TR0 = 1; } void timer1_init(void) //定时器中断1,显示时间 { EA = 1; TMOD = 0x11; TH1 = (65536 - 2000) / 256; TL1 = (65536 - 2000) % 256; ET1 = 1; TR1 = 1; } void main() { timer0_init(); timer1_init(); while(1); } void timer0_isr() interrupt 1 { TH0 = (65536 - 2000) / 256; TL0 = (65536 - 2000) % 256; count++; if(500 == count) { count = 0; miao++; if(60 == miao) { miao = 0; fen++; } if(60 == fen) { fen = 0; shi++; } if(24 == shi) { shi = 0; } } tempdata[0] = segdata[shi / 10]; tempdata[1] = segdata[shi % 10]; tempdata[2] = 0x40; tempdata[3] = segdata[fen / 10]; tempdata[4] = segdata[fen % 10]; tempdata[5] = 0x40; tempdata[6] = segdata[miao / 10]; tempdata[7] = segdata[miao % 10]; } void timer1_isr() interrupt 3 { TH1 = (65536 - 2000) / 256; TL1 = (65536 - 2000) % 256; display(); }
相关文章推荐
- 根据服务器时间作为起始,显示时钟的小程序
- jsp中以服务器时间作为起始,显示时钟的小程序
- 显示程序执行时间php函数代码
- 帝国 标签模板 使用程序代码 自定义 时间显示方式
- 显示程序运行时间
- 团购限时抢购时间显示程序
- java的显示时间的程序
- 《PHP---简单小程序服务器为浏览器提供时间显示》
- 程序退出时,显示程序运行时间
- 给基于对话框的MFC程序添加状态栏并实时显示时间(转)
- 简单小程序获取显示当前时间
- 51单片机8*8点阵LED显示原理及程序
- c#窗体编程之建立时钟程序显示当前时间
- 关于c++中程序的时间显示
- 帖一个根据服务器时间作为起始,显示时钟的小程序
- 如何让程序显示运行时间和当前日期
- 第九周实验报告任务 1 定义Time类中的<<和>>运算符重载,实现时间的输入输出,改造原程序中对运算结果显示方式,使程序读起来更自然。
- 给基于对话框的MFC程序添加状态栏并实时显示时间
- DS18B20多点测温(读序列,匹配序列,51 C程序,1602显示)
- 利用BIOS中断或DOS中断实现一个显示当前时间的程序