<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ARM學(xué)習(xí)1-LED流水燈

          ARM學(xué)習(xí)1-LED流水燈

          作者: 時(shí)間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
          通過近段時(shí)間的不懈努力終于找到一個(gè)可以用來編譯ARM 的Keil ,再利用Protuse軟件進(jìn)行模擬仿真。 開始了我的ARM學(xué)習(xí)之路……

          本實(shí)例是我學(xué)習(xí)ARM的第一個(gè)實(shí)例,仿真軟件是利用的是Porteus,編譯軟件用的是Keil的RealView.MDK.3.2。

          本文引用地址:http://www.ex-cimer.com/article/201611/317360.htm

          本程序是花樣流水。一共有三個(gè)花樣,可以通過按鍵選擇不同的花樣。通過此程序?qū)W習(xí)了ARM GPIO的處理和按鍵處理。

          原理圖:

          程序代碼:

          /*********************************************/
          /* */
          /* led.c: 花樣流水 */
          /* */
          /*********************************************/

          #include

          #define KEY 0x00010000 // P0.16引腳連接按鍵

          unsigned char Count;

          /*********************************************
          **函 數(shù) 名: delay()
          **描 述: 軟件延時(shí)
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          void delay (unsigned char num)
          {
          unsigned char i;
          unsigned volatile long j;

          for(i=0;i{
          for(j=0;j<60000;j++)
          {
          ;
          }
          }
          }
          /*********************************************
          **函 數(shù) 名: init()
          **描 述: 初始化
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          void init(void)
          {
          PINSEL0 = 0;// 設(shè)置低16引腳為GPIO
          IO0DIR = 0x000000FF;// 將P0低8位設(shè)置為輸出
          IO0SET = 0x000000FF;// 將P0低8位置1,也就是讓led滅
          Count = 0;
          }
          /*********************************************
          **函 數(shù) 名: light_one_by_one()
          **描 述: 逐個(gè)點(diǎn)亮
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          void light_one_by_one(void)
          {
          unsigned char i;
          unsigned volatile long tem;

          tem = 0x01;

          for (i=0; i<8; i++)
          {
          IO0CLR = tem;
          delay(5);
          tem <<= 1;
          }

          IO0SET = 0x000000FF; // 關(guān)閉所有燈
          delay(5);
          }

          /*********************************************
          **函 數(shù) 名: light_interval()
          **描 述: 間隔點(diǎn)亮
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          void light_interval(void)
          {
          unsigned char i;

          for (i=0; i<4; i++)
          {
          IO0SET = 0x00000055;
          IO0CLR = 0x000000aa;
          delay(5);

          IO0SET = 0x000000aa;
          IO0CLR = 0x00000055;
          delay(5);
          }
          }

          /*********************************************
          **函 數(shù) 名: light_single()
          **描 述: 單個(gè)點(diǎn)亮
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          void light_single(void)
          {
          unsigned char i;
          unsigned volatile long tem;

          tem = 0x01;

          for (i=0; i<8; i++)
          {
          IO0SET = 0x000000FF;
          IO0CLR = tem;
          delay(5);
          tem <<= 1;
          }

          IO0SET = 0x000000FF;
          delay(5);
          }
          /*********************************************
          **函 數(shù) 名: WaitKey()
          **描 述: 按鍵處理
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          void WaitKey(void)
          {

          if ((IO0PIN&KEY)==0) // 如果有鍵按下
          {
          delay(1); // 延時(shí)消抖

          if ((IO0PIN&KEY)==0) // 再次判斷
          {
          Count++; // 有鍵按下,計(jì)數(shù)器加1
          }

          if (Count >= 3)
          {
          Count = 0;
          }

          while ((IO0PIN&KEY)==0); // 等待按鍵釋放
          }
          }

          /*********************************************
          **函 數(shù) 名: main()
          **描 述: 主函數(shù)
          **參數(shù)說明:無
          **返 回 值:無
          **********************************************/
          int main(void)
          {
          init();

          while (1)
          {
          WaitKey();

          switch (Count)
          {
          case 0: light_one_by_one();break; // 逐個(gè)點(diǎn)亮
          case 1:light_interval();break; // 間隔點(diǎn)亮
          case 2: light_single();break; // 單個(gè)點(diǎn)亮
          default: break;
          }
          }
          }



          關(guān)鍵詞: ARMLED流水

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();