標(biāo)題: 8255A方式0的PAPB驅(qū)動(dòng)荔枝 [打印本頁]

作者: xianfajushi    時(shí)間: 2024-7-2 07:40
標(biāo)題: 8255A方式0的PAPB驅(qū)動(dòng)荔枝
這個(gè)荔枝隨意拿個(gè)程序添加而成,前些天回復(fù)16按鍵對(duì)應(yīng)16LED的,這個(gè)8255標(biāo)題看代碼和電路圖關(guān)注與8255A有關(guān)的部分即可.
  1. #include "reg52.h"
  2. sbit A08255=P2^5;
  3. sbit CS8255=P2^6;
  4. void main()
  5. {//緣由http://www.torrancerestoration.com/bbs/dpj-236599-1.html
  6.         unsigned char sy=0,ys=0,my=0,ls=0,a=0,n=0,f=1;
  7.         A08255=f;
  8.         while(1)
  9.         {//模擬16按鍵,仿真圖上放置一片AT89C52芯片,//什么電路都不接LED、按鍵也沒有,就能仿真驗(yàn)證程序。
  10.                 if(++sy==0)if(++ys>47)
  11.                 {ys=0;
  12.                         if(a<128)
  13.                         {
  14.                                 if(a)a*=2;
  15.                                 else {a=1;A08255=f%2;}
  16.                                 CS8255=1;
  17.                                 P1=255-a;
  18.                                 CS8255=0;
  19.                         }
  20.                         else
  21.                         {
  22.                                 P1=255;
  23.                                 if(n<128)if(n)n*=2;
  24.                                 else n=1;
  25.                                 else {a=n=0;P3=255;++f;}
  26.                                 P3=255-n;
  27.                         }
  28.                 }
  29.                 if(P1!=255&&++my==0){ls=P1;P0=ls;}//P2=255;
  30.                 if(P3!=255&&++my==0){ls=P3;P2=ls;P0=255;}
  31.                 if(P1==255&&P3==255)my=0;//按鍵消抖綜合
  32.         }
  33. }
復(fù)制代碼









歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1