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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3174|回復: 1
打印 上一主題 下一主題
收起左側

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)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:6656 發表于 2018-12-10 14:14 | 只看該作者
多謝樓主分享資料
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 97精品国产 | 久久伊人一区 | 亚洲成人观看 | 久久精品国产a三级三级三级 | 久久99国产精一区二区三区 | 玖草资源 | 黄视频网址 | 在线观看你懂的网站 | 久久久www成人免费无遮挡大片 | 国产午夜精品久久久久 | 四虎成人精品永久免费av九九 | 国产乱码精品一区二区三区中文 | 成人影音 | 天天草夜夜骑 | 亚洲欧美国产精品久久 | 精品国产乱码久久久久久蜜臀 | 亚洲欧美第一视频 | 天堂中文字幕av | 91国在线视频 | 亚洲91精品| 中文字幕乱码一区二区三区 | 久草网视频 | 成人精品一区 | 久久免费香蕉视频 | 国产伦精品一区二区三区在线 | 国产精品1区2区3区 男女啪啪高潮无遮挡免费动态 | 日韩在线小视频 | 日韩av一区二区在线观看 | 久久精品欧美一区二区三区麻豆 | 欧美一区免费在线观看 | 国产精品污www一区二区三区 | 黄色骚片| 亚洲a视频| 国产精品视频中文字幕 | 精品在线免费看 | 久久国产精品网站 | www亚洲精品| 99久久99热这里只有精品 | 美女视频h | 亚洲成人在线网 | 99久久久久 |