zoukankan      html  css  js  c++  java
  • lpc4357第一个实验,串口(中断)

    源码如下

      1 #include "chip.h"
      2 #include "board.h"
      3 
      4 #define UARTNum 3 //使用串口3
      5 #define LPC_UART LPC_USART3
      6 #define UARTx_IRQn  USART3_IRQn
      7 #define UARTx_IRQHandler UART3_IRQHandler
      8 #define _GPDMA_CONN_UART_Tx GPDMA_CONN_UART3_Tx
      9 #define _GPDMA_CONN_UART_Rx GPDMA_CONN_UART3_Rx
     10 
     11 static uint8_t uartComplete[] = "Hello  World!
    ";
     12 static uint8_t uart_interrupt_menu[] =
     13     "UART Interrupt mode demo ! 
    Press someting to display 
    ";
     14 
     15 /* Print Welcome Screen Menu subroutine by Interrupt mode */
     16 void Print_Menu_Interrupt(LPC_USART_T *UARTx)
     17 {
     18     uint32_t tmp, tmp2;
     19     uint8_t *pDat;
     20 
     21     tmp = sizeof(uart_interrupt_menu);
     22     tmp2 = 0;
     23     pDat = (uint8_t *) &uart_interrupt_menu[0];
     24     while (tmp) {
     25         tmp2 = Chip_UART_Interrupt_Transmit(UARTx, pDat, tmp);
     26         pDat += tmp2;
     27         tmp -= tmp2;
     28     }
     29 }
     30 
     31 
     32 void App_Interrupt_Test(void)
     33 {
     34     uint8_t isExit = 0, userInput;
     35     uint32_t len;
     36 
     37 
     38     /* Print out uart interrupt menu */
     39     //Print_Menu_Interrupt(LPC_UART);
     40 
     41     while (!isExit) {
     42         len = 0;
     43         while (len == 0) {
     44             len = Chip_UART_Interrupt_Receive(LPC_UART, &userInput, 1);
     45         }
     46         
     47             Chip_UART_Interrupt_Transmit(LPC_UART, (uint8_t *) &userInput, sizeof(userInput));
     48         
     49         
     50          if (( userInput == 'x') || ( userInput == 'X') ) {
     51             isExit = 1;
     52         }
     53     }
     54     //App_Interrupt_DeInit();
     55 }
     56 
     57 
     58 /*****************************************************************************
     59  *中断服务程序
     60  ****************************************************************************//
     61  
     62 void UARTx_IRQHandler(void)
     63 {
     64     Chip_UART_Interrupt_Handler(LPC_UART);
     65 }
     66 
     67 /**
     68  * @brief    Main UART program body
     69  * @return    Always returns -1
     70  */
     71 int main(void)
     72 {
     73     
     74     //局部变量和一些数据结构的定义
     75     
     76     uint8_t buffer[10];
     77     UART_FIFO_CFG_T UARTFIFOConfigStruct;//FIFO½á¹¹ÌåÉùÃ÷
     78  
     79     //--------时钟初始化-----------------------
     80     Board_Init();//
     81     Board_UART_Init(LPC_UART);
     82 
     83 //设置波特率
     84     Chip_UART_Init(LPC_UART);
     85     Chip_UART_SetBaud(LPC_UART, 115200);
     86     Chip_UART_ConfigData(LPC_UART, UART_DATABIT_8, UART_PARITY_NONE, UART_STOPBIT_1);    /* Default 8-N-1 */
     87 
     88     /* Enable UART Rx interrupt */
     89     Chip_UART_IntConfig(LPC_UART, UART_INTCFG_RBR, ENABLE);
     90     /* Enable UART line status interrupt */
     91     Chip_UART_IntConfig(LPC_UART, UART_INTCFG_RLS, ENABLE);
     92     /* Enable UART Transmit */
     93     Chip_UART_TxCmd(LPC_UART, ENABLE);
     94 
     95 //Fifo 初始化
     96     Chip_UART_FIFOConfigStructInit(LPC_UART, &UARTFIFOConfigStruct);
     97     Chip_UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct);
     98 /*
     99 /抢占式优先级和响应优先级 http://www.arm32.com/post/304.html
    100     http://blog.csdn.net/blue0432/article/details/7892960
    101 
    102  preemption = 1, sub-priority = 1 */
    103     NVIC_SetPriority(UARTx_IRQn, 1);
    104     /* Enable Interrupt for UART0 channel */
    105     NVIC_EnableIRQ(UARTx_IRQn);
    106     Chip_UART_InitRingBuffer;// ringbuffer !!!!!
    107 
    108 // 来输出个 字符串 呗Hello world
    109  Chip_UART_Send(LPC_UART, uartComplete, sizeof(uartComplete), BLOCKING);
    110 
    111     
    112     Print_Menu_Interrupt(LPC_UART);
    113 
    114     App_Interrupt_Test();
    115     
    116     return -1;
    117     }
  • 相关阅读:
    业务领域建模Domain Modeling
    用例建模Use Case Modeling
    分析一套源代码的代码规范和风格并讨论如何改进优化代码
    结合工程实践选题调研分析同类软件产品
    如何提高程序员的键盘使用效率
    python知识准备及环境配置
    一张图片在Python操作下的4种玩法(附源码)
    Python中的错误和异常
    当你忘记网站上的密码时怎么办?Python如何快速帮你找回?
    Python最简单的图片爬虫,20行代码带你爬遍整个网站
  • 原文地址:https://www.cnblogs.com/kalo1111/p/3172228.html
Copyright © 2011-2022 走看看