-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial2.c
50 lines (40 loc) · 1.24 KB
/
serial2.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
// Source code under CC0 1.0
#include <stdint.h>
#include <stdio.h>
#define PC_DDR (*(volatile uint8_t *)0x500c)
#define PC_CR1 (*(volatile uint8_t *)0x500d)
#define CLK_DIVR (*(volatile uint8_t *)0x50c0)
#define CLK_PCKENR1 (*(volatile uint8_t *)0x50c3)
#define USART1_SR (*(volatile uint8_t *)0x5230)
#define USART1_DR (*(volatile uint8_t *)0x5231)
#define USART1_BRR1 (*(volatile uint8_t *)0x5232)
#define USART1_BRR2 (*(volatile uint8_t *)0x5233)
#define USART1_CR2 (*(volatile uint8_t *)0x5235)
#define USART1_CR3 (*(volatile uint8_t *)0x5236)
#define USART_CR2_TEN (1 << 3)
#define USART_CR3_STOP2 (1 << 5)
#define USART_CR3_STOP1 (1 << 4)
#define USART_SR_TXE (1 << 7)
//void putchar(char c)
//{
// while(!(USART1_SR & USART_SR_TXE));
//
// USART1_DR = c;
//}
void main(void)
{
unsigned long i = 0;
// char letters = "qweqr"; // mike fix this for sdcc
CLK_DIVR = 0x00; // Set the frequency to 16 MHz
CLK_PCKENR1 = 0xFF; // Enable peripherals
PC_DDR = 0x08; // Put TX line on
PC_CR1 = 0x08;
USART1_CR2 = USART_CR2_TEN; // Allow TX and RX
USART1_CR3 &= ~(USART_CR3_STOP1 | USART_CR3_STOP2); // 1 stop bit
USART1_BRR2 = 0x03; USART1_BRR1 = 0x68; // 9600 baud
for(;;)
{
// printf("Hello World!\n");
for(i = 0; i < 147456; i++); // Sleep
}
}