#include"LPC11xx.h" #define LSR_THRE 0x20 #define LSR_TEMT 0x40 #define LSR_RDR 0x01 #define TEMT (1<<6) int main(void) { unsigned int regVal; unsigned int Fdiv; LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); /* Enable IOCON block */ LPC_IOCON->PIO1_6 &= ~0x07; //Clear the first 3 bits in the FUNC of the 'PIO1_6' LPC_IOCON->PIO1_6 |= 0x01; //Set PIO1_6 as UART RXD LPC_IOCON->PIO1_7 &= ~0x07; //Clear the first 3 bits in the FUNC of the 'PIO1_7' LPC_IOCON->PIO1_7 |= 0x01; //Set PIO1_7 as UART TXD /*Enable UART Clock*/ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); //Enable UART clock LPC_SYSCON->UARTCLKDIV = 0x01; //Divide by 1 LPC_UART->LCR = 0x83; //8 bits, no parity, 1 stop bit, DLAB(divisor latch access bit) = 1 regVal = LPC_SYSCON->UARTCLKDIV; Fdiv = (((SystemCoreClock)/regVal)/16)/38400 ; /*baud rate is set to 38400,Because HC05 is set to 38400 Baud rate */ LPC_UART->DLM = Fdiv / 256; LPC_UART->DLL = Fdiv % 256; LPC_UART->LCR = 0x03; /* Diable latch access bit DLAB = 0 */ //Skal være 0 for at kunne skrive til THR LPC_UART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ unsigned int i =0; unsigned int data ; while(1){ data = LPC_UART->LSR; // Ensure a clean start, no data in either TX or RX FIFO. while (( LPC_UART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); while ( LPC_UART->LSR & LSR_RDR ) { data = LPC_UART->RBR; // Dump data from RX FIFO } if(LPC_UART->LSR &0x01) data = LPC_UART->RBR; LPC_UART->THR |= data; } return 0 ; } |