專注電子技術(shù)學習與研究
當前位置:單片機教程網(wǎng) >> MCU設計實例 >> 瀏覽文章

單片機程序-利用C52庫函數(shù)實現(xiàn)左右流水燈

作者:寒竹子   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2014年03月21日   【字體:

本程序所用的原理圖下載: 點這里 ,單片機芯片使用的stc89c52;找到流水燈部分的原理圖即可.這是一整個單片機開發(fā)板的電路圖其他的忽略

下面是程序源代碼:
/***********左右流水燈**************/
/**
*功能:利用C52庫函數(shù)實現(xiàn)左右流水燈
*    方法一:goto 語句實現(xiàn)之
*    方法二: 順序?qū)崿F(xiàn)之
*    方法三: 順序和goto語句實現(xiàn)之
*日期:2013-06-16-09:00-09:40
*備注:程序已通過調(diào)試
**/
/*********AT89C52-RC MCU*************/
/***********HL-1 開發(fā)板***********/
#include <reg52.h>
#include <intrins.h>
typedef unsigned int uint;
typedef unsigned char uchar;
void delay(uint xms)
{
 uint x, y;
 for(x = xms; x > 0; x--)
   for(y = 110; y > 0; y--);
}
/**********方法1************/
/*
void main(void)
{
 
 uchar temp, temp1, i;
 /******流水燈向左流動********/
 /*
loop1: while(1)
  {
   P1 = 0xfe;
   for(i = 0; i < 7; i++)
   {
    temp = P1;
    temp = _crol_(temp, 1);
    P1 = temp;
    delay(200);
   }
   goto loop;
  }
   /******流水燈向右流動********/
   /*
loop: while(1)
  {
   P1 = 0x7f;
   for(i = 0; i < 7; i++)
   {
    temp1 = P1;
    temp1 = cror_(temp1, 1);
    P1 = temp1;
    delay(200);
   }
   goto loop1;
  }
}
 */
/**********方法2************/
/*
void main(void)
{
 uchar temp, i;
 P1 = 0xfe;
 while(1)
 {
  P1 = 0xfe;
  temp = P1;
 /******流水燈向左流動********/
 /*
  for(i = 0; i < 7; i++)
  {
   temp = _crol_(temp, 1);
   P1 = temp;
   delay(200);
  }
 /******流水燈向右流動********/
  /*
  P1 = 0x7f;
  temp = P1;
  for(i = 0; i < 7; i++)
  {
   temp = _cror_(temp, 1);
   P1 = temp;
   delay(200);
  }
 }
}
*/
/**********方法3***********/
void main(void)
{
 uchar temp, i;
 while(1)
 {
  P1 = 0xfe;
  temp = P1;
 /******流水燈向左流動********/
  for(i = 0; i < 7; i++)
  {
   temp = _crol_(temp, 1);
   P1 = temp;
   delay(200);
   if(i >= 7)
   goto loop;
  }
 /******流水燈向右流動********/
loop: P1 = 0x7f;
  temp = P1;
  for(i = 0; i < 7; i++)
  {
   temp = _cror_(temp, 1);
   P1 = temp;
   delay(200);
  }
 }
}
 

關閉窗口

相關文章