⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 AVR,系列单片机MEGA48应用例程,包括原理图,代码基本包括全部资源的配置应用.
💻 C
字号:
//ICC-AVR application builder : 2005-5-11 下午 05:50:17
// Target : M48
// Crystal: 7.3728Mhz

#define IAR_DEMO
#ifdef  IAR_DEMO
#include <iom48.h>
#include <ioavr.h>
#include <inavr.h>
#else 
#include <iom48v.h>
#include <macros.h>
#endif


void PutChar(unsigned char send_byte)
{
while ( !(UCSR0A & (1<<UDRE0)) )
		; /* wait for empty transmit buffer */
UDR0 = send_byte; /* start transmittion */

}
void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
}

//UART0 initialize
// desired baud rate: 19200
// actual: baud rate:19200 (0.0%)
void uart0_init(void)
{
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x00;
 UCSR0C = 0x06;
 UBRR0L = 0x17; //set baud rate lo
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0x98;
}

#ifdef  IAR_DEMO
#pragma vector=USART_RX_vect	
__interrupt 
#else 
#pragma interrupt_handler uart0_rx_isr:19
#endif
void uart0_rx_isr(void)
{
unsigned char temp;
temp=UDR0;            //Receive Byte
PutChar(temp);        //send back
 
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 #ifdef  IAR_DEMO
__disable_interrupt();
#else 
CLI(); //disable all interrupts
#endif
 port_init();
 uart0_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EIMSK = 0x00;
 
 TIMSK0 = 0x00; //timer 0 interrupt sources
 TIMSK1 = 0x00; //timer 1 interrupt sources
 TIMSK2 = 0x00; //timer 2 interrupt sources
 
 PCMSK0 = 0x00; //pin change mask 0 
 PCMSK1 = 0x00; //pin change mask 1 
 PCMSK2 = 0x00; //pin change mask 2
 PCICR = 0x00; //pin change enable 
 PRR = 0x00; //power controller
  #ifdef  IAR_DEMO
__enable_interrupt();
#else 
 SEI(); //re-enable interrupts
#endif
 //all peripherals are now initialized
}

//
void main(void)
{
 init_devices();
 while(1);
 //insert your functional code here...
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -