console.c

来自「ucos2 in lpc2104 的源码」· C语言 代码 · 共 48 行

C
48
字号
/******************************************************************************
    uC/OS-II Porting for LPC210x

    By: Pary WU <parywu@mail2000.com.tw>
    History:
    0406271325:parywu
        The first stable release.
******************************************************************************/
#include "console.h"
void console_init(void){
    
    // console uses UART0
    rPINSEL0 = (rPINSEL0 & 0xfffffff0) | 0x05;
    rU0LCR = 0x80;
    rU0DLM = vU0DLM;
    rU0DLL = vU0DLL;
    rU0LCR = vU0LCR;
    rU0IER = 0x00; // clear interrupt; console do NOT use interrupt
}

char console_getch(void){
    while(!(rU0LSR&(0x01<<0)))
        continue;
    return rU0RBR;
}

void console_putch(char c){
    while(!(rU0LSR & (0x01<<5)))
        continue;
    rU0THR = c;
}

void console_putstr(char* str){
    while(*str)
        console_putch(*str++);
}
void console_puthex(unsigned int v){
    unsigned int i;
    unsigned char ab[]="0123456789abcdef";
    for(i=0;i<8;i++)
        console_putch(  ab[((v >> ((7-i) << 2)) & 0x0000000f)] );
}
void console_putbin(unsigned int v){
    unsigned int i;
    for(i=0;i<32;i++)
        console_putch((char)('0' + (unsigned char)((v >> (31-i))&0x00000001)));
}

⌨️ 快捷键说明

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