AVR单片机(ATMEGA16)外部中断程序

来源:互联网 发布:mac os xshell 编辑:程序博客网 时间:2024/05/16 05:54
#include<iom16v.h>#include<macros.h>#define uchar unsigned char#define uint unsigned int#pragma interrupt_handler exter1:3void delay(uint x){ uint y,z; for(y=x;y>0;y--)  for(z=1111;z>0;z--);}void main(void){ uchar i,temp; MCUCR=0x00;   //外部中断低电平触发 //MCUCR=0x08; //外部中断1下降沿触发 GICR=0x80;   //开外部中断1 SREG=0x80;   //开全局中断 DDRB=0xff; while(1) {  temp=0x01;  for(i=0;i<8;i++)  {   PORTB=temp;   temp<<=1;   delay(50);  } }}void exter1(void){ PORTB=0xff;}