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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1500|回復: 4
打印 上一主題 下一主題
收起左側

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

[復制鏈接]
跳轉到指定樓層
樓主
#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;             //發送端設為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;                //在發送或接受才開始使用
        TF0 = 0;                                                       
        ET0 = 1;                //允許允許定時器0中斷
        EA=1;                        //中斷允許
}

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

                        //發送校驗位(無)

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

void Sendata()
{
     for(i=0;i<sizeof(zhiling);i++)//外層循環,遍歷數組
    {
          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空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

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

使用道具 舉報

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

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

使用道具 舉報

地板
ID:155507 發表于 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;             //發送端設為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;                //在發送或接受才開始使用
  28.         TF0 = 0;                                                        
  29.         ET0 = 1;                //允許允許定時器0中斷
  30.         EA=1;                        //中斷允許
  31. }

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

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

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

  47. void Sendata()
  48. {
  49.      for(i=0;i<sizeof(zhiling);i++)//外層循環,遍歷數組
  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 發表于 2018-8-23 09:07 | 只看該作者
angmall 發表于 2018-8-22 15:45
給你改了一下試試。

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

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

微信圖片_20180823090537.jpg
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表