📄 int0._c
字号:
//ICC-AVR application builder : 2007-5-18 9:57:24
// Target : M16
// Crystal: 8.0000Mhz
#include <iom16v.h>
#include <macros.h>
#include"delay.h"
#define uchar unsigned char
#define uint unsigned int
//uchar num=0;
uchar temp=0;
unsigned char abc[17]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,
0xee,0x3e,0x9c,0x7a,0x9e,0x8e,0x00};
//----------------SPI初始化------------//
void SPI_init(void)
{
DDRB&=0xbf;
SPCR=(1<<SPE)|(1<<DORD)|(1<<MSTR)|(1<<SPR1);
}
//-------------------SPI发送数据-----------//
void SPI_send(unsigned char i)
{
SPDR=i;
while((SPSR&0x80)==0x00);
}
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
uchar i;
CLI();
{
for(i=0;i<5;i++)
{
delay_nus(1000);
if((PIND&0X04)==0X04)
{
return;
}
}
while((PIND&0X04)!=0X04);//等待高电平
delay_nus(2900);//延时4.8ms
for(i=0;i<8;i++)
{
while((PIND&0X04)!=0X04);//等待高电平
delay_nus(480);//延时480us
if(PIND&0X04)
{
temp=temp>>1;
delay_nus(200);//
temp|=0x80; //数据写入1
}
else
{
temp=temp>>1;
temp&=0x7f; //数据写入0
}
}
}
while((PIND&0X04)!=0X04);//等待高电平
delay_nus(480);//延时480us
if(!(PIND&0X04))
{
return;
}
/*if(temp==0x06)
{
PORTA=temp;
SPI_send(abc[temp]);
//PORTD&=~BIT(1);
}*/
else
{
PORTA=temp;
SPI_send(abc[temp]);
//num=temp;
//PORTD=0xff;
}
SEI();
}
//call this routine to initialize all peripherals
void main(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
SPI_init();
MCUCR = 0x02;
GICR = 0x40;
TIMSK = 0x00; //timer interrupt sources
SPI_send(abc[16]);
SEI(); //re-enable interrupts
//all peripherals are now initialized
while(1)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -