89C51單片機定時器控制的流水燈


/***************************************************
Copyright: 2014-02-11.version1.0
File name: timer.c
Description: 定時中斷控制的流水燈
Author: lxl
Version: version1.0
Date: 2014.02.11
History: 無
****************************************************/
#include <reg51.h>
char a=0xff;
int num=0;
/*************************************************
Function: init()
Description: 定時中斷初始化功能
Calls: 無
Called By: main()
Table Accessed: 無
Table Updated: 無
Input: void
Output: 無
Return: void
Others: 無
*************************************************/
void init(void)
{
 TMOD=0x01;
 EA=1;
 ET0=1; 
 TH0=(65536-50000)/256;
 TL0=(65536-50000)%256;
 TR0=1;
}
/*************************************************
Function: main()
Description: 程序的主函數
Calls: init()
Called By: 無
Table Accessed: 無
Table Updated: 無
Input: void
Output: 無
Return: void
Others: 無
*************************************************/
void main(void)
{
 init();
 while(1)
 {
  P1=a;
 }
}
void tr() interrupt 1
{
 TH0=(65536-50000)/256;
 TL0=(65536-50000)%256;
 num++;
 if(num==20)
 {
  num=0;
  a--;
  if(a==0x00)
   a=0xff;
 } 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM