//=============头文件===========
#include //chip----ATMEGA64
#include
#include
#include
#include
//==========================================
void init_timer0(void);
void init_uart0(void);
void init_uart1(void);
void init_port(void);
//=========================================
//RAM define.
unsigned char Buf0[10];
unsigned char count=0;
//==================================================================
//==================================================================
//=============定时器T0初始化函数============
void init_timer0(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0x70; //set count
OCR0 = 0x90;
TCCR0 = 0x06; //start timer
}
/*****************************************************/
//calculating register UBRR reult .
//algorithm:if(u2x=0) ubrr=fosc/(16*baud)-1.
// if(u2x=1) ubrr=fosc/(8*baud)-1 .
//UART0初始化函数,晶体:7.37258M
//====================
void init_uart0(void)
{
UCSR0B=(1<=UART_TX0_BUFFER_SIZE) TxBuf0_begin=0;
}
}*/
//===================================
//UART0接收中断处理函数
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RX
void uart0_rx_isr(void)
{
Buf0[count]=UDR0;
count++;
if(count>=10) count=0;
}
/* RxBuf0[RxBuf0_end]=UDR0;
RxBuf0_end++;
if(RxBuf0_end>=UART_RX0_BUFFER_SIZE) RxBuf0_end=0;
}*/
/*************************************************************/
//calculating register UBRR reult .
//algorithm:if(u2x=0) ubrr=fosc/(16*baud)-1.
// if(u2x=1) ubrr=fosc/(8*baud)-1 .
//UART1(PC)初始化函数,晶体:7.37258M.
//===================================
void init_uart1(void)
{
UCSR1B=(1<=UART_TX1_BUFFER_SIZE) TxBuf1_begin=0;
}
}*/
//=================================
//UART1(GPS)接收中断处理函数
/*#pragma interrupt_handler uart1_rx_isr:iv_USART1_RXC
void uart1_rx_isr(void)
{
RxBuf1[RxBuf1_end]=UDR1;RxBuf1_end++;
if(RxBuf1_end>=UART_RX1_BUFFER_SIZE) RxBuf1_end=0;
}*/
/*************************************************************/
void init_port(void)
{
DDRA = 0x00; //INPUT
DDRB = 0x00; //INPUT
DDRC = 0x00; //INPUT
DDRD = 0x00; //INPUT
DDRE = 0x00; //INPUT
DDRF = 0x00; //INPUT
DDRG = 0x00; //INPUT
PORTA = 0xFF; //上拉电阻
PORTB = 0xFF;
PORTC = 0xFF;
PORTD = 0xFF;
PORTE = 0xFF;
PORTF = 0xFF;
PORTG = 0xFF;
// DDRG |= BIT(RUN); //RUN
// DDRB |= BIT(LED_WXCHCY);
// DDRG |= BIT(LED_GPS);
}
/**************************************************************/
//===========================================================//
void main(viod)
{
init_uart0();
// init_uart1();
// init_timer0();
init_port();
MCUCR=0x00;
TIMSK=0x00;
TIMSK |= BIT(TOIE0);
// SEI();
UDR0=Buf0[count];
while(1)
{;
}
}