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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
12
返回列表 發(fā)新帖
樓主: small2
打印 上一主題 下一主題
收起左側

為何抄的單片機程序都不成?

  [復制鏈接]
41#
ID:995256 發(fā)表于 2021-12-21 16:06 | 只看該作者
用的系統(tǒng)不一樣,有可能需要改一些數(shù)據(jù)呀
回復

使用道具 舉報

42#
ID:995265 發(fā)表于 2021-12-21 16:08 | 只看該作者
這是根據(jù)博主代碼的強壯性決定的吧
回復

使用道具 舉報

43#
ID:995326 發(fā)表于 2021-12-21 17:48 | 只看該作者
因為抄了咋不懂,而且網(wǎng)上很多都是錯誤的
回復

使用道具 舉報

44#
ID:471297 發(fā)表于 2021-12-21 20:22 | 只看該作者
確實太難了,我改的這個程序就有問題,哪位大神幫我看看吧,P0 P1 P2口接24個LED 循環(huán)亮,顯示就是不正常
  1. #include <REG52.H>

  2. unsigned char RunMode;
  3. //**********************************System Fuction*************************************************
  4. void Delay1ms(unsigned int count)
  5. {
  6.         unsigned int i,j;
  7.         for(i=0;i<count;i++)
  8.         for(j=0;j<120;j++);
  9. }


  10. unsigned char GetKey(void)
  11. {
  12.         unsigned char KeyTemp,CheckValue,Key = 0x00;
  13.         CheckValue = P3&0x32;
  14.         if(CheckValue==0x32)
  15.                 return 0x00;
  16.         
  17.         Delay1ms(10);  //延遲1ms(10)
  18.         KeyTemp = P3&0x32;
  19.         if(KeyTemp==CheckValue)
  20.                 return 0x00;

  21.         if(!(CheckValue&0x02))
  22.                 Key|=0x01;
  23.         if(!(CheckValue&0x10))
  24.                 Key|=0x02;
  25.         if(!(CheckValue&0x20))
  26.                 Key|=0x04;
  27.         return Key;
  28. }

  29. unsigned int TimerCount,SystemSpeed,SystemSpeedIndex;
  30. void InitialTimer2(void)
  31. {
  32.         T2CON  = 0x00;                        //16 Bit Auto-Reload Mode
  33.         TH2 = RCAP2H = 0xFC;          //重裝值,初始值        TL2 = RCAP2L = 0x18;
  34.         ET2=1;                                        //定時器 2 中斷允許
  35.         TR2 = 1;                                //定時器 2 啟動
  36.         EA=1;
  37. }

  38. unsigned int code SpeedCode[]={   1,   2,   3,   5,   8,  10,  14,  17,  20,  30,
  39.                                                              40,  50,  60,  70,  80,  90, 100, 120, 140, 160,
  40.                                                                 180, 200, 300, 400, 500, 600, 700, 800, 900,1000};//30
  41. void SetSpeed(unsigned char Speed)
  42. {
  43.         SystemSpeed =SpeedCode[Speed];
  44. }

  45. void LEDShow(unsigned long LEDStatus)    //修改處
  46. {
  47.         P0 = ~(LEDStatus&0x00FF);
  48.         P1 = ~((LEDStatus>>8)&0x00FF);
  49.         P2 = ~((LEDStatus>>16)&0x00FF);  //修改處
  50. }

  51. void InitialCPU(void)
  52. {
  53.         RunMode = 0x00;
  54.         TimerCount = 0;
  55.         SystemSpeedIndex = 10;

  56.         P0 = 0xFF;
  57.         P1 = 0xFF;
  58.         P2 = 0xFF;
  59.         P3 = 0xFF;
  60.         Delay1ms(500);
  61.         P0 = 0xFF;
  62.         P1 = 0xFF;
  63.         P2 = 0xFF;
  64.         P3 = 0xFF;
  65.         SetSpeed(SystemSpeedIndex);
  66.         
  67. }

  68. //Mode 0
  69. unsigned int LEDIndex = 0;
  70. bit LEDDirection = 1,LEDFlag = 1;

  71. void Mode_0(void)
  72. {
  73.         if(LEDDirection)
  74.                 LEDShow(0x000001<<LEDIndex);   //修改處
  75.         else
  76.                 LEDShow(0x800000>>LEDIndex);   //修改處
  77.         if(LEDIndex==23)                       //修改處                  
  78.                 LEDDirection = !LEDDirection;
  79.    LEDIndex = (LEDIndex+1)%24;                 //修改處              
  80. }

  81. void TimerEventRun(void)
  82. {
  83.         
  84.         if(RunMode ==0x00)
  85.         {
  86.                 Mode_0();
  87.         }

  88. }

  89. void Timer2(void) interrupt 5 using 3
  90. {
  91.         TF2 = 0;         //中斷標志清除( Timer2 必須軟件清標志!)
  92.         if(++TimerCount>=SystemSpeed)
  93.         {
  94.                 TimerCount = 0;
  95.                 TimerEventRun();
  96.            }
  97. }
  98. unsigned char MusicIndex = 0;
  99. void KeyDispose(unsigned char Key)
  100. {
  101.         
  102.         if(Key&0x02)
  103.         {
  104.                 if(SystemSpeedIndex>0)
  105.                 {
  106.                         --SystemSpeedIndex;
  107.                         SetSpeed(SystemSpeedIndex);
  108.                 }
  109.                 else
  110.                 {
  111.                         
  112.                 }
  113.         }
  114.         if(Key&0x04)
  115.         {
  116.                 if(SystemSpeedIndex<28)
  117.                 {
  118.                         ++SystemSpeedIndex;
  119.                         SetSpeed(SystemSpeedIndex);
  120.                 }
  121.                 else
  122.                 {
  123.                         
  124.                 }
  125.         }        
  126. }

  127. //***********************************************************************************
  128. main()
  129. {
  130.         unsigned char Key;
  131.         InitialCPU();
  132.         InitialTimer2();

  133.         while(1)
  134.         {
  135.                 Key = GetKey();
  136.                 if(Key!=0x00)
  137.                 {
  138.                         KeyDispose(Key);
  139.                 }
  140.         }
  141. }
復制代碼
回復

使用道具 舉報

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

本版積分規(guī)則

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

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

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