uart fixes - at least it's transmitting bullshitz by now!
[my-code/arm.git] / betty / fwbc.c
1 /*
2  * fwbc.c - broadcast the betty tv original firmware via uart0
3  *          use fwdump to write it onto your computers harddisk
4  *
5  * author: hackbard@hackdaworld.org
6  *
7  */
8
9 #include "lpc2xxx.h"
10
11 #define OSC_CLOCK               10000000
12 #define BAUDRATE                9600
13 #define P_DIV                   1
14 #define P_CLOCK                 (OSC_CLOCK/P_DIV)
15
16 typedef unsigned char u8;
17 typedef unsigned int u32;
18
19 void uart0_init(u32 br) {
20
21         /* pin select -> tx rx */
22         PINSEL0&=~((1<<0)|(1<<1)|(1<<2)|(1<<3));
23         PINSEL0|=((1<<0)|(1<<2));
24
25         /* divisor */
26         UART0_LCR|=(1<<7);
27         //UART0_DLL=((OSC_CLOCK/(16*br)))&0xff;
28         //UART0_DLM=(((OSC_CLOCK/(16*br)))&0xff00)>>8;
29         UART0_DLL=65;
30         UART0_DLM=0;
31
32         /* 8 bit data */
33         UART0_LCR=((1<<0)|(1<<1));
34
35         /* activate rx tx fifo */
36         UART0_FCR|=((1<<0)|(1<<1)|(1<<2));
37 }
38
39 void uart_send(u8 byte) {
40
41         /* wait for empty transmit buffer */
42         while(!(UART0_LSR&(1<<5)))
43                 continue;
44
45         UART0_THR=byte;
46 }
47
48 int main(void) {
49
50         /* initialization */
51         uart0_init(9600);
52
53         while(1) {
54                 uart_send(0x23);
55         }
56
57         return 0;
58 }
59