📄 softuart.h
字号:
#if !defined(F_CPU)
#warning F_CPU not defined in makefile - now defined in softuart.h
#define F_CPU 3686400UL
#endif
#define SOFTUART_BAUD_RATE 2400
#define SOFTUART_RXPIN PINB
#define SOFTUART_RXDDR DDRB
#define SOFTUART_RXBIT PB0
#define SOFTUART_TXPORT PORTB
#define SOFTUART_TXDDR DDRB
#define SOFTUART_TXBIT PB1
#define SOFTUART_T_COMP_LABEL TIM0_COMPA_vect
#define SOFTUART_T_COMP_REG OCR0A
#define SOFTUART_T_CONTR_REGA TCCR0A
#define SOFTUART_T_CONTR_REGB TCCR0B
#define SOFTUART_T_CNT_REG TCNT0
#define SOFTUART_T_INTCTL_REG TIMSK
#define SOFTUART_CMPINT_EN_MASK (1<<OCIE0A)
#define SOFTUART_CTC_MASKA (1<<WGM01)
#define SOFTUART_CTC_MASKB (0)
/* "A timer interrupt must be set to interrupt at three times
the required baud rate." */
#define SOFTUART_PRESCALE (8)
// #define SOFTUART_PRESCALE (1)
#if (SOFTUART_PRESCALE==8)
#define SOFTUART_PRESC_MASKA (0)
#define SOFTUART_PRESC_MASKB (1<<CS01)
#elif (SOFTUART_PRESCALE==1)
#define SOFTUART_PRESC_MASKA (0)
#define SOFTUART_PRESC_MASKB (1<<CS00)
#else
#error "prescale unsupported"
#endif
#define SOFTUART_TIMERTOP ( F_CPU/SOFTUART_PRESCALE/SOFTUART_BAUD_RATE/3 -1)
#if (SOFTUART_TIMERTOP > 0xff)
#warning "Check SOFTUART_TIMERTOP"
#endif
#define SOFTUART_IN_BUF_SIZE 32
// Init the Software Uart
void softuart_init(void);
// Clears the contents of the input buffer.
void softuart_flush_input_buffer( void );
// Tests whether an input character has been received.
unsigned char softuart_kbhit( void );
// Reads a character from the input buffer, waiting if necessary.
char softuart_getchar( void );
// To check if transmitter is busy
unsigned char softuart_can_transmit( void );
// Writes a character to the serial port.
void softuart_putchar( const char );
// Turns on the receive function.
void softuart_turn_rx_on( void );
// Turns off the receive function.
void softuart_turn_rx_off( void );
// Write a NULL-terminated string from RAM to the serial port
void softuart_puts( const char *s );
// Write a NULL-terminated string from program-space (flash)
// to the serial port. i.e. softuart_puts_p(PSTR("test"))
void softuart_puts_p( const char *prg_s );
// Helper-Macro - "automaticly" inserts PSTR
// when used: include avr/pgmspace.h before this include-file
#define softuart_puts_P(s___) softuart_puts_p(PSTR(s___))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -