c语言单片机中断服务程序

#include <reg52.h>

#define uchar unsigned char
#define uint  unsigned int

uint count;
void delay(uint z)
{
    uint x,y;
    for(x = z; x > 0; x--)
        for(y = 114; y > 0 ; y--);
}

/*中断服务特殊功能寄存器配置*/    
void init()
{
    
    TMOD = 0x01;  //定时器16为计数工作模式
    TH0 =0x4b;
    TL0 =0xfd; //50ms
    ET0 = 1; //开定时器0中断
    TR0 = 1;//启动定时器0

    EA = 1;    //开总中断

    IT0 = 0; //t0低电平触发模式,1位跳边沿触发模式
    EX0 = 1; //开T0中断
}

void main()
{
    init();
    while(1)
    {
        P1 = 0xff;//流水灯全灭
        //delay(2000);
    }
}

/*中断服务程序*/
void timer0() interrupt 1
{
    count++;
    if (count == 80)
    {
        P1 = 0; //流水灯全亮
        delay(2000);
        count = 0;    
    }
}
void int0() interrupt 0
{
    P1 = 0;//流水灯全亮    
}

1,短接单片机to脚与GND脚,TO外部中断点亮流水灯

2,定时器模式每80*50ms进入一次计时器一中断模式

原文地址:https://www.cnblogs.com/cerofang/p/8368799.html