Добавил:
lelik
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные МПр / код / lab3 / Lab - timer / src / uart
.c/***************************************
*
* LETI traning 2011
*
***************************************/
#include "LPC17xx.h"
#include "uart.h"
//---
void uart_init(void) {
LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */
LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */
LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
LPC_UART0->DLL = 9; /* 115200 Baud Rate @ 25.0 MHZ PCLK */
LPC_UART0->FDR = 0x21; /* FR 1,507, DIVADDVAL = 1, MULVAL = 2 */
LPC_UART0->DLM = 0; /* High divisor latch = 0 */
LPC_UART0->LCR = 0x03; /* DLAB = 0 */
LPC_UART0->IER = 15;
NVIC_EnableIRQ((IRQn_Type) UART0_IRQn);
}
//---
void send_char(char c) {
while (!(LPC_UART0->LSR & 0x20)); //wait while uart is busy
...//send character c
}
//---
void receive_char(void) {
char c;
while (!(LPC_UART0->LSR & 0x01)); //wait while uart is busy
...//receive character c
...//do something with character c
}
//---
void send_string(char* s) { //send string by charecters
while (*s != 0) {
send_char(*s++);
}
}
//---
void UART0_IRQHandler(void) __irq {
... //what need to do first?
if(...) { //check: if interrupted by receive, then receive_char()
receive_char();
}
}