您的位置 首页 IOT

80C51单片机经过模仿SPI口驱动UZZ9001读写操作

includereg51h>includeabsacch>includeintrinsh>includemathh>sbitCS=P2^0;sbitCLK

#include

#include   #include    #include   sbit CS  = P2^0;   sbit CLK = P2^1;   sbit DATA= P2^2;   /*宏界说8155的A口,B口和操控口*/   #define PA8155 XBYTE[0x7101]   #define PB8155 XBYTE[0x7102]   #define COM8155 XBYTE[0x7100]   //显现[0,1,2,3,4,5,6,7,8,9,A,b,c,d,e,f]的代码;   unsigned char code  Table[16]={0X0FC,0X60,0X0DA,0X0F2,0X66,0X0B6,0X0BE,0X0E0,0X0FE,0X0F6,0xee,0x3e,0x9c,0x7a,0xde,0x8e};   unsigned char Buf[4]={0,0,0,0};             //对应四个数码管显现数据的缓冲区   void delay(unsigned int time)  //延时                                           {      while(time--);     }   /*************************************************  函数称号:数码管显现  功用:将四个缓冲区单元的内容别离显现到四个数码管上面  参数:unsigned charp *Bufptr  返回值:无  **************************************************/   void DISP_LED(unsigned char *Bufptr)   {   unsigned char disi;   unsigned char BitCT=0X10;   for(disi=0;disi<4;disi++)   {   PA8155=BitCT;                                       //选中个位数码管   PB8155=Table[*Bufptr++]+(disi==1);                          //取段码   BitCT=_crol_(BitCT,1);                              //左移一位   delay(500);   }   }   unsigned int uzz9001(void)   {   unsigned int i,temp=0;   CLK=1;   CS=1;   delay(5);   CS=0;   delay(1);   i=16;   while(i--)   {   temp<<=1;   CLK=0;   delay(5);   CLK=1;   if(DATA==1)   temp |=0x0001;   else   temp &=0xfffe;   delay(5);   }   CS=1;   return(temp);   }   float angle(void)   {   unsigned int i,temp0,temp1,temp2=0;   float jiaodu;   for(i=0;i<8;i++)   {   temp0=uzz9001();   temp1=temp0&0x3f00;   temp1>>=1;   temp0&=0x007f;   temp0=temp0+temp1;   temp2+=temp0;   }   jiaodu=temp2*180.000/65536.000;   return(jiaodu);   }   void main()   {   unsigned char count;   unsigned int jiaodu;   COM8155=0x03;   TMOD=0X01;   TH0=0X3c;       //初始化,守时50MS   TL0=0Xb0;   count=0;   TR0=1;   while(1)   {   DISP_LED(Buf);   if(TF0==1)    {   TF0=0;   count++;   if(count==10)   //20*50MS=1S   {   count=0;   jiaodu=(unsigned int) (angle()*10.0);   DISP_LED(Buf);   Buf[3]=jiaodu/1000;   Buf[2]=jiaodu%1000/100;      Buf[1]=jiaodu%100/10;   Buf[0]=jiaodu%10;   }   }   }   }   

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/iot/318297.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部