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

📄 initrialm16.h

📁 ATmega128的GPS例子
💻 H
字号:
//ICC-AVR application builder : 2007-6-27 10:26:06
// Target : M8
// Crystal: 8.0000Mhz

/**************初始化m8函数***************/
#ifndef Initrial_M16_H
#define Initrial_M16_H

/**************************************************************
**函数名称	     :void init_devices(void)
**函数功能	     :初始化设备
**输入参数      :无
**返回值	     :无
**外定义变量:无
**调用的函数:无
**************************************************************/
void Init_Devices(void);

/**************************************************************
**函数名称	     :void port_init(void)
**函数功能      :初始化端口
**输入参数      :无
**返回值	     :无
**外定义变量:无
**调用的函数: Port_init();
**************************************************************/
void Port_Init(void);
void Init_Devices(void);
void uart0_init(void);
void uart0_rx_isr(void);
extern void Get_GPRMC_data(void);//提取GPRMC数据


//call this routine to initialize all peripherals
void Init_Devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 Port_Init();
 uart0_init();
 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

void Port_Init(void)
{
	PORTB = 0xFF;
	DDRB  = 0xFF;
	PORTC = 0x7F; //m103 output only
	DDRC  = 0x7F;
	PORTD = 0xFF;
	DDRD  = 0xFF;

	DDRD &=~ BIT(PD0);
	PORTD &= ~ BIT(PD0);
	
	DDRA &=~ BIT(PA1);//按键
	DDRA &=~ BIT(PA3);
	//PORTA &= ~ BIT(PA5);
 	//PORTA &= ~ BIT(PA7);
	
	
 
}

//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = BIT(URSEL) | 0x06;
 UBRRL = 0x33; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x98;
}

#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
	char data;
 	data = UDR;
	if(data == '$')//开始字符
	{
		usart_flag |= BIT(SINK0_START);
		sink0_count = 0;	
	}
	if(usart_flag & BIT(SINK0_START))
	{
		sink0_buf[sink0_count] = data; 
		sink0_count ++;
	}
	if(data == 0x0a)//换行结束字符
	{
		usart_flag &=~ BIT(SINK0_START);
		usart_flag |= BIT(SINK0_FINISH);
		
	}
	if(usart_flag & BIT(SINK0_FINISH))
	{
		Get_GPRMC_data();	
		usart_flag &=~ BIT(SINK0_FINISH);			
	}
		
}

#endif




⌨️ 快捷键说明

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