完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
#include
#define uint unsigned int #define uchar unsigned char uchar code table[]={ 0xC0,0xF9,0xA4,0xB0, 0x99,0x92,0x82,0xF8, 0x80,0x90}; uchar shi,fen,miao; ***it ce=P1^2; ***it sclk=P1^1; ***it sda=P1^0; void delay(uint z) //延迟 { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void write_bit(uchar date) //写一位 { uchar i; for(i=0;i<8;i++) { sclk=0; sda=date&0x01; date<<=1; sclk=1; } } uchar read_bit() //读一位 { uchar i,temp; for(i=0;i<8;i++) { temp=temp>>1; sclk=0; if(sda) temp=temp&0x80; sclk=1; } return temp; } void write_1302(uchar add,uchar dat) //写进1302地址,数据 { ce=0; sclk=1; ce=1; write_bit(add); write_bit(dat); sclk=0; ce=0; } uchar read_1302(uchar dats) //读1302数据 { uchar dat; ce=0; sclk=0; ce=1; write_bit(dats); dat=read_bit(); sclk=1; ce=0; return dat; } void write() //对内部进行初始化 { write_1302(0x8e,0x00); write_1302(0x80,0x00); write_1302(0x82,0x43); write_1302(0x84,0x15); write_1302(0x86,0x17); write_1302(0x88,0x07); write_1302(0x8a,0x01); write_1302(0x8c,0x11); write_1302(0x8e,0x80); } uchar BCD(uchar bcd) //转换成BCD码 { uchar num; num=bcd>>4; return(num=num*10+(bcd&=0x0F)); } void dispaly(uchar shi,uchar fen,uchar miao) //显示 { uchar ad1,ad2,ad3,ad4,ad5,ad6; ad1=miao/10; ad2=miao%10; ad3=fen/10; ad4=fen%10; ad5=shi/10; ad6=shi%10; P0=0Xff; P0=table[ad1]; P2=0x01; delay(1); P0=0Xff; P0=table[ad2]; P2=0x02; delay(1); P0=0Xff; P0=table[ad3]; P2=0x04; delay(1); P0=0Xff; P0=table[ad4]; P2=0x08; delay(1); P0=0Xff; P0=table[ad5]; P2=0x10; delay(1); P0=0Xff; P0=table[ad6]; P2=0x20; delay(1); } void init() //中断初始化 { TMOD=0x01; TH0=(65535-8000)/256; TL0=(65535-8000)%256; EA=1; ET0=1; TR0=1; } void main() //主函数 { init(); write(); while(1) { miao=BCD(read_1302(0x81)); fen=BCD(read_1302(0x83)); shi=BCD(read_1302(0x85)); } } void to() interrupt 1 //中断子函数 { TH0=(65535-8000)/256; TL0=(65535-8000)%256; dispaly(shi,fen,miao); } 显示不正常
|
|
相关推荐
3个回答
|
|
|
|
|
|
|
|
|
学习 学习!!!
|
|
|
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
470 浏览 0 评论
532 浏览 0 评论
660 浏览 0 评论
822 浏览 0 评论
RT-Thread与英飞凌(infineon)合作得板子PSOC 6 板子学习
758 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
17027 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-13 05:36 , Processed in 0.656509 second(s), Total 77, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2757