/***************************************************
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;
}
}