欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: GY-26電子指南針資料(串口+IIC+溫度源程序) [打印本頁(yè)]

作者: 第二只芐基    時(shí)間: 2017-10-15 19:22
標(biāo)題: GY-26電子指南針資料(串口+IIC+溫度源程序)
如題 我只想下個(gè)別的資料但是積分不夠,程序有51單片機(jī)版本的和pic單片機(jī)的


所有資料51hei提供下載:
GY-26電子指南針模塊電子羅盤模塊+機(jī)器人配件送資料.rar (628.2 KB, 下載次數(shù): 50)

單片機(jī)源程序如下:
  1. //  GY-26電子指南針模塊測(cè)試程序
  2. //  使用單片機(jī):STC89C52
  3. //  晶振:  11.0592 M
  4. //  液晶屏:LCD1602
  5. #include<REG52.H>       
  6. #include<math.h>       //Keil library  
  7. #include<stdio.h>      //Keil library       
  8. #include<INTRINS.H>
  9. #define uchar unsigned char
  10. #define uint  unsigned int       
  11. #define DataPort P0           //LCD1602 數(shù)據(jù)端口       
  12. sbit    LCM_RS=P2^0;   //LCD1602 控制端口               
  13. sbit    LCM_RW=P2^1;   //LCD1602 控制端口       
  14. sbit    LCM_EN=P2^2;   //LCD1602 控制端口
  15. sbit    KEY_1 =P2^6;
  16. sbit    KEY_2 =P2^5;
  17. sbit    KEY_3 =P2^4;
  18. sbit    KEY_4 =P2^3;       
  19. //********定義變量*****************************
  20. uchar   BUF[8];        //數(shù)據(jù)緩存區(qū)
  21. uchar   cnt;           //接收數(shù)據(jù)的累計(jì)值
  22. //********定義函數(shù)*****************************
  23. void    delay(unsigned int k);
  24. void    InitLcd();
  25. void    WriteDataLCM(uchar dataW);
  26. void    WriteCommandLCM(uchar CMD,uchar Attribc);
  27. void    DisplayOneChar(uchar X,uchar Y,uchar DData);
  28. void    SeriPushSend(uchar send_data);
  29. void    ReadKey(void);
  30. void         display(void);
  31. //*********************************************
  32. //串口中斷
  33. void serial_serve(void) interrupt 4       
  34. {
  35.   if(RI==1){
  36.     RI=0;
  37.     BUF[cnt]=SBUF;
  38.         cnt++;
  39. //        if(cnt==7)flag=1;
  40.   }
  41. }
  42. //*********************************************
  43. //串口初始化
  44. //9600 bps @ 11.059 MHz
  45. void init_uart()
  46. {
  47.         TMOD=0x21;                               
  48.         TH1=0xfd;                               
  49.         TL1=0xfd;                               
  50.         SCON=0x50;
  51.         PS=1;      //串口中斷設(shè)為高優(yōu)先級(jí)別
  52.         TR0=1;           //啟動(dòng)定時(shí)器                       
  53.         TR1=1;
  54.         ET0=1;     //打開(kāi)定時(shí)器0中斷                       
  55.         ES=1;       
  56. }
  57. //*********LCD1602初始化**********************
  58. void InitLcd()                               
  59. {                       
  60.         WriteCommandLCM(0x38,1);       
  61.         WriteCommandLCM(0x08,1);       
  62.         WriteCommandLCM(0x01,1);
  63.         WriteCommandLCM(0x06,1);       
  64.         WriteCommandLCM(0x0c,1);
  65. }
  66. //**********檢測(cè)忙信號(hào)************************
  67. void WaitForEnable(void)       
  68. {                                       
  69.         DataPort=0xff;               
  70.         LCM_RS=0;LCM_RW=1;_nop_();
  71.         LCM_EN=1;_nop_();_nop_();
  72.         while(DataPort&0x80);       
  73.         LCM_EN=0;                               
  74. }                                       
  75. //**********寫命令至LCD***********************
  76. void WriteCommandLCM(uchar CMD,uchar Attribc)
  77. {                                       
  78.         if(Attribc)WaitForEnable();       
  79.         LCM_RS=0;LCM_RW=0;_nop_();
  80.         DataPort=CMD;_nop_();       
  81.         LCM_EN=1;_nop_();_nop_();LCM_EN=0;
  82. }                                       
  83. //**********寫數(shù)據(jù)至LCD************************
  84. void WriteDataLCM(uchar dataW)
  85. {                                       
  86.         WaitForEnable();               
  87.         LCM_RS=1;LCM_RW=0;_nop_();
  88.         DataPort=dataW;_nop_();       
  89.         LCM_EN=1;_nop_();_nop_();LCM_EN=0;
  90. }                                       
  91. //*********寫一個(gè)字符數(shù)據(jù)到指定的目標(biāo)***********
  92. void DisplayOneChar(uchar X,uchar Y,uchar DData)
  93. {                                               
  94.         Y&=1;                                               
  95.         X&=15;                                               
  96.         if(Y)X|=0x40;                                       
  97.         X|=0x80;                       
  98.         WriteCommandLCM(X,0);               
  99.         WriteDataLCM(DData);               
  100. }
  101. //**********延時(shí)函數(shù)***************
  102. void delay(unsigned int k)       
  103. {                                               
  104.         unsigned int i,j;                               
  105.         for(i=0;i<k;i++)
  106.         {                       
  107.         for(j=0;j<121;j++)                       
  108.         {;}
  109.         }                                               
  110. }                                                           
  111. //*********串口數(shù)據(jù)發(fā)送******************
  112. void  SeriPushSend(uchar send_data)
  113. {
  114.     SBUF=send_data;  
  115.         while(!TI);TI=0;          
  116. }
  117. //*********按鍵檢測(cè)**********************
  118. void ReadKey(void)
  119. {

  120.     EA=0;
  121.     if(KEY_1==0){
  122.        delay(50);
  123.        if(KEY_1==0){
  124.        SeriPushSend(0XC0);                                    //發(fā)送校準(zhǔn)命令。
  125.            display();
  126.        while(KEY_1==0);                                       //等待按鍵放開(kāi)
  127.        }
  128.     }
  129.     if(KEY_2==0){
  130.        delay(50);
  131.        if(KEY_2==0){
  132.        SeriPushSend(0XC1);                                    //發(fā)送停止校準(zhǔn)命令。
  133.            display();
  134.        while(KEY_2==0);                                       //等待按鍵放開(kāi)
  135.        }
  136.     }
  137.     if(KEY_3==0){
  138.        delay(50);
  139.        if(KEY_3==0){
  140.        SeriPushSend(0XA0);                                    //發(fā)送恢復(fù)出廠命令。
  141.            display();
  142.        SeriPushSend(0XAA);                                    //發(fā)送恢復(fù)出廠命令。
  143.            display();
  144.        SeriPushSend(0XA5);                                    //發(fā)送恢復(fù)出廠命令。
  145.            display();
  146.        SeriPushSend(0XC5);                                    //發(fā)送恢復(fù)出廠命令。
  147.            display();
  148.        while(KEY_3==0);                                       //等待按鍵放開(kāi)
  149.        }
  150.     }

  151.     if(KEY_4==0){
  152.        delay(50);
  153.        if(KEY_4==0){
  154.        SeriPushSend(0X3);                                    //發(fā)送設(shè)定磁偏角高8位命令。
  155.            display();
  156.        SeriPushSend(0X0);                                    //發(fā)送磁偏角高8位的數(shù)據(jù)。
  157.            display();
  158.        SeriPushSend(0X4);                                    //發(fā)送設(shè)定磁偏角低8位命令
  159.            display();
  160.        SeriPushSend(0X64);                                   //發(fā)送磁偏角低8位的數(shù)據(jù)。此時(shí)磁偏角被設(shè)定為10.0度
  161.            display();
  162.        while(KEY_4==0);                                       //等待按鍵放開(kāi)
  163.        }
  164.     }
  165. /*
  166.     if(KEY_5==0){
  167.        delay(50);
  168.        if(KEY_4==0){
  169.        SeriPushSend(0XAE);                                    //發(fā)送當(dāng)前角度為0度命令。
  170.            display();
  171.        while(KEY_4==0);                                       //等待按鍵放開(kāi)
  172.        }
  173.     }
  174. */

  175.     EA=1;

  176. }
  177. //*******************數(shù)據(jù)接收并顯示**********************
  178. void display(void)
  179. {
  180.     uchar SUM;
  181.     uint   i ;
  182.    for (i=0;i<3000;i++);                                      //傳送數(shù)據(jù)延時(shí)
  183.           if(BUF[0]==0X0D&&BUF[1]==0X0A){                         //幀頭判斷
  184.         SUM=BUF[6]+BUF[5]+BUF[4]+BUF[3]+BUF[2]+BUF[1]+BUF[0]; //校驗(yàn)和
  185.                if (BUF[7]==SUM){                                     //校驗(yàn)和判斷
  186.           DisplayOneChar(0,0,BUF[2]);                         //角度百位值 寫入LCD,因?yàn)槭亲址愋停圆挥棉D(zhuǎn)換,直接顯示
  187.           DisplayOneChar(1,0,BUF[3]);                         //角度十位值 寫入LCD
  188. ……………………

  189. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼









作者: highwest    時(shí)間: 2019-4-3 15:37
謝謝分享~~




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1