📄 main.c
字号:
#include<iom16.h>
#include<inavr.h>
#include<RemoKey.h>
#include<define.h>
unsigned char Flag=0;
unsigned int temp;
#define Debug_Uart
//#define Debug_ANA
//#define Debug_Spi
//#define Debug_T2
//#define Debug_T1
//#define Debug_WDT
//#define Debug_T0
void NmDelay(unsigned int n)
{
unsigned char i;
while(n--)i=0;
for(;i<125;)
i++;
}
void ANA_Init(void)
{
ACSR=0x00;
ACSR|=0x02;
ACSR|=0x08;
//SFIOR|=0x08;
//ADMUX=0x02;
// ADCSRA=0x00;
}
void WDT_On(void)
{
WDTCR=0x0f;
}
void WDT_Off(void)
{
WDTCR|=0x18;
WDTCR&=~0x08;
}
void WDT_Reset(void)
{
__watchdog_reset();
}
void Uart_Init(void)
{
UBRRL=25; //8M--Buad=19200
UCSRB=0xd8;
}
void Uart_Send_Byte(unsigned char c)
{
#ifdef Debug_Uart
UCSRB=0x98;
ClrBit(UCSRA,TXC);
UDR=c;
while(!(ValBit(UCSRA,TXC)));
ClrBit(UCSRA,TXC);
#endif
}
void Spi_Send(unsigned char ch)
{
SPSR&=0x7f;
SPDR=ch;
while(SPSR|0x80==0);
SPSR&=0x7f;
}
void main( void )
{
#ifdef Debug_Spi
DDRB|=0xa0;
SPCR|=0x71;
SPSR|=0x01;
#endif
//__sleep();
#ifdef Debug_T1
DDRD|=0x20;
TCCR1A|=0x82;//0xc3
TCCR1B|=0x15;
ICR1=80;
OCR1A=20;
#endif
#ifdef Debug_T0
DDRB|=0x08;
PORTB|=0x08;
TCCR0=0x15;
OCR0=25;
#endif
#ifdef Debug_WDT
WDT_On();
#endif
//OCR1B=30;
INT0_Enable;
SREG|=0x80;
//TIMSK|=0x01;
MCUCR|=0x03;
#ifdef Debug_ANA
ANA_Init();
#endif
Uart_Init();
//TCCR1A=0x80;
//TCCR1B=0xdd;
//TCCR0=0x06;
//ICR1=0x06ff;
TIMSK|=0x01;
SetBit(DDRB,5);
SetBit(PORTB,5);
while(1)
{
#ifdef Debug_WDT
WDT_Reset();
#endif
#ifdef Debug_Spi
Spi_Send(0x00);
//spi-=0x0f;
//if(spi<=0x0f)
//spi=0xff;
NmDelay(50);
Spi_Send(0xff);
#endif
//Uart_Send_Byte(ICR1L);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
NmDelay(5000);
if(RemoSuccess==1)
{
RemoSuccess=0;
INT0_Enable;
#ifdef Debug_T0
Remo_ProT0();
#endif
#ifdef Debug_T1
Remo_ProT1();
#endif
#ifdef Debug_WDT
Remo_ProWDT();
#endif
}
}
}
#pragma vector=TIMER1_COMPA_vect
__interrupt void T1AOC_INT(void)
{
if(Flag==0)
{
temp=1;
OCR1A=temp;
Flag=1;
}
if(Flag==1)
{
temp+=5;
OCR1A=temp;
if(temp>=0xfF)
{
temp=1;
Flag=0;
}
}
}
#pragma vector=SPI_STC_vect
__interrupt void Spi_Int(void)
{
}
#pragma vector=ANA_COMP_vect
__interrupt void ANA_Int(void)
{
Uart_Send_Byte(0x33);
NmDelay(1000);
}
#pragma vector=20
__interrupt void ICP1_Int(void)
{
Uart_Send_Byte(0x11);
NmDelay(1000);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -