⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t01led.c

📁 可以熟悉51单片机中断机制 大大方便学习51单片机
💻 C
字号:
/*******************************************************************************
* P2.0 P2.1  LED显示  流水灯 (双定时中断				               *
********************************************************************************
*  日期:  2008-2-25                                                            *
*  版本:  3.0                                                                  *
*  作者:  深圳志博电子有限公司     专业8051单片机教学站                        *
*  邮箱: zty0012001@163.com                                                       *
*  网站: http://www.elecmcu.com     http://www.elecmcu.com    更多例程请登陆网站   *
********************************************************************************
*  硬件:此程序在本公司志博电子实验仪运行通过                           *
********************************************************************************/	
#include < reg51.h >
#include <intrins.h>
#define uchar unsigned char
#define uint  unsigned int
sbit led_0=P2^0;
sbit led_1=P2^1;
uchar time0count,time1count,move1,move2;
/*********************************************************
  主函数
**********************************************************/
void  main()
{
    P2=0xff;
    TMOD=0x11;   //定时/计数器1工作于方式1
    TH0=0xa6;
    TL0=0x00;    //25ms定时常数
    TH1=0x4c;
    TL1=0x00;    //50ms定时常数
    PT0=1;       //定义TIMER0优先
    EA=1;        //开总中断
    ET0=1;       //允许定时/计数器0 中断
    ET1=1;       //允许定时/计数器1 中断
    TR0=1;       //启动定时/计数器0 中断
    TR1=1;       //启动定时/计数器1 中断
    move1=0xfe;
    move2=0xfe;
    while(1);
}
/*********************************************************
  TIMER0中断服务函数
**********************************************************/
void Time0(void) interrupt 1 
{
   TH0=0xa6;               //25ms定时
   TL0=0x00;
   time0count++;
   if(time0count==100)
   {
     time0count=0; 
     led_0=!led_0; 
   }
}
/*********************************************************
  TIMER1中断服务函数
**********************************************************/
void Time1(void) interrupt 3 
{
   TH1=0x4c;               //50ms定时
   TL1=0x00;
   time1count++;
   if(time1count==100)
   {
     time1count=0;
     led_1=!led_1; 
   }
}
/*********************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -