-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.c
88 lines (77 loc) · 1.69 KB
/
serial.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* serial.c
*
* Created on: Feb 12, 2017
* Author: srazak
* Edited on: Sep 16, 2021
* Author: efeoflus
*/
#include "15348.h"
void SetupSerial()
{
SYSCTL_RCGCUART_R = 0x01;
SYSCTL_RCGCGPIO_R |= 0x01;
//GPIO_PORTA_CR_R = 0xFF;
GPIO_PORTA_AFSEL_R |= 0x03;
GPIO_PORTA_DEN_R |= 0x03;
GPIO_PORTA_PCTL_R = 0x11;
UART0_CTL_R &= ~UART_CTL_UARTEN;
UART0_IBRD_R = 0x8;
UART0_FBRD_R = 0x2C;
UART0_LCRH_R = 0x0070;
UART0_CTL_R |= UART_CTL_UARTEN;
UART0_IFLS_R = 0x12;
UART0_CC_R = 0x05;
}
void SerialWrite(char * st)
{
char* temp = st;
while (*temp!=0)
{
while(UART0_FR_R & 0x20);
UART0_DR_R = *temp;
temp++;
asm(" NOP");
asm(" NOP");
}
}
void SerialWriteLine(char * st)
{
SerialWrite(st);
while(UART0_FR_R & 0x20);
UART0_DR_R = 13;
__asm(" NOP");
__asm(" NOP");
while(UART0_FR_R & 0x20);
UART0_DR_R = 10;
__asm(" NOP");
__asm(" NOP");
}
void SerialWriteInt(int n)
{
// change n to String
char str[] = {'0','0','0','0','0','0','0','0','0','0',0};
int i = 9;
while (n>0)
{
str[i] = '0'+n%10;
n = n /10;
i--;
}
char * ch = str;
while (*ch!=0 && *ch=='0')
ch++;
SerialWriteLine(ch);
}
static char hexmap[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void SerialWriteHex(unsigned int n)
{
char str[] = {'0','0','0','0','0','0','0','0',0};
int i = 7;
while (n > 0) {
str[i] = hexmap[n&0xf];
n >>= 4;
i--;
}
SerialWriteLine(str);
}