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

📄 usart_test.c

📁 NEC单片机开发资料 NEC单片机开发资料 NEC单片机开发资料
💻 C
字号:
/*********************************************************/
/*                                                       */
/*         第2篇第8章 串口校准发送测试 源程序            */
/*                                                       */
/*                   编写:江海波                        */
/*                                                       */
/*                2007-03       V1.0                     */
/*                                                       */
/*         提示 : 本程序仅随本书使用,保留版权            */
/*              实例代码用于工程时应谨慎!               */
/*                                                       */
/*             E-mail : soundman@sohu.com                */
/*                                                       */
/*********************************************************/

#include "iom48v.h"
#include "macros.h"

void uart0_init(void)
{
	UCSR0A = 0x02;					//使用波特率倍增,不使用多从机模式
	UCSR0C = 0x06;					//异步串口模式,禁止奇偶校验,1位停止位,8-bit桢模式
	UBRR0L = 0x0C;					//设置波特率,9600
	UBRR0H = 0x00;
	UCSR0B = 0x98;					//允许接收完成中断使能,禁止发送完成中断,禁止发送寄存器空中断,允许接收,允许发送
}

void Delay_ms(unsigned int Time)
{
    unsigned char n=0;
    while(Time>0)
    {
        for (n=1;n<187;n++)
        {
            NOP();
        }
        Time--;
    }
}

void main (void)
{
    unsigned char SendData = 0xFF;
    
    uart0_init();
    
    do
    {
        while(!(UCSR0A&(1<<UDRE0)));
        UDR0 = SendData;
        SendData--;
    }
    while(SendData != 0xFF);
    
    while(1);
}

⌨️ 快捷键说明

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