46a342c8ab3e6e3101a8b00f70c1d0d6215b6973
[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
18 void uart0_init(int br) {
19
20         PINSEL0&=~((0x03<<0)|(0x03<<2));        // clear bits 0-3
21         PINSEL0|=((1<<0)|(1<<2));               // pin select: tx, rx
22
23         UART0_LCR|=(1<<7);                      // enable access to divisor
24         UART0_DLL=(P_CLOCK/(br*16))&0xff;       // set divisor
25         UART0_DLL=((P_CLOCK/(br*16))&0xff00)>>8;
26         UART0_LCR&=~(1<<7);                     // disable access to divisor
27
28         UART0_LCR&=~(0x03<<2);                  // 1 stop bit, no parity
29         UART0_LCR|=0x03;                        // 8 data bits
30
31         UART0_FCR=0x01;                         // activate fifo
32 }
33
34 void uart_send(u8 byte) {
35
36         /* wait for empty transmit buffer */
37         while(!(UART0_LSR&(1<<5)))
38                 continue;
39
40         UART0_THR=byte;
41 }
42
43 int main(void) {
44
45         /* initialization */
46         uart0_init(9600);
47
48         while(1) {
49                 uart_send(0x23);
50         }
51
52         return 0;
53 }
54