历史上的今天
返回首页

历史上的今天

今天是:2024年11月28日(星期四)

正在发生

2019年11月28日 | LPC1788 SPI主从机代码

2019-11-28 来源:51hei

单片机源程序如下:

/**********************************************************************

* $Id[        DISCUZ_CODE_1        ]nbsp;               mcu_main_new.c                        2012-05-04

*//**

* @file                mcu_main_new.c

* @brief        User program.

* @version        1.0

* @date                04. May. 2012

* @author        NXP MCU SW Application Team

* Copyright(C) 2011, NXP Semiconductor

* All rights reserved.

*

***********************************************************************

* Software that is described herein is for illustrative purposes only

* which provides customers with programming information regarding the

* products. This software is supplied "AS IS" without any warranties.

* NXP Semiconductors assumes no responsibility or liability for the

* use of the software, conveys no license or title under any patent,

* copyright, or mask work right to the product. NXP Semiconductors

* reserves the right to make changes in the software without

* notification. NXP Semiconductors also make no representation or

* warranty that such application will be suitable for the specified

* use without further testing or modification.

* Permission to use, copy, modify, and distribute this software and its

* documentation is hereby granted, under NXP Semiconductors'

* relevant copyright in the software, without fee, provided that it

* is used in conjunction with NXP Semiconductors microcontrollers.  This

* copyright, permission, and disclaimer notice must appear in all copies of

* this code.

**********************************************************************/


#include "includes.h"


#define VTOR_OFFSET         (0x00001000)


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


/************************** PRIVATE DEFINITIONS *************************/

#ifdef __MCU_LPC17xx

#define MCB_1700

//#define IAR_LPC_1768

#elif defined (__MCU_LPC11xx)

#define MCB_1100

#endif


#if defined (MCB_1700) 

/* Number of user LEDs */

#define LED_NUM     4

const unsigned long led_mask[] = { 1<<3, 1<<4, 1<<5, 1<<6 };

#elif defined(MCB_1100)

#define LED_NUM     4

const unsigned long led_pin[] = { 3, 4, 5, 6 };

#endif


/************************** PRIVATE VARIABLES *************************/

/* SysTick Counter */

volatile unsigned long SysTickCnt;


/************************** PRIVATE FUNCTIONS *************************/

void SysTick_Handler (void);

void ReAllocateNVIC(void);


/*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/

/*********************************************************************//**

* @brief            SysTick handler sub-routine (1ms)

* @param[in]        None

* @return           None

**********************************************************************/

void SysTick_Handler (void) {

  SysTickCnt++;

}


/*-------------------------PRIVATE FUNCTIONS------------------------------*/

/*********************************************************************//**

* @brief            Re-allocate vector interrupt table

* @param[in]        None

* @return           int

**********************************************************************/

void ReAllocateNVIC(void)

{

#ifdef __MCU_LPC17xx

    __disable_irq();

    NVIC_SetVTOR(VTOR_OFFSET);

    __enable_irq();

#elif defined (__MCU_LPC11xx)

    uint32_t* src,*dst;

    int32_t size;


    __disable_irq();

    // copy vector table

    src = (uint32_t*)VTOR_OFFSET;

    dst = (uint32_t*)0x10000000;

    size = 192;


    while(size > 0)

    {

        *dst++ = *src++;

        size -= 4;

    }

     LPC_SYSCON->SYSMEMREMAP = 0x1;    /* remap to internal RAM */

    __enable_irq();

#endif

}

/*-------------------------MAIN FUNCTION------------------------------*/

/*********************************************************************//**

* @brief          c_entry: Main program body

* @param[in]      None

* @return         None

**********************************************************************/

void c_entry(void)

{   

    int num = 0;

    uint32_t systickcnt;

    SBL_SlaveInit();


    /* Relocate NVIC */

    ReAllocateNVIC();


    SystemCoreClockUpdate();

    SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms   */


#if defined (MCB_1700) 

    GPIO_SetDir(2, 0x0000007C, 1);           /* LEDs on PORT2 defined as Output    */

    GPIO_ClearValue(2, 0x0000007C);

#elif defined(MCB_1100)

    for(num = LED_NUM-1;num>=0;num--)

    {

        GPIO_SetDir(2, led_pin[num],1);

        GPIO_SetValue(2, led_pin[num]);

    }

#elif defined(IAR_LPC_1768)

    GPIO_SetDir(1, (1<<25), 1);

    GPIO_ClearValue(1, (1<<25));

#endif


    while(1)

    {

        if(SBL_SlaveCmdRecv())

        {

            SBL_SlaveCmdHandler(SBL_SlaveGetRecvCmd());

        }

        else

        {

            if(((SysTickCnt - systickcnt) < 500))

            {

#if defined (MCB_1700)

                for(num = LED_NUM-1;num>=0;num--)

                    GPIO_SetValue(2, led_mask[num]);

#elif defined(MCB_1100)   

                for(num = LED_NUM-1;num>=0;num--)

                    GPIO_SetValue(2, led_pin[num]);

#else

                  GPIO_SetValue(2,(1<<25));

#endif

            }

            else if(((SysTickCnt - systickcnt) < 1000))

            { 

#ifdef MCB_1700              

                for(num = LED_NUM-1;num>=0;num--)

                    GPIO_ClearValue(2, led_mask[num]);

#elif defined(MCB_1100)   

                for(num = LED_NUM-1;num>=0;num--)

                    GPIO_ClearValue(2, led_pin[num]);

#else

                GPIO_ClearValue(1,(1<<25));

#endif    

            }

            else

            {

                 systickcnt = SysTickCnt;

            }

        }

        

    }

    //SBL_DeInit();

}


/* With ARM and GHS toolsets, the entry point is main() - this will

   allow the linker to generate wrapper code to setup stacks, allocate

   heap area, and initialize and copy code and data segments. For GNU

   toolsets, the entry point is through __start() in the crt0_gnu.asm

   file, and that startup code will setup stacks and data */

int main(void)

{

    c_entry();

    return 0;

}



推荐阅读

史海拾趣

Clever Little Box公司的发展小趣事

在市场竞争日益激烈的情况下,Clever Little Box意识到,单打独斗很难取得长久的成功。于是,公司开始积极寻求与其他企业的合作,通过共赢的战略选择,实现资源共享、优势互补。这种合作模式不仅帮助公司扩大了市场份额,还提高了公司的品牌知名度和影响力。

AURORA公司的发展小趣事

AURORA公司深知自动驾驶技术的商业化落地需要与汽车制造商紧密合作。因此,AURORA积极与大众汽车集团、现代汽车等多家知名汽车制造商建立合作关系。通过共同研发和推广自动驾驶技术,AURORA成功帮助这些汽车厂商加速各自自动驾驶汽车的商用计划。这种深度合作不仅提升了AURORA的市场影响力,也为公司的长期发展奠定了坚实基础。

Components Corporation公司的发展小趣事

AURORA公司深知自动驾驶技术的商业化落地需要与汽车制造商紧密合作。因此,AURORA积极与大众汽车集团、现代汽车等多家知名汽车制造商建立合作关系。通过共同研发和推广自动驾驶技术,AURORA成功帮助这些汽车厂商加速各自自动驾驶汽车的商用计划。这种深度合作不仅提升了AURORA的市场影响力,也为公司的长期发展奠定了坚实基础。

ETAL公司的发展小趣事

在产品质量和技术水平得到认可后,ETAL开始积极拓展市场。公司制定了详细的市场营销策略,通过参加国际电子展会、与知名企业合作等方式提高品牌知名度。同时,ETAL还注重客户服务,建立了完善的售后服务体系,确保客户在使用产品过程中得到及时、专业的支持。这些举措使得ETAL的市场份额不断扩大,品牌影响力逐渐增强。

长园维安(CYGWAYON)公司的发展小趣事

长园维安始终关注环保和可持续发展。公司积极推行绿色制造和循环经济模式,降低生产过程中的能耗和排放。同时,长园维安还注重产品环保性能的研发和改进,为客户提供更加环保、节能的产品。这些努力使长园维安在电子行业中树立了绿色发展的典范。

EEMB Co Ltd公司的发展小趣事

为了适应公司业务的快速发展和满足市场需求的不断增长,EEMB集团于2017年在汉川市修建了新工厂。新工厂占地面积120亩,使用面积达27000平方米,配备了先进的生产设备和技术。一期工程全面投入生产后,公司的产能得到了显著提升,能够更好地满足客户的订单需求。同时,新工厂的建成也进一步提升了公司的生产效率和产品质量。

问答坊 | AI 解惑

谁有mega8学习板的电路图啊!分享一下!谢谢!

哪位仁兄有mega8学习板的原理图,分享一下嘛!小弟我找了好久都没找到啊!:\'(…

查看全部问答>

Linux动态加载驱动模块的问题

本人初学驱动开发 照着例子写了个简单的GPIO驱动 控制开发板上的LED 可是动态加载驱动后显示错误 过程如下: 硬件:s3c2440开发板      GPB5-8接4个LED 软件:linux-2.6.29内核      arm-linux-gcc- ...…

查看全部问答>

请问有4路24位的TTL电平信号的数据采集怎么设计和选型?

模拟信号都好采集,但是有的传感器是BCD码输出的,每个传感器的引脚是24条线输出,有4个,请问怎么设计和选型? 这里面可能要用到数据选择器或者寄存器;还有USB控制器…

查看全部问答>

请教,USART中的LIN模式如何配置`

请教,USART中的LIN模式如何配置GPIO、RCC以及USART的初始化,我用的STM32f103的,哪位用过次芯片的高手赐教下~~~…

查看全部问答>

nand flash驱动unable to mount partition

我的nand flash驱动加载时可以创建分区,也可以找到对应的文件系统驱动,但却无法mount这个分区,所以也出现不了盘符,请大家帮帮忙啊~~…

查看全部问答>

怎样将手机的摄像头作为Wince设备的USB设备

我的手机有一个摄像头,而且可以以USB接口连接到桌面计算机上,作为摄像头使用。请问怎样在WinCE设备里也可以这样用呢?需要怎样开发相关驱动?…

查看全部问答>

显示器怎么了,显示brilho=0

我的电脑前些天还好好的现在开机显示器黑屏只显示Brilho=0 我拿去别的机子试了不是主机的问题,各位大哥大姐教教小第 我该怎么处理啊 显示器调节按钮 按了都没反应。…

查看全部问答>

VS2005调试目标机上应用程序时,用TCP/IP方式连接总是“设备未就绪”??

使用VS2005开发win ce的应用程序,在调试的时间用TCP/IP方式连接到开发板,老说“设备未就绪”,该怎么解决啊?…

查看全部问答>

请教,关于ADS编译C++的问题

请教,我用ads1.2编译c++程序总是报一些头文件找不到,我把system path加了vc的库,结果有出了“only win32 and Mac supported\"这个问题,请问怎么办?ads1.2上可以编译c++吗?要怎么做? …

查看全部问答>

stm8l的Waitmode

Wait mode: The CPU clock is stopped, but selected peripherals keep running. 想请教前辈如何使用这种模式,我不明白进入等待模式后外设工作的时钟源从哪里来,是不是要使能LSI ? CPU停止工作应该不代表HSI停止工作吧?  有 ...…

查看全部问答>