久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1516|回復: 4
打印 上一主題 下一主題
收起左側(cè)

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

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:381738 發(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 code zhiling[ ]={0xDD,0xA5,0x03,0x00,0xFF,0xFD,0x77};

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

void Delayxms(unsigned char i)
{
while(--i)
{
_nop_();
}
}



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

void WByte(uint input)
{
                         //發(fā)送啟始位
     uchar j=8;
     newTXD=(bit)0;               //發(fā)送8位數(shù)據(jù)位
     while(j--)
     {
         newTXD=(bit)(input&0x01);      //先傳低位
         input=input>>1;
     }

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

                        //發(fā)送結束位
    newTXD=(bit)1;
}   

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

void display()
{
display_graphic_16x16(1,1,0,zong16);
display_graphic_16x16(1,17,0,dian16);
display_graphic_16x16(1,33,0,ya16);  
display_string_8x16(1,49,0,":");   //總電壓
display_graphic_16x16(3,1,0,zong16);
display_graphic_16x16(3,17,0,dian16);
display_graphic_16x16(3,33,0,liu16);  
display_string_8x16(3,49,0,":");    //總電流
display_graphic_16x16(5,1,0,sheng16);
display_graphic_16x16(5,17,0,yu16);
display_graphic_16x16(5,33,0,dian16);
display_graphic_16x16(5,49,0,liang16);   
display_string_8x16(5,65,0,":");     //剩余電量
display_graphic_16x16(7,1,0,dian16);
display_graphic_16x16(7,17,0,chi16);
display_graphic_16x16(7,33,0,wen16);
display_graphic_16x16(7,49,0,du16);
display_string_8x16(7,65,0,":");     //電池溫度
}

void main()
{
     UartInit();
     while(1)
     {
          Sendata();
     }
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:379392 發(fā)表于 2018-8-22 11:28 | 只看該作者
第8行 int i ; 應該是uint i;另外i是不是重復定義了  程序不全 display()子程序沒用到 而且主程序前面的子程序不需要聲明
回復

使用道具 舉報

板凳
ID:381738 發(fā)表于 2018-8-22 13:47 | 只看該作者
santo 發(fā)表于 2018-8-22 11:28
第8行 int i ; 應該是uint i;另外i是不是重復定義了  程序不全 display()子程序沒用到 而且主程序前面 ...

問題是我設置的是波特率9600,按理說應該是104微秒一位,實際情況并不是,示波器上波形很密集,還有就是按照通訊協(xié)議發(fā)送的指令,然而沒有得到回復,是兩個單片機之間的通訊,用的io模擬串口,這個是通訊盒上的程序
回復

使用道具 舉報

地板
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ā)送端設為P4.1
  15. sbit newRXD = P4^2;             //接收端設為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ā)送結束位
  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. }
復制代碼
回復

使用道具 舉報

5#
ID:381738 發(fā)表于 2018-8-23 09:07 | 只看該作者
angmall 發(fā)表于 2018-8-22 15:45
給你改了一下試試。

感謝,調(diào)試了一下,看了下波形圖感覺還是怪怪的,模擬串口發(fā)送程序的話是不是只要調(diào)波特率和延時就行了?附上波形圖

微信圖片_20180823090537.jpg (100.41 KB, 下載次數(shù): 15)

微信圖片_20180823090537.jpg
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美一级在线观看 | 欧美日韩淫片 | 密室大逃脱第六季大神版在线观看 | a级黄色片在线观看 | 精品网 | 中文字幕久久久 | 久久久www成人免费无遮挡大片 | 日韩视频在线播放 | 免费视频一区二区 | 国产一区精品 | 亚洲国产成人精品一区二区 | 亚洲网站在线观看 | av中文网 | 亚洲国产精品一区二区www | 91.com视频| 精品乱码一区二区 | 精品91av| av午夜激情| 午夜激情影院 | 国产成人精品综合 | 无毛av| 日日噜噜噜夜夜爽爽狠狠视频, | 在线欧美视频 | 亚洲欧美日韩在线不卡 | 日韩欧美操 | 欧美精品一区二区免费 | 亚洲天堂av网 | 久久大全 | 欧美日韩一区精品 | 国产日韩久久 | 亚洲天堂成人在线视频 | 亚洲成a人片 | 国产精品久久久久一区二区三区 | 中文字幕福利视频 | 爱操av| 日韩中文字幕 | 日韩欧美1区2区 | 成人一区精品 | 亚洲国产精品久久久 | 福利一区在线观看 | 久久久久久国产精品三区 |