uart.c

来自「基于AVR的超声波测距程序」· C语言 代码 · 共 46 行

C
46
字号
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdio.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include "MyDef.h"
#include "Uart.h"

#ifdef Debug	

FILE mystd = FDEV_SETUP_STREAM(System_putchar, System_getchar,_FDEV_SETUP_RW); //虚拟设备

void Uart_Init(void)
{
  UCSRB=_BV(RXEN)|_BV(TXEN); 
  UBRRL=25;   //8M 19200 
  stdout=&mystd;
  stdin=&mystd;
  SetPrintfConvertMode=0;
}

int System_putchar(char c, FILE *stream)
{
	if(SetPrintfConvertMode==1)
	{
		
	}
	else
	{
		if (c == '\n')
		System_putchar('\r', stream);
		loop_until_bit_is_set(UCSRA, UDRE);
		UDR = c;
	}
	
	return 0;
}

int System_getchar( FILE *stream)
{
	loop_until_bit_is_set(UCSRA,RXC);
	return UDR;
}

#endif

⌨️ 快捷键说明

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