📄 16c550.c
字号:
/*
*****************************************************************************************
* Name :UART.C
* Date :2004.1.2
* Modified by :Avirl
* Fuctions :UART_Initialize() UART_Init() TxQInit() RxQInit() Uart0isr() Uart1isr()
* UARTTxIntOn() UARTRxIntOn() UARTTxIntOff() UARTRxIntOff() TxQWr() RxQRd()
* Uart_SendByte() Uart_SendString() Uart_Printf() getch() i_getc() kbhit()
******************************************************************************************
*/
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "conreg.h"
#include "uart.h"
#include "irq.h"
#include "16C550.h"
#include "pio.h"
extern unsigned long MS_TIMER;
extern void delay(int ms);
void UART16C550_Init(void)
{
UART16C550_FCR = 0x06;
UART16C550_IER = 0x01;
UART16C550_LCR = 0x80;
UART16C550_DLL = 0x0C;
UART16C550_DLM = 0x00;
UART16C550_LCR = 0x03;
UART16C550_MCR = 0x00;
}
void UART16C550_SendChar(char c)
{
char t;
do{
t = UART16C550_LSR;
}while((t & 0x40)==0);
UART16C550_THR = c;
}
void UART16C550_SendStr(char *str, uint8 strlen)
{
unsigned int k = 0;
do{
UART16C550_SendChar(*(str + k));
k++;
}while(k < strlen);
}
void UART16C550_Puts(char *str)
{
while(*str)
UART16C550_SendChar(*str++);
//UART16C550_SendStr(str, strlen(str));
}
int UART16C550_Expect(char *expect_string, unsigned long timeout)
{
uint expect_length, match_position;
unsigned long t;
int received;
expect_length = strlen(expect_string);
match_position = 0;
while(match_position < expect_length)
{
t = MS_TIMER;
while((received = UART16C550_GetChar()) == 0xFF)
{
if(MS_TIMER - t > timeout)
{
return 0; //timed out
}
}
//if(MODEM_DEBUG)
//{
// Uart_Printf("received");
//}
if(received == expect_string[match_position])
{
match_position++;
}
else
{
match_position = 0; //no match, start over
}
}
return 1;
}
int UART16C550_GetChar(void)
{
int t;
int c;
t = UART16C550_LSR;
if((t & 0x01)==0x01)
{
c = UART16C550_RBR;
return(c);
}
//c = UART16C550_RBR;
//return(c);
return(0xFF);
}
void UART16C550_isr_receive(void)
{
int i,c;
c = UART16C550_RBR;
PIO_Set_Low(18);
for(i=0; i<50000;i++);
//delay(200);
PIO_Set_High(18);
//i = UART16C550_GetChar();
if(c==80)
{
PIO_Set_Low(17);
//delay(200);
//PIO_Set_High(17);
//delay(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -