完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
本人初学单片机 准备做一个显示角度传感器转过的角度的题目 手上拿到的角度传感器是0到180度 0到5伏的电压输出
程序如下 #include #define uchar unsigned char #define uint unsigned int ***it DSO=P1^0; ***it DSI=P1^1; ***it CS=P1^2; ***it CLK=P1^3; uchar code tab[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; uchar code wei[]={0xf1,0xf2,0xf4,0xf8}; uint huancun[]={0x00,0x00,0x00,0x00}; void delay(uint m) { while(m--); } void display() { uchar i; for(i=0;i<4;i++) { P2=wei; P0=tab[huancun]; delay(5); } } uint Read_TLC2543(uchar CHN) { uchar i,temp; uint ad=0; CHN=CHN<<4; CLK=0; CS=1; CS=0; temp=CHN; for(i=0;i<12;i++) { ad=ad<<1; if((temp&0x80)!=0){DSI=1;} else{DSI=0;} if(DSO){ad=ad+1;} CLK=1; CLK=0; temp=temp<<1; } CS=1; ad=ad&0x0fff; return(ad); } void main() { float sum; uint date; while(1) { sum=Read_TLC2543(0x00)*18.0; date=sum/4095; huancun[0]=date/1000; huancun[1]=date%1000/100; huancun[2]=date%1000%100/10; huancun[3]=date%10; display(); } } 仿真得到的结果精度不够 何解
|
|
相关推荐
3个回答
|
|
|
sum=Read_TLC2543(0x00)*18.0;???
|
|
|
|
|
|
抱歉 是*1800然后 电阻每上升1%就18+18的变化 |
|
|
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
【瑞萨RA6E2】瑞萨E2S软件安装过程,等待过程玩下97_e2 studio_ZGZZ
331 浏览 0 评论
532 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
842 浏览 0 评论
1383 浏览 2 评论
824 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16912 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 15:08 , Processed in 1.193750 second(s), Total 76, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2374