[an error occurred while processing this directive]
Ну, тогда мой пример. Для начала громоздким покажется, но это самое первое, что попалось под руку.
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Bill 17 августа 2005 г. 18:29
В ответ на: Спасибо, а этого примера нет - было бы все - Телесистемы пришлось бы закрывать :-) отправлено <font color=gray>Vladimir Ljaschko</font> 17 августа 2005 г. 18:01


//
// **** UART interrupt handlers ***
//
// UART transmitter handlers
//
#pragma vector = UART_UDRE_vect
__interrupt void TX_Int(void) // **** UDRE interrupt handler
{
switch (UARTstate) // Process the current transmission state
{
case INIT_STATE: // Transmit the reply header
UDR = RplyPacket.Header; // Transmitt the byte
UARTstate = MSB_STATE; // The next will be info MSB
return;
case CONSOLE_STATE: // Transmit the console number
UDR = RplyPacket.Console; // Transmit the byte
UARTstate = LSB_STATE; // The next will be info LSB
return;
case KEY_STATE: // Transmit the pressed key number (the last byte in packet)
UDR = RplyPacket.KeyNumber; // Transmit the byte
UARTstate = INIT_STATE; // Return to the initial state
UCR |= TXCIE_BIT; // Enable TXC interrupts
return;
}
}
#pragma vector = UART_TX_vect
__interrupt void TXC_Int(void) // **** TXC interrupt handler
{
UCR &= ~TXCIE_BIT; // Disable TXC interrupts
UARTflags &= ~REPLY_BIT; // Reset the event flag
UART_CTRL &= ~DIR_BIT; // Set RS-485 driver in reception mode
}
//
// UART reciever handler
//
#pragma vector = UART_RX_vect
__interrupt void RX_Int(void)
{
char _ch;

_ch = UDR; // Get the just received byte
switch (UARTstate) // Process the current state
{
case INIT_STATE: // Initial state
if (_ch==REQUEST_HDR || _ch==BRDCAST_HDR) // Message header is received
{
SendPacket.Header = _ch; // Fill the message header field,
UARTstate = MSB_STATE; // Wait for the MSB info byte
}
return; // Interrupt exit
case MSB_STATE: // 1st info byte is received
SendPacket.Info = ((unsigned)_ch << 8); // Fill the MSB info field
UARTstate = LSB_STATE; // Wait for the LSB info byte
return; // Interrupt exit
case LSB_STATE: // 2nd info byte is received
SendPacket.Info |= _ch; // Concatenate LSB byte
UARTflags |= MESSAGE_BIT; // The new message is received
default:
UARTstate = INIT_STATE; // Wait for a new messge
return;
}
}


Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 
NoIX ключ Запомнить

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru