|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2013-5-14 23:50:24
|
显示全部楼层
好的,程序就在下面,很简单的程序,在中断里点亮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);
}
}
|
|