完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我就纳闷,论坛上这么多人就没一个来帮我们新手解决问题的么,自己慢慢摸索,终于把问题解决掉了。
#include #define uint unsigned int #define uchar unsigned char uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar numxiaoshi,numfenzhong,nummiao,xiaoshishi,xiaoshige,fenzhongshi,fenzhongge,miaoshi,miaoge; void delayms(uint z)//延时函数 { uint i,j; for(i=z;i>0;i--) for(j=110;j>0;j--); } void display()//显示函数 { //以下16行显示小时 P5OUT=0x20; P4OUT=0xfe; P5OUT=0x00; P4OUT=0xff; P5OUT=0x01; P4OUT=table[xiaoshishi]; P5OUT=0x00; delayms(10); P5OUT=0x20; P4OUT=0xfd; P5OUT=0x00; P4OUT=0xff; P5OUT=0x01; P4OUT=table[xiaoshige]; P5OUT=0x00; delayms(10); //以下16行显示分钟 P5OUT=0x10; P1OUT=0xfe; P5OUT=0x00; P1OUT=0xff; P5OUT=0x02; P1OUT=table[fenzhongshi]; P5OUT=0x00; delayms(10); P5OUT=0x10; P1OUT=0xfd; P5OUT=0x00; P1OUT=0xff; P5OUT=0x02; P1OUT=table[fenzhongge]; P5OUT=0x00; delayms(10); //以下16行显示秒 P5OUT=0x08; P2OUT=0xfe; P5OUT=0x00; P2OUT=0xff; P5OUT=0x04; P2OUT=table[miaoshi]; P5OUT=0x00; delayms(10); P5OUT=0x08; P2OUT=0xfd; P5OUT=0x00; P2OUT=0xff; P5OUT=0x04; P2OUT=table[miaoge]; P5OUT=0x00; delayms(10); } init()//定时器A初始化 { WDTCTL=WDTPW+WDTHOLD; P3DIR=0x00; P4DIR=0xff; P5DIR=0xff; P1DIR=0xff; P2DIR=0xff; P3SEL=0; P1SEL=0; P2SEL=0; P4SEL=0; P5SEL=0; BCSCTL1=CALBC1_1MHZ; DCOCTL=CALBC1_1MHZ; TACTL=TASSEL_2+MC_3+ID_3; CCTL0=CCIE; CCR0=46000; _EINT(); } anjian() { if(P3IN==0x0e) { delayms(10); if(P3IN==0x0e) { while(!(P3IN==0x0f)); _DINT(); while(1) { miaoshi=nummiao/10; miaoge=nummiao%10; fenzhongshi=numfenzhong/10; fenzhongge=numfenzhong%10; xiaoshishi=numxiaoshi/10; xiaoshige=numxiaoshi%10; display(); if(P3IN==0x0d) { delayms(10); if(P3IN==0x0d) { while(!(P3IN==0x0f)); nummiao++; if(nummiao>59) nummiao=0; } } if(P3IN==0x0b) { delayms(10); if(P3IN==0x0b) { while(!(P3IN==0x0f)); numfenzhong++; if(numfenzhong>59) numfenzhong=0; } } if(P3IN==0x07) { delayms(10); if(P3IN==0x07) { while(!(P3IN==0x0f)); numxiaoshi++; if(numxiaoshi>23) numxiaoshi=0; } } if(P3IN==0x0e) { delayms(10); if(P3IN==0x0e) { while(!(P3IN==0x0f)); _EINT(); break; } } } } } } void main() { init(); while(1) { anjian(); miaoshi=nummiao/10; miaoge=nummiao%10; fenzhongshi=numfenzhong/10; fenzhongge=numfenzhong%10; xiaoshishi=numxiaoshi/10; xiaoshige=numxiaoshi%10; display(); } } #pragma vector=tiMERA0_VECTOR __interrupt void Timer_A() { nummiao++; if(nummiao>59) { nummiao=0; numfenzhong++; } if(numfenzhong>59) { numfenzhong=0; numxiaoshi++; } if(numxiaoshi>23) { numxiaoshi=0; } }
|
|
相关推荐
11 个讨论
|
|
|
厉害~~~赞楼主~~
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
3333个成员聚集在这个小组
加入小组9768 浏览 1 评论
10571 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
10891 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2679 浏览 1 评论
5131 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
10894浏览 2评论
10575浏览 1评论
9771浏览 1评论
8422浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-13 23:00 , Processed in 1.445447 second(s), Total 60, Slave 52 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2321