forked from ntavish/mpu9150-pic32
-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.c
executable file
·54 lines (45 loc) · 1 KB
/
console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <plib.h>
#include "hardwareprofile.h"
const unsigned char CharacterArray[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void ConsoleInit(void)
{
ANSELB=0x00;
//UART2 tx RPB0
TRISBbits.TRISB0=0;
RPB0Rbits.RPB0R = 0b0010;
OpenUART2(UART_EN, (1 << 12)|UART_TX_ENABLE, (SYS_FREQ/(1<<mOSCGetPBDIV())/16)/BAUD_RATE-1);
}
void ConsolePut(BYTE c)
{
while(U2STAbits.TRMT == 0);
U2TXREG = c;
}
void PrintChar(BYTE toPrint)
{
BYTE PRINT_VAR;
PRINT_VAR = toPrint;
toPrint = (toPrint>>4)&0x0F;
ConsolePut(CharacterArray[toPrint]);
toPrint = (PRINT_VAR)&0x0F;
ConsolePut(CharacterArray[toPrint]);
return;
}
void PrintDec(BYTE toPrint)
{
ConsolePut(CharacterArray[toPrint/10]);
ConsolePut(CharacterArray[toPrint%10]);
}
void ConsolePutROMString(const char* str)
{
BYTE c;
while( (c = *str++) )
ConsolePut(c);
}
void ConsoleWriteBuffer(BYTE *buf, unsigned int length)
{
unsigned int i = 0;
while(i<length)
{
ConsolePut(buf[i++]);
}
}