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

📄 liushui.c

📁 ME500——51单片机的几个中断程序
💻 C
字号:
/*******************************************************************/
/*                                                                 */
/* ME500单片机开发系统演示程序 - 流水灯 (双定时中断)             */
/*                                                                 */
/* P0、P2 LED显示                                                  */
/*                                                                 */
/* 版本: V1.0 (2006/11/20)                                        */
/* 作者: gguoqing (Email: gguoqing@willar.com)                    */
/* 网站: www.willar.com(伟纳电子)   www.mcusj.com(伟纳单片机世界) */
/* 邮箱: support@willar.com                                       */
/*                                                                 */
/*【版权】Copyright(C)伟纳电子 www.willar.com  All Rights Reserved */
/*【声明】此程序仅用于学习与参考,引用请注明版权和作者信息!       */
/*                                                                 */
/*******************************************************************/
	
#include < reg51.h >
#include <intrins.h>

#define uchar unsigned char
#define uint  unsigned int
uchar time0count,time1count,move1,move2;

/*********************************************************

  主函数

**********************************************************/
void  main()
{
    P0=0xff;     //关所有灯
    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==10)
   {
     time0count=0;
	 P0=move1;     
	 move1=(move1 <<1)|0x01;
     if(move1==0xff)
     move1=0xfe;
   }
}

/*********************************************************

  TIMER1中断服务函数

**********************************************************/
void Time1(void) interrupt 3 
{
   TH1=0x4c;               //50ms定时
   TL1=0x00;
   time1count++;
   if(time1count==10)
   {
     time1count=0;
     P2=move2;
	 move2=(move2 <<1)|0x01;
     if(move2==0xff)
     move2=0xfe;
   }
}

/*********************************************************/

⌨️ 快捷键说明

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