久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: LPC1788 SPI主從機代碼 [打印本頁]

作者: hadaxio    時間: 2018-12-6 13:19
標題: LPC1788 SPI主從機代碼
在做LPC1788開發板的主從機開發,分享下代碼

單片機源程序如下:
  1. /**********************************************************************
  2. * $Id[        DISCUZ_CODE_1        ]nbsp;               mcu_main_new.c                        2012-05-04
  3. *//**
  4. * @file                mcu_main_new.c
  5. * @brief        User program.
  6. * @version        1.0
  7. * @date                04. May. 2012
  8. * @author        NXP MCU SW Application Team
  9. *
  10. * Copyright(C) 2011, NXP Semiconductor
  11. * All rights reserved.
  12. *
  13. ***********************************************************************
  14. * Software that is described herein is for illustrative purposes only
  15. * which provides customers with programming information regarding the
  16. * products. This software is supplied "AS IS" without any warranties.
  17. * NXP Semiconductors assumes no responsibility or liability for the
  18. * use of the software, conveys no license or title under any patent,
  19. * copyright, or mask work right to the product. NXP Semiconductors
  20. * reserves the right to make changes in the software without
  21. * notification. NXP Semiconductors also make no representation or
  22. * warranty that such application will be suitable for the specified
  23. * use without further testing or modification.
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors'
  26. * relevant copyright in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers.  This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. **********************************************************************/

  31. #include "includes.h"

  32. #define VTOR_OFFSET         (0x00001000)

  33. SBL_FirmVerion_Type firm_vers __attribute__((section("firmware_id_section")))= {0,1,'b'};

  34. /************************** PRIVATE DEFINITIONS *************************/
  35. #ifdef __MCU_LPC17xx
  36. #define MCB_1700
  37. //#define IAR_LPC_1768
  38. #elif defined (__MCU_LPC11xx)
  39. #define MCB_1100
  40. #endif

  41. #if defined (MCB_1700)
  42. /* Number of user LEDs */
  43. #define LED_NUM     4
  44. const unsigned long led_mask[] = { 1<<3, 1<<4, 1<<5, 1<<6 };
  45. #elif defined(MCB_1100)
  46. #define LED_NUM     4
  47. const unsigned long led_pin[] = { 3, 4, 5, 6 };
  48. #endif

  49. /************************** PRIVATE VARIABLES *************************/
  50. /* SysTick Counter */
  51. volatile unsigned long SysTickCnt;

  52. /************************** PRIVATE FUNCTIONS *************************/
  53. void SysTick_Handler (void);
  54. void ReAllocateNVIC(void);

  55. /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
  56. /*********************************************************************//**
  57. * @brief            SysTick handler sub-routine (1ms)
  58. * @param[in]        None
  59. * @return           None
  60. **********************************************************************/
  61. void SysTick_Handler (void) {
  62.   SysTickCnt++;
  63. }

  64. /*-------------------------PRIVATE FUNCTIONS------------------------------*/
  65. /*********************************************************************//**
  66. * @brief            Re-allocate vector interrupt table
  67. * @param[in]        None
  68. * @return           int
  69. **********************************************************************/
  70. void ReAllocateNVIC(void)
  71. {
  72. #ifdef __MCU_LPC17xx
  73.     __disable_irq();
  74.     NVIC_SetVTOR(VTOR_OFFSET);
  75.     __enable_irq();
  76. #elif defined (__MCU_LPC11xx)
  77.     uint32_t* src,*dst;
  78.     int32_t size;

  79.     __disable_irq();
  80.     // copy vector table
  81.     src = (uint32_t*)VTOR_OFFSET;
  82.     dst = (uint32_t*)0x10000000;
  83.     size = 192;

  84.     while(size > 0)
  85.     {
  86.         *dst++ = *src++;
  87.         size -= 4;
  88.     }
  89.      LPC_SYSCON->SYSMEMREMAP = 0x1;    /* remap to internal RAM */
  90.     __enable_irq();
  91. #endif
  92. }
  93. /*-------------------------MAIN FUNCTION------------------------------*/
  94. /*********************************************************************//**
  95. * @brief          c_entry: Main program body
  96. * @param[in]      None
  97. * @return         None
  98. **********************************************************************/
  99. void c_entry(void)
  100. {   
  101.     int num = 0;
  102.     uint32_t systickcnt;
  103.     SBL_SlaveInit();

  104.     /* Relocate NVIC */
  105.     ReAllocateNVIC();

  106.     SystemCoreClockUpdate();
  107.     SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms   */

  108. #if defined (MCB_1700)
  109.     GPIO_SetDir(2, 0x0000007C, 1);           /* LEDs on PORT2 defined as Output    */
  110.     GPIO_ClearValue(2, 0x0000007C);
  111. #elif defined(MCB_1100)
  112.     for(num = LED_NUM-1;num>=0;num--)
  113.     {
  114.         GPIO_SetDir(2, led_pin[num],1);
  115.         GPIO_SetValue(2, led_pin[num]);
  116.     }
  117. #elif defined(IAR_LPC_1768)
  118.     GPIO_SetDir(1, (1<<25), 1);
  119.     GPIO_ClearValue(1, (1<<25));
  120. #endif

  121.     while(1)
  122.     {
  123.         if(SBL_SlaveCmdRecv())
  124.         {
  125.             SBL_SlaveCmdHandler(SBL_SlaveGetRecvCmd());
  126.         }
  127.         else
  128.         {
  129.             if(((SysTickCnt - systickcnt) < 500))
  130.             {
  131. #if defined (MCB_1700)
  132.                 for(num = LED_NUM-1;num>=0;num--)
  133.                     GPIO_SetValue(2, led_mask[num]);
  134. #elif defined(MCB_1100)   
  135.                 for(num = LED_NUM-1;num>=0;num--)
  136.                     GPIO_SetValue(2, led_pin[num]);
  137. #else
  138.                   GPIO_SetValue(2,(1<<25));
  139. #endif
  140.             }
  141.             else if(((SysTickCnt - systickcnt) < 1000))
  142.             {
  143. #ifdef MCB_1700              
  144.                 for(num = LED_NUM-1;num>=0;num--)
  145.                     GPIO_ClearValue(2, led_mask[num]);
  146. #elif defined(MCB_1100)   
  147.                 for(num = LED_NUM-1;num>=0;num--)
  148.                     GPIO_ClearValue(2, led_pin[num]);
  149. #else
  150.                 GPIO_ClearValue(1,(1<<25));
  151. #endif   
  152.             }
  153.             else
  154.             {
  155.                  systickcnt = SysTickCnt;
  156.             }
  157.         }
  158.         
  159.     }
  160.     //SBL_DeInit();
  161. }

  162. /* With ARM and GHS toolsets, the entry point is main() - this will
  163.    allow the linker to generate wrapper code to setup stacks, allocate
  164.    heap area, and initialize and copy code and data segments. For GNU
  165.    toolsets, the entry point is through __start() in the crt0_gnu.asm
  166.    file, and that startup code will setup stacks and data */
  167. int main(void)
  168. {
  169.     c_entry();
  170.     return 0;
  171. }
復制代碼

所有資料51hei提供下載:
AN11257.zip (637.92 KB, 下載次數: 11)



作者: yb1988001    時間: 2018-12-10 14:14
多謝樓主分享資料




歡迎光臨 (http://m.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 国产羞羞视频在线观看 | 亚洲精品一区二三区不卡 | 日韩一级一区 | 中文一区二区 | 国产欧美视频一区 | 97日韩精品 | 精品欧美乱码久久久久久 | 男人天堂久久久 | 国产成人精品一区二区三区四区 | 综合久久久 | 精品国产一区二区国模嫣然 | 国产三级日本三级 | 色吊丝2288sds中文字幕 | 天天综合永久入口 | 麻豆国产一区二区三区四区 | www.色五月.com | 免费看黄色片 | 免费播放一级片 | 亚洲综合久久久 | 成人av网站在线观看 | 999精品视频 | 男人的天堂在线视频 | 在线中文字幕视频 | 精品综合 | 免费不卡av | 久久综合久 | 国产精品久久久久久久久久免费看 | 欧美视频网 | 99免费 | 99精品欧美一区二区三区综合在线 | 91精品久久久 | a级在线免费观看 | 国产a视频 | 一区二区三区国产 | 天天色天天射天天干 | 国产 日韩 欧美 制服 另类 | 国产美女在线播放 | 日韩国产中文字幕 | 男女羞羞免费网站 | 黄色小视频入口 | 日韩欧美在线视频播放 |