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

📄 uart_atmega8._c

📁 AVR单片机的T_TO_TWI通讯方式
💻 _C
字号:
/*****************************************************************
ICC-AVR application builder : 2005-8-19 14:40:53
 Target : M8
 Crystal: 7.3728Mhz
// Crystal: 4.6080Mhz

实验:做usart串行通讯实验
目的:了解及会使用usart串口
CPU:atmega8L
相关的5个寄存器:UCSRA,UCSRB,UCSRC,UDR,UBRR(UBRRH,UBRRL)
	         其中:UBRRH和UCSRC共用一个地址
******************************************************************/
/*配置:CKOPT=0,CKSEL3..0=1111,SUT1..0=11(65ms慢速上升电源)*/
#include <iom8v.h>
#include <macros.h>
#include "usart_m8.h"
#include "twi.h"

void check_I2C(void);
void init_data(void);
void port_init(void);
void init_devices(void);
void check_watchdog(void);
void process_data_pack(void);
void watchdog_init(void);


void main(void)
{
	init_devices();
	init_data();
  
	while(1)  //forever
	   {
	      check_I2C();
		  USART_Transmit( "我是中国人" );
	      process_data_pack();
		  check_watchdog();//喂狗
       }
}
//解包
void process_data_pack(void)
{
   if(Rx_Over_Pack_Flag == true)
    {
		if((UART_RX_buff[1] == 0x57)&&(UART_RX_buff[8] == 0x58))
		{
		  
		}
		if((UART_RX_buff[1] == 0x52)&&(UART_RX_buff[8] == 0x58))
		{
		 
		}
	}
}


void check_I2C(void)
{
	unsigned char dat;
	
	if(Mem_Write_Flag == true)
	{
	 	Mem_Write_Flag = false;			  

		;
	}	
}

void init_data(void)
{
 ;// Rx_Flag    = false;
}
void port_init(void)
{
 PORTB = 0x3F;
 DDRB  = 0x00;
 PORTC = 0x4F; //m103 output only
 DDRC  = 0x00;
 PORTD = 0xFC;
 DDRD  = 0x00;
}
//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();
 twi_init();
 watchdog_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}
void check_watchdog(void)
{
 	WDR();//喂狗
}
void watchdog_init(void)
{
 WDR();//看门狗计数清零
 WDTCSR=((1<<WDE)|(1<<WDP2)|(1<<WDP0));//64K分频,0.52S
 //WDIE是看门狗中断使能,WDE看门狗使能 101 512k
}

⌨️ 快捷键说明

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