矩阵键盘可调时钟
来源:互联网 发布:轩辕剑伏曦殿进阶数据 编辑:程序博客网 时间:2024/04/30 05:53
#include <reg52.h>#include "./delay/delay.h"#define SEGPORT P0#define KEYPORT P1unsigned char num[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char segdata[8] = {0x3f,0x3f,0x40,0x3f,0x3f,0x40,0x3f,0x3f};unsigned char s = 0;unsigned char min = 0;unsigned char h = 0;sbit bit_select = P2^0;sbit seg_select = P2^1;sbit beep =P3^7;void timer0_init(void) {EA = 1;TMOD |= 0x01; TH0 = (65536 - 1000) / 256; TL0 = (65536 - 1000) % 256; ET0 = 1; TR0 = 0;//计时控制}void timer1_init(void){EA = 1;TMOD |= 0x10;TH1 = (65536 - 1000) / 256;TL1 = (65536 - 1000) % 256;ET1 = 1;TR1 = 1;}unsigned char key_scan(void) //键盘扫描{unsigned char keyvalue;KEYPORT = 0xf0;if(0xf0 != KEYPORT){delay_ms(10);if(0xf0 != KEYPORT){KEYPORT = 0xfe;if(0xfe != KEYPORT){keyvalue = KEYPORT;keyvalue &= 0xf0;keyvalue += 0x0e;while(0xfe != KEYPORT);delay_ms(10);while(0xfe != KEYPORT);return keyvalue;} KEYPORT = 0xfd;if(0xfd != KEYPORT){keyvalue = KEYPORT;keyvalue &= 0xf0;keyvalue += 0x0d;while(0xfd != KEYPORT);delay_ms(10);while(0xfd != KEYPORT);return keyvalue;}KEYPORT = 0xfb;if(0xfb != KEYPORT){keyvalue = KEYPORT;keyvalue &= 0xf0;keyvalue += 0x0b;while(0xfb != KEYPORT);delay_ms(10);while(0xfb != KEYPORT);return keyvalue;}KEYPORT = 0xf7;if(0xf7 != KEYPORT){keyvalue = KEYPORT;keyvalue &= 0xf0;keyvalue += 0x07;while(0xf7 != KEYPORT);delay_ms(10);while(0xf7 != KEYPORT);return keyvalue;}}}return 0xff;}void main(){ unsigned char key; delay_s(0);timer0_init();timer1_init();while(1){key = key_scan();if(0xff != key){if(0x7e == key) //时钟停止运行{TR0 = ~TR0;}if(0xbe == key) //调小时高位 {if(h <= 13){h += 10;segdata[0] = num[h / 10];}else{h = 0;segdata[0] = num[h / 10];} }if(0xde == key) //调小时低位{if(h <= 23){h += 1;segdata[1] = num[h %10];}else{h = 0;segdata[1] = num[h % 10];}}if(0xbd == key) //调分钟高位{if(min <= 49){min += 10;segdata[3] = num[min /10];}else{min = 0;segdata[3] = num[min / 10];}}if(0xdd == key) //调分钟低位{if(min <= 59){min += 1;segdata[4] = num[min %10];}else{min = 0;segdata[4] = num[min % 10];}}if(0xbb == key) //调秒位高位{if(s <= 49){s += 10;segdata[6] = num[s /10];}else{s = 0;segdata[6] = num[s / 10];}}if(0xdb == key) //调秒位低位{if(s <= 59){s += 1;segdata[7] = num[s %10];}else{s = 0;segdata[7] = num[s % 10];}}}}}void display() //显示时钟{static unsigned char i = 0;SEGPORT = 0x0;seg_select = 1;seg_select = 0;SEGPORT = 0xff;bit_select = 1;bit_select = 0;SEGPORT = segdata[i];seg_select = 1;seg_select = 0;SEGPORT = bitdata[i];bit_select = 1;bit_select = 0;i++;if(8 == i){i = 0;}}void timer0_isr(void) interrupt 1{ static unsigned char i = 0;TH0 = (65536 - 20000) / 256;TL0 = (65536 - 20000) % 256;i++;if(50 == i){i = 0;s++;if(60 == s){s = 0;min++;if(60 == min){min = 0;h++;if(24 == h){ h = 0;}}}}segdata[0] = num[h / 10];segdata[1] = num[h % 10];segdata[2] = 0x40;segdata[3] = num[min / 10];segdata[4] = num[min % 10];segdata[5] = 0x40;segdata[6] = num[s / 10];segdata[7] = num[s % 10];}void timer1_isr(void) interrupt 3{TH1 =(65536 - 1000) / 256;TL1 =(65536 - 1000) % 256;display();}
0 0
- 矩阵键盘可调时钟
- 矩阵键盘可调闹钟
- 矩阵键盘可调时间,可调闹钟(LCD显示)
- 可调时钟
- 矩阵键盘时钟
- 可调数字时钟程序
- 定时器可调时钟
- LCD液晶显示可调时钟
- 可调闹钟lcd时钟
- 可调闹钟的时钟
- 51单片机可调时钟
- 数码可调时钟(加闹钟)
- 3、时钟数码管显示--可调时
- 可编程时钟4个时钟的独立可调设计
- 单片机实验代码——可调时间的时钟程序
- 单片机==矩阵键盘+时钟+键入时间+闹钟(12)
- 矩阵键盘
- 矩阵键盘
- 自动化专业英语常用词汇集锦
- ubuntu16.04安装mysql报错解决
- Lua 关于类的理解整理
- awk命令
- CSDN 博客转载
- 矩阵键盘可调时钟
- MySQL索引背后的数据结构及算法原理
- 数组的数组
- ubuntu14.04上vncserver上的相关配置
- java中实现根据中文首字母排序
- iOS开发之drawRect的作用和调用机制
- 升级XCode8编译报错:“Module file was created by an older version of the compiler”
- LeetCode 136: Invert Binary Tree
- php知识整理