X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Farm.git;a=blobdiff_plain;f=betty%2Ffwbc.c;h=46a342c8ab3e6e3101a8b00f70c1d0d6215b6973;hp=6a8f187c55b80db709a2e8c1de7737e0ce3d6805;hb=2cdab277c293b22742ebf7888ca8ac40555f4f1d;hpb=feece393fb07514608a7ad21eaa376ea3375e945 diff --git a/betty/fwbc.c b/betty/fwbc.c index 6a8f187..46a342c 100644 --- a/betty/fwbc.c +++ b/betty/fwbc.c @@ -6,23 +6,49 @@ * */ -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; + +void uart0_init(int br) { + + PINSEL0&=~((0x03<<0)|(0x03<<2)); // clear bits 0-3 + PINSEL0|=((1<<0)|(1<<2)); // pin select: tx, rx + + UART0_LCR|=(1<<7); // enable access to divisor + UART0_DLL=(P_CLOCK/(br*16))&0xff; // set divisor + UART0_DLL=((P_CLOCK/(br*16))&0xff00)>>8; + UART0_LCR&=~(1<<7); // disable access to divisor + + UART0_LCR&=~(0x03<<2); // 1 stop bit, no parity + UART0_LCR|=0x03; // 8 data bits + + UART0_FCR=0x01; // activate fifo } -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; }