📄 async.c
字号:
#include <pic.h>
#include "..\inc\async.h"
/* Routines for initialisation and use of the SCI
* for the PIC processor.
*/
void async_Init()
{
/*
This is a list of different settings in SPREG at FOSC 4 and 16 MHZ
Baudrate 4 16
9600 25 103
19200 12 51
38400 5.5 25
*/
// SPBRG = 25; /* set the baud rate 9600 at 4 MHz */
// TXSTA = 0x24; /* TXEN and BRGH=1 */
// RCSTA = 0x90; /* SPEN=1, CREN=1, */
// TXIE = 0; /* disable tx interrupts in PIE1 register */
// RCIE = 0; /* disable rx interrupts in PIE1 register */
SPBRG = 12; /* set the baud rate 9600 at 4 MHz */
TXSTA = 0x20; /* TXEN and BRGH=1 */
RCSTA = 0x80; /* SPEN=1, CREN=1, */
TXIE = 0; /* disable tx interrupts in PIE1 register */
RCIE = 0; /* disable rx interrupts in PIE1 register */
}
//void async_PutByte(unsigned char byte)
void putch(unsigned char byte) // This will make printf() use our routine
{
while(!TXIF) /* set when register is empty */
continue;
TXREG = byte;
return;
}
/* Will wait until a character is received and return the character.
If error condition is to be checked, do that ahead of this function */
unsigned char async_GetByte(void)
{
while(!RCIF) /* set when register is not empty */
continue;
return RCREG; /* RXD9 and FERR are gone now */
}
/* Check if there is an overrun condition if so remove the condition
return OVERRUN if error othervise OK */
unsigned char async_CheckOERR(void)
{
if(OERR) /* re-enable after overrun error */
{
CREN = 0;
CREN = 1;
return 1;
}
return 0;
}
/* Wait forever for a character to be recieved */
unsigned char async_GetFERR(void)
{
while(!RCIF)
continue;
return FERR; /* RCIF is not cleared until RCREG is read */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -