找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2478|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)程序?qū)慿eil里面沒有報(bào)錯(cuò),生成hex文件就放在proteus里面,就是仿真不出來怎...

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
這個(gè)就是模擬仿真控制電壓輸出波形的一個(gè)程序,用原先的hex文件是可以運(yùn)行的,但是后面重新生成的hex文件放到仿真當(dāng)中就沒有用了,請問是怎么回事,有什么解決方法嗎
程序及仿真圖如下:


單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #include <intrins.h>
  3. #define _nop_  _nop_()
  4. #define uchar unsigned char
  5. #define uint unsigned int
  6. uchar a,flang;

  7. sbit U3CS=P2^4;        //DA引腳
  8. sbit U3WR=P2^5;
  9. sbit U2CS=P2^6;
  10. sbit U2WR=P2^7;
  11. sbit fudu_up=P1^2;        //幅度
  12. sbit fudu_dn=P1^3;        //幅度
  13. sbit L1=P2^0;
  14. sbit L2=P2^1;

  15. bit flag;
  16. uchar n=25;//幅度初始2.5v

  17. unsigned char code ledcode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
  18.                                0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};        // 數(shù)碼管編碼
  19. uchar jj;
  20. uchar k;
  21. uint dingshi=0;
  22. uint SET_PL=50;
  23. uchar Tempho,Templo;
  24. uchar display_data[8];// 顯示緩存                                                                                          
  25. void set_time();
  26. void timetoseg();  //數(shù)據(jù)轉(zhuǎn)換成段碼
  27. void delay(uint z)
  28. {
  29.    uint a,b;
  30.    for(a=z;a>0;a--)
  31.      for(b=20;b>0;b--);
  32. }
  33. void init()// 定時(shí)器初始化
  34. {
  35.         TMOD=0x01;
  36.   EA=1;
  37.         TR0=1;
  38.         ET0=1;
  39. }
  40. void key()
  41. {
  42.    if(fudu_up==0)//幅度控制
  43.     { delay(1);
  44.      if(fudu_up==0)
  45.       {      
  46.        n++;if(n==50)n=0;
  47.        P3=0XFF;
  48.        U3CS=1;_nop_;_nop_;//數(shù)據(jù)鎖存                        
  49.        P3=n*5.1;//數(shù)據(jù)讀入 幅度按一次0.1                                
  50.        U2CS=0;_nop_;_nop_; //數(shù)據(jù)寫入弧度控制DA
  51.        U2CS=1;//DA數(shù)據(jù)鎖存
  52.        U3CS=0;//恢復(fù)數(shù)據(jù)輸出
  53.                          while(fudu_up==0);
  54.        }                  
  55.      }
  56.                 if(fudu_dn==0)//幅度控制-
  57.     { delay(1);
  58.      if(fudu_dn==0)
  59.       {
  60.                          if(n>2)n--;
  61.                                 else  n=1;                        
  62.        P3=0XFF;
  63.        U3CS=1;_nop_;_nop_;//數(shù)據(jù)鎖存                        
  64.        P3=n*5.1;//數(shù)據(jù)讀入 幅度按一次0.1                                
  65.        U2CS=0;_nop_;_nop_; //數(shù)據(jù)寫入弧度控制DA
  66.        U2CS=1;//DA數(shù)據(jù)鎖存
  67.        U3CS=0;//恢復(fù)數(shù)據(jù)輸出
  68.                          while(fudu_dn==0);
  69.        }                  
  70.      }   
  71. }
  72. void set_time()//從新計(jì)算定時(shí)值
  73. {
  74.   dingshi=200;
  75.         Tempho =(65536-dingshi+15)/256;
  76.         Templo =(65536-dingshi+15)%256;
  77.         TH0=Tempho;
  78.         TL0=Templo;
  79. }
  80. void main()
  81. {
  82.    U3WR=0;
  83.    U2WR=0;
  84.    U3CS=1;
  85.    U2CS=1;
  86.     P3=n*5.1;//數(shù)據(jù)讀入 幅度按一次0.1                                
  87.                  U2CS=0;_nop_;_nop_; //數(shù)據(jù)寫入弧度控制DA
  88.                  U2CS=1;//DA數(shù)據(jù)鎖存
  89.                  U3CS=0;//恢復(fù)數(shù)據(jù)輸出
  90.                         flang=1;
  91.       set_time();
  92.                         init();
  93.         while(1)
  94.   {
  95.    key();        
  96.             //數(shù)碼管掃描程序
  97.      //數(shù)據(jù)轉(zhuǎn)換成段碼
  98.                                 P0=ledcode[n/10]&0X7F;//幅度
  99.                                 L1=1;
  100.                           delay(5);
  101.                                 L1=0;               
  102.                           P0=ledcode[n%10];//幅度
  103.                                 L2=1;
  104.                           delay(5);
  105.                                 L2=0;
  106. }               
  107. }
  108. void time0() interrupt 1 //中斷
  109. {  
  110.                  TH0=Tempho;
  111.                         TL0=Templo;        
  112.         if(flag==0)
  113.         {
  114.     a++;        
  115.           if(a==255)
  116.                 {
  117.                 flag=1;
  118.                 }
  119.         }
  120.         else
  121.         {
  122.            a--;        
  123.           if(a==0)
  124.                 {
  125.                  flag=0;
  126.                 }
  127.         }
  128.          P3=a;        // 加載波形碼  
  129. }
復(fù)制代碼


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

使用道具 舉報(bào)

沙發(fā)
ID:342822 發(fā)表于 2022-1-19 13:31 | 只看該作者
仿真完全沒得問題可以運(yùn)行(調(diào)試狀態(tài)和HEX狀態(tài))
回復(fù)

使用道具 舉報(bào)

板凳
ID:968470 發(fā)表于 2022-1-20 10:28 | 只看該作者
taotie 發(fā)表于 2022-1-19 13:31
仿真完全沒得問題可以運(yùn)行(調(diào)試狀態(tài)和HEX狀態(tài))

但是就是我在仿真的時(shí)候,用hex文件仿真的時(shí)候就是沒有效果,之前的hex文件進(jìn)行仿真是沒有問題的,就讓我感到很奇怪
回復(fù)

使用道具 舉報(bào)

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

本版積分規(guī)則

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

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

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