1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
***it S7 = P3^0; unsigned char a = 0; //状态位 bit b = 1; unsigned char count = 0; unsigned char month = 1; unsigned char code SEG_code[19] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e, 0xbf,0x7f,0xff}; //定义共阳数码管段码内容:0~F,—,. void Delay(unsigned int t) { while(t--); } //void delay_m(unsigned int n) //延时n秒 //{ // unsigned int i=0,j=0; // for(i=0;i // for(j=0;j<21738;j++); //} void Select_HC138(unsigned char n) { switch(n) { case 5: P2 = (P2 & 0x1f) | 0xa0; break; case 6: P2 = (P2 & 0x1f) | 0xc0; break; case 7: P2 = (P2 & 0x1f) | 0xe0; break; } } void Show_tube(unsigned char position,unsigned char value) { Select_HC138(6); P0 = 0x01 << position; Select_HC138(7); P0 = value; } void Dynamic_display() { if((a == 1)&&(b == 1)) { Show_tube(0,SEG_code[18]); Show_tube(1,SEG_code[18]); } else { Show_tube(0,SEG_code[2]); Delay(500); Show_tube(1,SEG_code[3]); Delay(500); } Show_tube(2,SEG_code[16]); Delay(500); if((a == 2)&&(b == 1)) { Show_tube(3,SEG_code[18]); Show_tube(4,SEG_code[18]); } else { Show_tube(3,SEG_code[5]); Delay(500); Show_tube(4,SEG_code[9]); Delay(500); } Show_tube(5,SEG_code[16]); Delay(500); if((a == 3)&&(b == 1)) { Show_tube(6,SEG_code[18]); Show_tube(7,SEG_code[18]); } else { Show_tube(6,SEG_code[5]); Delay(500); Show_tube(7,SEG_code[0]); Delay(500); } } //void Delay_dynamic(unsigned char t) //延时,让最后两位数码管的值发生变化(从1变到12) //{ // while(t--) // { // Dynamic_display(); // } //} void Init_timer0() //定时器0初始化(中断初始化) { TMOD = 0x01; //选择定时器0(16位定时器),定时50ms(间隔50000个脉冲) TH0 = (65535 - 50000) / 256; //取高八位(3c)给TH0寄存器 TL0 = (65535 - 50000) % 256; //取低八位(af)给TL0寄存器 EA = 1; //打开总中断 ET0 = 1; //打开定时器0的中断 TR0 = 0; //关闭定时器 } void Service_timer0() interrupt 1 //定时器0中断服务函数 { TH0 = (65535 - 50000) / 256; TL0 = (65535 - 50000) % 256; //一次计时完后需要给TH0和TL0赋初值 count++; if(count == 10) //定时0.5s(间隔1s) { b = ~b; count = 0; } } void Delay_keys() { unsigned char i,j; i = 108; j = 145; do { while(--j); }while(--i); } void Press_keys() { if(S7 == 0) { Delay_keys(); if(S7 == 0) { switch(a) { case 0: a = 1; TR0 = 1; break; case 1: a = 2; break; case 2: a = 3; break; case 3: a = 0; TR0 = 0; break; } while(S7 == 0) { Dynamic_display(); } } } } void main() { Init_timer0(); Select_HC138(5); P0 = 0x00; while(1) { //Dynamic_display(); // if(month > 12) // { // month = 1; // } // Delay_dynamic(200); // month++; Dynamic_display(); Press_keys(); } } |
|
|
|
只有小组成员才能发言,加入小组>>
3323 浏览 9 评论
3000 浏览 16 评论
3498 浏览 1 评论
9073 浏览 16 评论
4093 浏览 18 评论
1198浏览 3评论
614浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
603浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2343浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1902浏览 2评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-30 23:58 , Processed in 1.278922 second(s), Total 78, Slave 59 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号