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

📄 main._c

📁 meg16 的所有功能实例
💻 _C
字号:
/****************************************Copyright (c)**************************************************
**                               ADEmbed Development Co.,LTD.                                    
**                                 http://www.adembed.com
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2008-12-13
** Last Version:		1.0
** Descriptions:		UART Tx Test.
** 
**------------------------------------------------------------------------------------------------------
** Created by:			junbolu
** Created date:		2008-12-13
** Version:				1.0
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
**ICC-AVR application builder : 2008-12-13
**Target : M16
**Crystal: 7.3728Mhz
*******************************************************************************************************/

#include <iom16v.h>
#include <macros.h>
#include "main.h"
#include "Define.h"

unsigned char GET_TxNum;
unsigned char GET_TxBUF1[15]="UART Tx Test...";
unsigned char GET_TxBUF2[15]="www.adembed.com";

void Uart_Init(void); 
void USART_TXD(uint8 data);

void Delay_us(unsigned int time)
{
while(time--);
}

void Delay_ms(unsigned int time)
{
while(time--)
	{
	Delay_us(1000);
	}
}

void main(void)
{
 Uart_Init();                 //TART初始化
 SEI();                       //全局中断使能
 while(1)
     {
 	 for(GET_TxNum=0;GET_TxNum<15;GET_TxNum++)
         {
	 	 USART_TXD(GET_TxBUF1[GET_TxNum]); 
     	 }
	 USART_TXD(0x0A);  
	 
     for(GET_TxNum=0;GET_TxNum<15;GET_TxNum++)
     	 {
	 	 USART_TXD(GET_TxBUF2[GET_TxNum]); 
     	 }
	 USART_TXD(0x0A);
	 Delay_ms(2000);
     }
}

//===============================================================
void Uart_Init(void)          //UART初始化
  { 
     
    //设置侦格式
	//异步,8位数据,无奇偶校验,一个停止位,无倍速
	UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
	
    //设置波特率
    UBRRL= (F_osc/Baud_rate/16-1)%256;
    UBRRH= (F_osc/Baud_rate/16-1)/256;

	//使能接收中断,使能接收,使能发送
    UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
  }
  

//===============================================================
void USART_TXD(uint8 data) //发送采用查询方式
{
	while( !(UCSRA & BIT(UDRE)) );
	UDR=data;
	while( !(UCSRA & BIT(TXC )) );
	UCSRA|=BIT(TXC);
}

//=======================================================================

#pragma interrupt_handler USART_RXC:12
void USART_RXC(void)
{
  
}



⌨️ 快捷键说明

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