#define __watchdog_reset() asm("wdr") //Reset Watchdog Timer #define __disable_interrupt() asm("cli") //Turn off global interrupt #define __enable_interrupt() asm("sei") //Turn on global interrupt
/ void UART3_ini(void) { //UART3 口 UBRR3 = 103; //baudrate = 9600 at system clk = 16MHz UCSR3C = 0x06; //异步,8位数据,无奇偶校验,一个停止位,无倍速 UCSR3B = 0x98; //接收中断使能,接收允许,发送允许 }
void UART_transmit(unsigned char dat) { while ( !( UCSR3A & (1<<UDRE3)) ); UDR3 = dat; }
int main(void) { __disable_interrupt(); //上电默认DDRx=0x00,PORTx=0x00 输入,无上拉电阻 PORTA = 0xFF; //不用的管脚使能内部上拉电阻 DDRD = 0xC0; PORTD = 0xC0;
UART3_ini(); __watchdog_reset(); __enable_interrupt();
while(1) { if(PINJ2) PORTD = 0x80; else PORTD = 0x40;
__watchdog_reset(); }
return 0;
}
SIGNAL(USART3_RX_vect) // USART Receiver interrupt service routine { UDR3 = UDR3; }
PJ2引脚上接一个摇臂开关,可以接入0V或5V. 这段下载到扳子上时,发现无论怎么拨这个开关,PINJ2的值总是1. 用AVR Studio4 仿真发现PINJ2的值总是莫名其妙被改为1. 这是为什么? |