X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Ffwbc.c;h=fecb7533ac3275da6700c2b5848b41de50b049ca;hb=404060c864c2d8bd444246078590c6f71f22217f;hp=6a8f187c55b80db709a2e8c1de7737e0ce3d6805;hpb=90fa4f3eca580f497dd24e9b3afd818d3b1f7054;p=my-code%2Farm.git diff --git a/betty/fwbc.c b/betty/fwbc.c index 6a8f187..fecb753 100644 --- a/betty/fwbc.c +++ b/betty/fwbc.c @@ -6,23 +6,54 @@ * */ -void uart0_init(void) { +#include "lpc2xxx.h" - PINSEL0|=((1<<0)|(1<<2)); /* pin select: tx, rx */ +#define OSC_CLOCK 10000000 +#define BAUDRATE 9600 +#define P_DIV 1 +#define P_CLOCK (OSC_CLOCK/P_DIV) +typedef unsigned char u8; +typedef unsigned int u32; + +void uart0_init(u32 br) { + + /* pin select -> tx rx */ + PINSEL0&=~((1<<0)|(1<<1)|(1<<2)|(1<<3)); + PINSEL0|=((1<<0)|(1<<2)); + + /* divisor */ + UART0_LCR|=(1<<7); + //UART0_DLL=((OSC_CLOCK/(16*br)))&0xff; + //UART0_DLM=(((OSC_CLOCK/(16*br)))&0xff00)>>8; + UART0_DLL=65; + UART0_DLM=0; + + /* 8 bit data */ + UART0_LCR=((1<<0)|(1<<1)); + + /* activate rx tx fifo */ + UART0_FCR|=((1<<0)|(1<<1)|(1<<2)); } -void arm_init(void) { +void uart_send(u8 byte) { - /* pin selection */ - uart0_init(); + /* wait for empty transmit buffer */ + while(!(UART0_LSR&(1<<5))) + continue; + UART0_THR=byte; } -void main(void) { +int main(void) { /* initialization */ - arm_init(); + uart0_init(9600); + + while(1) { + uart_send(0x23); + } + return 0; }