📄 infrare.c
字号:
//ICC-AVR application builder : 2006-5-31 10:57:45
// Target : M8
// Crystal: 8.0000Mhz
#include <iom8v.h>
#include <macros.h>
void port_init(void)
{
PORTB = 0xFF;
DDRB = 0x00;
PORTD = 0x00;
DDRD = 0x11;
}
//TIMER1 initialize - prescale:1
// WGM: 4) CTC, TOP=OCRnA
// desired value: 38.4KHz
// actual value: 38.462KHz (0.2%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x31;
OCR1AH = 0x00;
OCR1AL = 0xCF;
OCR1BH = 0x00;
OCR1BL = 0xCF;
ICR1H = 0x00;
ICR1L = 0xCF;
TCCR1A = 0x80;
TCCR1B = 0x09; //start Timer
}
//UART0 initialize
// desired baud rate: 2400
// actual: baud rate:2404 (0.2%)
// char size: 8 bit
// parity: Odd
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x36;
UBRRL = 0xCF; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x28;
}
#pragma interrupt_handler uart0_udre_isr:13
void uart0_udre_isr(void)
{
//character transferred to shift register so UDR is now empty
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer1_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void delay()
{ unsigned char i = 100;
while(i--);
}
void main()
{
init_devices(void);
while(PORTB != 0x0)
{
unsigned char temp;
temp = PORTB;
switch(temp)
{
case 1:
while(PORTB = 0)
{
UDR0 = 'A'; //A代表加速,
//B代表减速,
delay(); //C为正方向
break: //D为反方向
} //E代表开
case 2: //F代表关
while(PORTB = 0)
{
UDR0 = 'B';
delay();
break:
}
case 1:
while(PORTB = 0)
{
UDR0 = 'C';
delay();
break:
}
case 4:
while(PORTB = 0)
{
UDR0 = 'D';
delay();
break:
}
case 8:
while(PORTB = 0)
{
UDR0 = 'E';
delay();
break:
}
case 16:
while(PORTB = 0)
{
UDR0 = 'F';
delay();
break:
}
case 32:
while(PORTB = 0)
{
UDR0 = 'G';
delay();
break:
}
case 64:
while(PORTB = 0)
{
UDR0 = 'E';
delay();
break:
}
}
}
]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -