Atmega8外部中断
ATemage8外部中断只有电平触发可以用,其他上升沿、下降沿触发都不正常工作,求大神指教! 给程序,看是否设置有问题? 好的,程序就在下面,很简单的程序,在中断里点亮LED,不过只有电平触发可以用,其他的都不可以工作//ICC-AVR application builder :
// Target : M8
// Crystal: 8.0000Mhz
#include <iom8v.h>
#include <macros.h>
unsigned char i=0;
void port_init(void)
{
PORTD = 0x00;
DDRD= 0x00;
PORTC = 0xff;
DDRC = 0xff;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR= 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
/************************************
用 途:微秒级延时程序
Taget :mega8
crystal :8M
介 绍:在8M的晶振上进行us级的延时
入口参数:
*************************************/
void delay_us(int time)
{
do
{
time--;
}
while (time > 1);
}
/************************************
用 途:打开外部中断
介 绍:
入口参数:
出口参数:
*************************************/
void int_init()
{
CLI();
PORTD|=(1<<PD2)|(1<<PD3);
MCUCR|=(1<<ISC10)|(0<<ISC01);//3-0,外部中断定1,0的控制方式(下降沿出发)
//MCUCR=3-2,0是低电平中断,1是下(降沿)和上(升沿)中断,2是下中断,3是上中断
GICR|=(1<<INT0)|(1<<INT1);//7,6外部中断1,0使能
SEI();
}
/************************************
用 途:中断0服务子程序
介 绍:
入口参数:
出口参数:
*************************************/
#pragma interrupt_handler init_0:2
void init_0()
{
PORTC &= ~(1<<PC0);//中断点亮灯
}
/************************************
用 途:中断1服务子程序
介 绍:
入口参数:
出口参数:
*************************************/
#pragma interrupt_handler init_1:3
void init_1()
{
PORTC &= ~(1<<PC0); //中断点亮灯
}
void main()
{
port_init();
init_devices();
int_init();//中断初始化
SREG|=BIT(7);//使能全局中断 初始化后在打开中断
while(1)
{
//PORTC |= (1<<PD0);
PORTC |= (1<<PD0);
}
}
我买的这一批都ATemage8芯片都出现上面的问题,可不可能是芯片有问题呢! 你怎么确定边缘触发不能中断的? 有示波器观察LED引脚还是看LED亮度?
如果是用的示波器,那可能程序有其它问题,我也没看出来;
如果是看LED亮度的话,那可能是观察问题,程序不一定有问题,只是LED点亮了立即又灭了,可能观察不到 示波器看的,这一批都不行! qq1328454800 发表于 2013-5-14 23:52 static/image/common/back.gif
我买的这一批都ATemage8芯片都出现上面的问题,可不可能是芯片有问题呢!
应该不会是假芯片吧。 我也不确定啊,准备再买一个回来试试! 中断的时候叫电平翻转,可以清楚的看看。 可不可能是编译器的问题了?
页:
[1]