код программы:
- Код: Выделить всё
//atmega32, fsck=16MHz
#include <delay.h>
#include <mega32.h>
#define RXB8 1 //usart control bits
#define TXB8 0
#define UPE 2
#define DOR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
#define DATA_REGISTER_FULL (1<<DOR)
// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char data;
PORTB++; //значение после одного входа в прерывание-F-1
data=UDR;
//while(!(UCSRA & DATA_REGISTER_EMPTY));
// UDR=data;
}
void reset_WDT(void)
{
#asm
WDR
#endasm
}
void initialization(void)
{
UCSRA=0x00;//uart initialization 8data,1stop,no parity, asynchronous, 38400
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x19;//end usart initialization
DDRD=0xFF; //port usart and max 485
PORTD=0xFF;//usart on and max 485 transmit
DDRB=0xFF;
}
void main(void)
{
initialization();
reset_WDT();
#asm("sei")// Global enable interrupts
while(!(UCSRA & DATA_REGISTER_EMPTY));
PORTB=0xF;
UDR=8;
//while(!(UCSRA&DATA_REGISTER_FULL));
while (1)
{
reset_WDT();
delay_ms(1000);
};
}