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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索

請教一下論壇里的大神i能不能幫我看看我代碼錯在哪兒

查看數(shù): 1505 | 評論數(shù): 4 | 收藏 0
關(guān)燈 | 提示:支持鍵盤翻頁<-左 右->
    組圖打開中,請稍候......
發(fā)布時間: 2018-8-22 09:31

正文摘要:

#include "stc15f2k60s2.h" #include "lcd.h" #include <stdio.h> #include <string.h> #include "intrins.h" #define uint unsigned int #define uchar unsigned char int i; uint c ...

回復(fù)

ID:155507 發(fā)表于 2018-8-22 15:45
給你改了一下試試。

  1. #include "stc15f2k60s2.h"
  2. #include "lcd.h"
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "intrins.h"
  6. #define uint unsigned int
  7. #define uchar unsigned char
  8. int i;

  9. uint code zhiling[ ]={0xDD,0xA5,0x03,0x00,0xFF,0xFD,0x77};

  10. char xdata char_U[50];                        //總電壓
  11. char xdata char_I[50];                        //總電流
  12. char xdata char_EXT[50];                //電池溫度
  13. void display();                                        //屏幕顯示
  14. sbit newTXD = P4^1;             //發(fā)送端設(shè)為P4.1
  15. sbit newRXD = P4^2;             //接收端設(shè)為p4.2

  16. void Delayxms(unsigned char i)
  17. {
  18. while(--i)
  19. {
  20. _nop_();
  21. }
  22. }



  23. void UartInit()                 //串口初始化
  24. {TMOD= 0x02;           //定時器0方式2
  25.         TH0 = 0xFD;           //9600波特率
  26.         TL0 = TH0;
  27.         TR0 = 0;                //在發(fā)送或接受才開始使用
  28.         TF0 = 0;                                                        
  29.         ET0 = 1;                //允許允許定時器0中斷
  30.         EA=1;                        //中斷允許
  31. }

  32. void WByte(uint input)
  33. {
  34.                          //發(fā)送啟始位
  35.      uchar j=8;
  36.      newTXD=(bit)0;               //發(fā)送8位數(shù)據(jù)位
  37.      while(j--)
  38.      {
  39.          newTXD=(bit)(input&0x01);      //先傳低位
  40.          input=input>>1;
  41.          Delayxms(96);  //延時 104us
  42.      }

  43.                         //發(fā)送校驗位(無)

  44.                         //發(fā)送結(jié)束位
  45.     newTXD=(bit)1;
  46. }   

  47. void Sendata()
  48. {
  49.      for(i=0;i<sizeof(zhiling);i++)//外層循環(huán),遍歷數(shù)組
  50.     {
  51.           WByte(zhiling[i]);
  52.      }
  53. }

  54. /*
  55. void display()
  56. {
  57. display_graphic_16x16(1,1,0,zong16);
  58. display_graphic_16x16(1,17,0,dian16);
  59. display_graphic_16x16(1,33,0,ya16);  
  60. display_string_8x16(1,49,0,":");   //總電壓
  61. display_graphic_16x16(3,1,0,zong16);
  62. display_graphic_16x16(3,17,0,dian16);
  63. display_graphic_16x16(3,33,0,liu16);  
  64. display_string_8x16(3,49,0,":");    //總電流
  65. display_graphic_16x16(5,1,0,sheng16);
  66. display_graphic_16x16(5,17,0,yu16);
  67. display_graphic_16x16(5,33,0,dian16);
  68. display_graphic_16x16(5,49,0,liang16);   
  69. display_string_8x16(5,65,0,":");     //剩余電量
  70. display_graphic_16x16(7,1,0,dian16);
  71. display_graphic_16x16(7,17,0,chi16);
  72. display_graphic_16x16(7,33,0,wen16);
  73. display_graphic_16x16(7,49,0,du16);
  74. display_string_8x16(7,65,0,":");     //電池溫度
  75. }
  76. */

  77. void main()
  78. {
  79.      UartInit();
  80.      while(1)
  81.      {
  82.           Sendata();
  83.      }
  84. }
復(fù)制代碼
ID:381738 發(fā)表于 2018-8-22 13:47
santo 發(fā)表于 2018-8-22 11:28
第8行 int i ; 應(yīng)該是uint i;另外i是不是重復(fù)定義了  程序不全 display()子程序沒用到 而且主程序前面 ...

問題是我設(shè)置的是波特率9600,按理說應(yīng)該是104微秒一位,實際情況并不是,示波器上波形很密集,還有就是按照通訊協(xié)議發(fā)送的指令,然而沒有得到回復(fù),是兩個單片機之間的通訊,用的io模擬串口,這個是通訊盒上的程序
ID:379392 發(fā)表于 2018-8-22 11:28
第8行 int i ; 應(yīng)該是uint i;另外i是不是重復(fù)定義了  程序不全 display()子程序沒用到 而且主程序前面的子程序不需要聲明

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表