悬赏
2
分 芯积分未解决
本人第一次做avr单片机的项目,现在用atmel studio在调试程序。在调试的时候我把参数或者常量放在watch里面,基本都显示的unknown identifier,具体就像图中一样。求问问题在哪。
另还有我想进入中断中编译,或者手动输入符合中断条件。如何实现呢。
我写的是一个简单的USART通信的代码
#include
#include
#include
//Definition USART
//UCSRA
#define UPE 2
#define DOR 3
#define FE 4
#define UDRE 5
#define RXC 7
//UCSRB
#define RXCIE 7
#define TXCIE 6
#define RXEN 4
#define TXEN 3
//UCSRC
#define URSEL 7
#define UCSZ1 2
#define UCSZ0 1
#define FRAMING_ERROR (1<
#define PARITY_ERROR (1<
#define DATA_OVERRUN (1<
#define DATA_REGISTER_EMPTY (1<
#define RX_COMPLETE (1<
//Definition Baudsetting
#define BAUD 9600 //Baudrate
#define Freq 8000000 //Krystal
#define UBRR_Setting (unsigned int)((unsigned long)Freq/(16*(unsigned long)BAUD)-1)
#define BAUD_H (unsigned char)(UBRR_Setting>>8)
#define BAUD_L (unsigned char)(UBRR_Setting)
//Definition Schaltbank
#define INH 3 //Schaltbank1-INH auf PORTD.3 anschliessen
void Zellauswaehlen(int Z)
{ unsigned char Portset,i = 0;
for (i = 0; i < 8; i++)
{ Portset >>= 1;
Portset |= Z & 0x80;
Z <<= 1;
} //PORTD einstellen
PORTD |= (1 << INH); //Schaltbank deaktivieren
delay_ms(2);
PORTD = (PORTD & 0b00001111) | (Portset & 0b11110000);
delay_us(100);
PORTD &= ~(1 << INH);
return;
}
interrupt[USART_RXC] void usart_rx_isr(void)
{ unsigned char status,data;
status = UCSRA;
data = UDR;
if ((status & ( FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN ))==0)
{
Zellauswaehlen(data);
}
}
void main(void)
{
PORTD = 0x03; //TXD,RXD einstellen
DDRD = 0x02;
UCSRA = 0x00; //Initialisierung USART
UCSRB = (1 << RXCIE) | (1 << TXCIE) | (1 << RXEN) | (1 << TXEN);
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0);
UBRRH = BAUD_H;
UBRRL = BAUD_L;
#asm("sei");
}