usart.h

来自「sd」· C头文件 代码 · 共 86 行

H
86
字号
/*----------------------------------------------------------------------------
 Copyright:      Radig Ulrich  mailto: mail@ulrichradig.de
 Author:         Radig Ulrich
 Remarks:        
 known Problems: none
 Version:        14.06.2007
 Description:    RS232 Routinen
----------------------------------------------------------------------------*/

#ifndef _UART_H
	#define _UART_H

#define BUFFER_SIZE	100

volatile unsigned char buffercounter;
char usart_rx_buffer[BUFFER_SIZE];

struct {
		volatile unsigned char usart_ready:1;
		volatile unsigned char usart_rx_ovl:1;
		}usart_status ;
		
//----------------------------------------------------------------------------
	
	#include <avr/interrupt.h>
	#include <avr/pgmspace.h>
	#include <stdlib.h>
	#include <stdarg.h>
	#include <ctype.h>
	#include <string.h>
	#include <avr/io.h>

//----------------------------------------------------------------------------

//Der Quarz auf dem Experimentierboard
#ifndef SYSCLK
		//#define SYSCLK	8000000	//Quarz Frequenz in Hz
		//#define SYSCLK	14318180	//Quarz Frequenz in Hz
		#define SYSCLK 16000000UL
#endif //SYSCLK	

//Anpassen der seriellen Schnittstellen Register wenn ein ATMega128 benutzt wird
#if defined (__AVR_ATmega128__)
#	define USR UCSR0A
#	define UCR UCSR0B
#	define UDR UDR0
#	define UBRR UBRR0L
#	define EICR EICRB
#endif

#if defined (__AVR_ATmega32__)
#	define USR UCSRA
#	define UCR UCSRB
#	define UBRR UBRRL
#	define EICR EICRB
#endif

#if defined (__AVR_ATmega8__)
#	define USR UCSRA
#	define UCR UCSRB
#	define UBRR UBRRL
#endif

#if defined (__AVR_ATmega88__)
#	define USR UCSR0A
#	define UCR UCSR0B
#	define UBRR UBRR0L
#	define TXEN TXEN0
#	define UDR UDR0
#	define UDRE UDRE0
#endif

//----------------------------------------------------------------------------
	
void usart_init(unsigned int baudrate); 
void usart_write_char(char c);
void usart_write_str(char *str);
	
void usart_write_P (const char *Buffer,...);
#define usart_write(format, args...)   usart_write_P(PSTR(format) , ## args)
	
//----------------------------------------------------------------------------

#endif //_UART_H

⌨️ 快捷键说明

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