完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
#include #define uchar unsigned char #define uint unsigned int ***it DQ=P1^4; ***it Data=P0^2; ***it shcp=P0^4; ***it stcp=P2^3; code unsigned char duan[]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,0x80,0x90,0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//段的数字0123456789,+小数点的0123456789 code unsigned char wei[]={0x01,0x02,0x04,0x08, 0x10,0x20,0x40,0x80};//位的数字12345678 void delay00(unsigned int n) { unsigned int i; while(n--); { i=200; while(i--); } } void delay(uchar n)//延时3us { while(n--); } unsigned char reset(void) { uchar fuwei; DQ=0; delay(180); DQ=1; delay(20); if (!DQ)//说明存在 { fuwei = 1; } else//说明不存在 { fuwei = 0; } delay(160); return fuwei; } void writebyte(uchar val) { uchar i; for(i=0;i<8;i++) { if(val&0x01) { DQ=0; delay(1); DQ=1; delay(20); } else { DQ=0; delay(28); DQ=1; delay(1); } val>>=1; } } uchar readbyte(void) { uchar i,value=0; for(i=0;i<8;i++) { value>>=1; DQ=0; delay(1); DQ=1; _nop_(); if(DQ) { value|=0x80; } else { } delay(25); } return value; } uchar hq(void) { unsigned int temper; reset(); delay00(1); writebyte(0xCC); writebyte(0x44); reset(); delay00(1); writebyte(0xCC); writebyte(0xBE); temper=readbyte(); //读取便签的低字节(8位) temper|=readbyte()<<8;//读取便签的高字节(8位) return(temper); } void smg(unsigned char aa,unsigned char bb) { unsigned char i,duan1=duan[aa],wei1=wei[bb]; shcp=0; stcp=0; for(i=0;i<8;i++) { if(duan1&0x80) { Data=1; } else { Data=0; } _nop_(); shcp=1; _nop_(); shcp=0; _nop_(); duan1<<=1; } for(i=0;i<8;i++) { if(wei1&0x80) { Data=1; } else { Data=0; } _nop_(); shcp=1; _nop_(); shcp=0; _nop_(); wei1<<=1; } stcp=1; stcp=0; } uchar wendu(uint ss) { float wendu0; signed int wendu,wd1; wendu0=ss*0.0625; wd1=wendu0*10+0.5; wendu=wd1+0.05; return wendu; } void xs(signed int fff) { uchar cc,dd,ee; cc=fff/100; dd=fff%100/10; ee=fff%100%10; smg(cc,2);_nop_(); smg(dd+10,1);_nop_(); smg(ee,0);_nop_(); } void main() { uint ww,i; signed int gg; while(1) { reset(); ww=hq(); gg=wendu(ww); for(i=0;i<10;i++) { xs(gg); } } } |
|
相关推荐
2 个讨论
|
|
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 16:41 , Processed in 0.798177 second(s), Total 50, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号