[an error occurred while processing this directive]
|
//ICC-AVR application builder : 08.04.06 10:41:32
// Target : M162
// Crystal: 4.0000Mhz
#include #define UART_RX_BUFFER_SIZE1 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */ #if ( UART_RX_BUFFER_SIZE1 & UART_RX_BUFFER_MASK1 ) static unsigned char UART_RxBuf1[UART_RX_BUFFER_SIZE1]; #pragma interrupt_handler uart1_rx_isr:21 #pragma interrupt_handler uart1_tx_isr:25 while ( UART_RxHead1 == UART_RxTail1 ) /* wait for incomming data */ void TransmitByte1( unsigned char data1 ) unsigned char DataInReceiveBuffer1( void ) void init_devices(void) CLI(); void main(void) init_devices(); while(1){ }
E-mail:
info@telesys.ru
#include
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0x00;
DDRC = 0xFF;
PORTD = 0x03;
DDRD = 0xFE;
PORTE = 0x00;
DDRE = 0x07;
}
#define UART_RX_BUFFER_MASK1 ( UART_RX_BUFFER_SIZE1 - 1 )
#define UART_TX_BUFFER_SIZE1 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */
#define UART_TX_BUFFER_MASK1 ( UART_TX_BUFFER_SIZE1 - 1 )
#error RX buffer size is not a power of 2
#endif
static volatile unsigned char UART_RxHead1;
static volatile unsigned char UART_RxTail1;
static unsigned char UART_TxBuf1[UART_TX_BUFFER_SIZE1];
static volatile unsigned char UART_TxHead1;
static volatile unsigned char UART_TxTail1;
void uart1_init(void)
{
unsigned char x;
UBRR1H = (unsigned char)(9600>>8);
UBRR1L = (unsigned char)9600;
UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1)| (1 << TXCIE1);
UCSR1C = 0x06;
x = 0; /* flush receive buffer */
UART_RxTail1 = x;
UART_RxHead1 = x;
UART_TxTail1 = x;
UART_TxHead1 = x;
}
void uart1_rx_isr(void)
{
unsigned char data1;
unsigned char tmphead1;
data1 = UDR1; /* read the received data */
/* calculate buffer index */
tmphead1 = ( UART_RxHead1 + 1 ) & UART_RX_BUFFER_MASK1;
UART_RxHead1 = tmphead1; /* store new index */
if ( tmphead1 == UART_RxTail1 )
{
/* ERROR! Receive buffer overflow */
}
UART_RxBuf1[tmphead1] = data1; /* store received data in buffer */
}
void uart1_tx_isr(void)
{
unsigned char tmptail1;
if ( UART_TxHead1 != UART_TxTail1 )
{
tmptail1 = ( UART_TxTail1 + 1 ) & UART_TX_BUFFER_MASK1;
UART_TxTail1 = tmptail1; /* store new index */
UART_TxBuf1[tmptail1]; /* start transmition */
}
else
{
UCSR1B &= ~(1<
}
/* Read and write functions */
unsigned char ReceiveByte1( void )
{
unsigned char tmptail1;
;
tmptail1 = ( UART_RxTail1 + 1 ) & UART_RX_BUFFER_MASK1;/* calculate buffer index */
UART_RxTail1 = tmptail1; /* store new index */
return UART_RxBuf1[tmptail1]; /* return data */
}
{
unsigned char tmphead1;
/* calculate buffer index */
tmphead1 = ( UART_TxHead1 + 1 ) & UART_TX_BUFFER_MASK1;
while ( tmphead1 == UART_TxTail1 )
;
UART_TxBuf1[tmphead1] = data1; /* store data in buffer */
UART_TxHead1 = tmphead1; /* store new index */
UCSR1B |= (1<
{
return ( UART_RxHead1 != UART_RxTail1 );
/* return 0 (FALSE) if the receive buffer is empty */
}
{
port_init();
uart1_init();
MCUCR= 0x00;
EMCUCR = 0x00;
TIMSK= 0x10;
ETIMSK=0x00;
GICR= 0x00;
PCMSK0=0x00;
PCMSK1=0x00;
SEI();
}
{
TransmitByte1(0x55);
};
Ответы
Перейти к списку ответов
|||
Конференция
|||
Архив
|||
Главная страница
|||
Содержание