📄 serial.c
字号:
//-----------------------------------------------------------------------------
// SERIAL.C
//
// This module handles RS-232 messages and associated tasks
//-----------------------------------------------------------------------------
#include <string.h>
#include <avr/signal.h>
#include <avr/io.h>
#include "serial.h"
#include "net.h"
#include "general.h"
extern unsigned int event_word;
unsigned char RxBuf[RxBufLen] = "avrweb";
unsigned char RxBufn = 0;
//unsigned char TxBuf[TxBufLen];
//unsigned char TxBufn = 0;
void InitSerial(void)
{
UBRR0H = UBRR0_V>>8;
UBRR0L = (unsigned char)UBRR0_V; //1
UCSR0A = (1<<TXC)|(0<<U2X);//no double baud
UCSR0B = (1<<RXCIE)|(0<<TXCIE)|(1<<RXEN)|(1<<TXEN);
UCSR0C = (0<USBS)|(3<<UCSZ0); //8bit,1stop
}
SIGNAL(SIG_UART0_RECV)
{
event_word |= EVENT_RS232_ARRIVED;
if(RxBufn>RxBufLen)RxBufn=0;//servo a cycle buffer
RxBuf[RxBufn++] = UDR0;
}
/*
SIGNAL(SIG_UART0_TRANS)
{
if(TxBufn)UDR0 = TxBuf[--TxBufn];//clear TxC flag,load uart,until Txbufn==0
}
void PrintStr(unsigned char* str)
{
char i;
while(!(TxBufn==0 && (UCSR0A&(1<<UDRE))));//both tx, uart buffer is empty
TxBufn = strlen(str);
if(TxBufn)
{
for(i=TxBufn;i>0;i--)TxBuf[i-1]=*str++;
UDR0 = TxBuf[--TxBufn];
}
}
*/
void PrintStr(unsigned char* str)
{
while(*str)if(UCSR0A&(1<<UDRE))UDR0=*str++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -