[an error occurred while processing this directive]
Ответ: вот код если ниче лишнего не выбросил
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

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

Отправлено McLud 11 апреля 2006 г. 13:42
В ответ на: на код можно взглянуть? Очень интересно стало... отправлено glamur 11 апреля 2006 г. 13:37

//ICC-AVR application builder : 08.04.06 10:41:32
// Target : M162
// Crystal: 4.0000Mhz

#include
#include
#include
#pragma interrupt_handler uart0_rx_isr:20
#pragma interrupt_handler uart1_rx_isr:21
#pragma interrupt_handler uart0_tx_isr:24
#pragma interrupt_handler uart1_tx_isr:25

#define TestBit(x,y) (x&(1<

#define UART_RX_BUFFER_SIZE0 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */
#define UART_RX_BUFFER_MASK0 ( UART_RX_BUFFER_SIZE0 - 1 )
#define UART_TX_BUFFER_SIZE0 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */
#define UART_TX_BUFFER_MASK0 ( UART_TX_BUFFER_SIZE0 - 1 )

#if ( UART_RX_BUFFER_SIZE0 & UART_RX_BUFFER_MASK0 )
#error RX buffer size is not a power of 2
#endif
static unsigned char UART_RxBuf0[UART_RX_BUFFER_SIZE0];
static volatile unsigned char UART_RxHead0;
static volatile unsigned char UART_RxTail0;
static unsigned char UART_TxBuf0[UART_TX_BUFFER_SIZE0];
static volatile unsigned char UART_TxHead0;
static volatile unsigned char UART_TxTail0;


#define UART_RX_BUFFER_SIZE1 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */
#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 )

#if ( UART_RX_BUFFER_SIZE1 & UART_RX_BUFFER_MASK1 )
#error RX buffer size is not a power of 2
#endif

static unsigned char UART_RxBuf1[UART_RX_BUFFER_SIZE1];
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;


const char ce[] = "PD2";
const char cl[] = "PD3";
const char da[] = "PD4";


void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0x00;
DDRC = 0xFF;
PORTD = 0x03;
DDRD = 0xFE;
PORTE = 0x00;
DDRE = 0x07;
}

void uart0_init(void)
{
unsigned char x;

UBRR0H = (unsigned char)(9600>>8);
UBRR0L = (unsigned char)9600;
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0)| (1 << TXCIE0);
UCSR0C = 0x06;

x = 0;
UART_RxTail0 = x;
UART_RxHead0 = x;
UART_TxTail0 = x;
UART_TxHead0 = x;
}
void uart1_init(void)
{
unsigned char x;

UBRR1L =0x19; //set baud rate
UBRR1H = 0x00;
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 uart0_rx_isr(void)
{
unsigned char data0;
unsigned char tmphead0;
data0 = UDR0; /* read the received data */
/* calculate buffer index */
tmphead0 = ( UART_RxHead0 + 1 ) & UART_RX_BUFFER_MASK0;
UART_RxHead0 = tmphead0; /* store new index */
if ( tmphead0 == UART_RxTail0 )
{
/* ERROR! Receive buffer overflow */
}
UART_RxBuf0[tmphead0] = data0; /* store received data in buffer */
}

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 uart0_tx_isr(void)
{
unsigned char tmptail0;

/* check if all data is transmitted */
if ( UART_TxHead0 != UART_TxTail0 )
{
/* calculate buffer index */
tmptail0 = ( UART_TxTail0 + 1 ) & UART_TX_BUFFER_MASK0;
UART_TxTail0 = tmptail0; /* store new index */
UDR0 = UART_TxBuf0[tmptail0]; /* start transmition */
}
else
{
UCSR0B &= ~(1< }
}

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 */
UDR1=UART_TxBuf1[tmptail1]; /* start transmition */
}
else
{
UCSR1B &= ~(1< }
}

/* Read and write functions */
unsigned char ReceiveByte1( void )
{
unsigned char tmptail1;

while ( UART_RxHead1 == UART_RxTail1 ) /* wait for incomming data */
;
tmptail1 = ( UART_RxTail1 + 1 ) & UART_RX_BUFFER_MASK1;/* calculate buffer index */
UART_RxTail1 = tmptail1; /* store new index */
return UART_RxBuf1[tmptail1]; /* return data */
}

void TransmitByte1( unsigned char data1 )
{
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<
}

unsigned char DataInReceiveBuffer1( void )
{
return ( UART_RxHead1 != UART_RxTail1 );
/* return 0 (FALSE) if the receive buffer is empty */
}





void delay(int ticks)
{
while(ticks--);
}


//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart1_init();
uart0_init();
MCUCR= 0x00;
EMCUCR = 0x00;
TIMSK= 0x10;
ETIMSK=0x00;
GICR= 0x00;
PCMSK0=0x00;
PCMSK1=0x00;
SEI();
}

void main(void)
{
unsigned char i,j,rx1,ConSum;
init_devices();

while(1)
{

delay(65000);
TransmitByte1(0x55);

};

}

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

Ответы


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

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

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

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

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


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание

E-mail: info@telesys.ru