下面是嵌入式实验的代码 可以帮注释一下吗

#include <stdint.h>
#include "LPC17xx.h"
#include "bmboard.h"
#include "led.h"
#include "lpc1768_uart.h"

void UART2_SendString(unsigned char *s, uint32_t len)
{
while(len--)
UART2_SendByte(*s++);
}

void UART2_SendByte(unsigned char ucData)
{
while(!(LPC_UART2->LSR&LSR_THRE));
LPC_UART2->THR=ucData;
}

RX_BUF_TypeDef RxBuf; //声明 RxBuf lpc1768_uart 中可见
void UART2_Init(uint32_t baud)
{
LPC_UART_TypeDef *pUart;
pUart=LPC_UART2;
RxBuf.available=0;
RxBuf.len=0;
LPC_PINCON->PINSEL0|=(1<<20);
LPC_PINCON->PINSEL0|=(1<<22);
LPC_SC->PCONP=LPC_SC->PCONP|(1<<24);

uart_set_divisors(pUart,baud);
LPC_UART2->LCR=LCR_LENGTH_8|\ //数据位8位
LCR_STOP_1; //停止位1位
LPC_UART2->FCR=(FCR_FIFO_ENABLE|FCR_RX_FIFO|FCR_TX_FIFO);
LPC_UART2->IER=(IER_RBR_ENABLED|IER_THRE_ENABLED);
NVIC_EnableIRQ(UART2_IRQn);
}

UART2_IRQHandler(void)
{
uint32_t int_status;
uint32_t lsr_status;
char ch;

int_status=LPC_UART2->IIR;

switch(int_status&0x0F)
{
case IIR_RLS:
lsr_status=LPC_UART2->LSR;
break;

case IIR_RDA:
if(LPC_UART2->LSR&LSR_RDR)
{
if((ch=LPC_UART2->RBR)!='\r')
RxBuf.RxData[RxBuf.len++]=ch;
else{
RxBuf.available=1;
}
}
break;
case IIR_THRE:
LPC_UART2->IER&=~IER_THRE_ENABLED;
break;
}
}

慕码人8056858
浏览 115回答 2
2回答

喵喔喔

so easy. you can understand it.#include <stdint.h> // 数据类型头文件#include "LPC17xx.h" // LPC17寄存器定义头文件#include "bmboard.h" // 宝马开发板定义#include "led.h" // LED控制API#include "lpc1768_uart.h" // UART控制APIvoid UART2_SendString(unsigned char *s, uint32_t len) // 串口2字符串发送函数{while(len--)UART2_SendByte(*s++);}void UART2_SendByte(unsigned char ucData) // UART2单字节发送函数{while(!(LPC_UART2->LSR&LSR_THRE));LPC_UART2->THR=ucData;}RX_BUF_TypeDef RxBuf; //声明 RxBuf lpc1768_uart 中可见void UART2_Init(uint32_t baud) // 串口初始化函数,在此仅定义波特率{LPC_UART_TypeDef *pUart;pUart=LPC_UART2;RxBuf.available=0;RxBuf.len=0;LPC_PINCON->PINSEL0|=(1<<20);LPC_PINCON->PINSEL0|=(1<<22);LPC_SC->PCONP=LPC_SC->PCONP|(1<<24);uart_set_divisors(pUart,baud);LPC_UART2->LCR=LCR_LENGTH_8|\ //数据位8位LCR_STOP_1; //停止位1位LPC_UART2->FCR=(FCR_FIFO_ENABLE|FCR_RX_FIFO|FCR_TX_FIFO);LPC_UART2->IER=(IER_RBR_ENABLED|IER_THRE_ENABLED);NVIC_EnableIRQ(UART2_IRQn);}UART2_IRQHandler(void) // 串口2接收中断服务函数{uint32_t int_status;uint32_t lsr_status;char ch;int_status=LPC_UART2->IIR;switch(int_status&0x0F){case IIR_RLS:lsr_status=LPC_UART2->LSR;break;case IIR_RDA:if(LPC_UART2->LSR&LSR_RDR){if((ch=LPC_UART2->RBR)!='\r')RxBuf.RxData[RxBuf.len++]=ch;else{RxBuf.available=1;}}break;case IIR_THRE:LPC_UART2->IER&=~IER_THRE_ENABLED;break;}}

慕勒3428872

so easy. you can understand it.#include <stdint.h> // 数据类型头文件#include "LPC17xx.h" // LPC17寄存器定义头文件#include "bmboard.h" // 宝马开发板定义#include "led.h" // LED控制API#include "lpc1768_uart.h" // UART控制APIvoid UART2_SendString(unsigned char *s, uint32_t len) // 串口2字符串发送函数{while(len--)UART2_SendByte(*s++);}void UART2_SendByte(unsigned char ucData) // UART2单字节发送函数{while(!(LPC_UART2->LSR&LSR_THRE));LPC_UART2->THR=ucData;}RX_BUF_TypeDef RxBuf; //声明 RxBuf lpc1768_uart 中可见void UART2_Init(uint32_t baud) // 串口初始化函数,在此仅定义波特率{LPC_UART_TypeDef *pUart;pUart=LPC_UART2;RxBuf.available=0;RxBuf.len=0;LPC_PINCON->PINSEL0|=(1<<20);LPC_PINCON->PINSEL0|=(1<<22);LPC_SC->PCONP=LPC_SC->PCONP|(1<<24);uart_set_divisors(pUart,baud);LPC_UART2->LCR=LCR_LENGTH_8|\ //数据位8位LCR_STOP_1; //停止位1位LPC_UART2->FCR=(FCR_FIFO_ENABLE|FCR_RX_FIFO|FCR_TX_FIFO);LPC_UART2->IER=(IER_RBR_ENABLED|IER_THRE_ENABLED);NVIC_EnableIRQ(UART2_IRQn);}UART2_IRQHandler(void) // 串口2接收中断服务函数{uint32_t int_status;uint32_t lsr_status;char ch;int_status=LPC_UART2->IIR;switch(int_status&0x0F){case IIR_RLS:lsr_status=LPC_UART2->LSR;break;case IIR_RDA:if(LPC_UART2->LSR&LSR_RDR){if((ch=LPC_UART2->RBR)!='\r')RxBuf.RxData[RxBuf.len++]=ch;else{RxBuf.available=1;}}break;case IIR_THRE:LPC_UART2->IER&=~IER_THRE_ENABLED;break;}}
打开App,查看更多内容
随时随地看视频慕课网APP