查看: 4027|回复: 1

[原创] 【LPC1768】1.改例程,点灯

[复制链接]
  • TA的每日心情
    奋斗
    2 小时前
  • 签到天数: 2479 天

    连续签到: 10 天

    [LV.Master]伴坛终老

    17

    主题

    5354

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    11196
    最后登录
    2025-7-20
    发表于 2019-2-18 13:17:28 | 显示全部楼层 |阅读模式
    我还没到上班的时候,快递小哥借着公司没人,迟迟不送,催了几次才在昨天拿到。
    看大家有些很早就拿到了,东西基本都差不多。照例,先跑例程。

    000.jpg
    FDI公司给的点灯例程:Blinky_with_IRD_LPC1768,我用的keil uVision5.24,报错很多啊...
    包装盒上写的还是keil uVision3的版本,材料也是2009年的,看来主要是版本的问题。不过,10年前这套板子值不少钱啊。

    看了下代码,例程大概的意思是:开发板启动后,左下角的4个LED灯依次点亮,然后熄灭。通过ADC采样VR1可调电阻,调节可调电阻VR1,改变闪烁的频率。
    PCA9551.JPG
    根据原理图,LED1-4是由PCA9551PW驱动的,这是一款8位I²C总线LED驱动器,具有可编程闪烁速率。任何不用于控制LED的位均可用作通用并行输入/输出(GPIO)扩展。
    12 - 副本.jpg
    本开发套件的前四个输出PIN4-7接了SW1-4的按键,并没有接LED。后四位输出PIN9-12接了LED1-4。采用I2C总线输入,PIN15与14分别接LPC1768的P0.27和P0.28管脚,其工作在SDA0和SCL0模式。
    VR1.JPG
    VR1可调电阻接于LPC1768的P0.25管脚,其配置为ADC输入,引脚的数字部分禁能AD0.2。

    修改例程如下:
    1. /******************************************************************************/
    2. /* BLINKY.C: LED Flasher                                                      */
    3. /******************************************************************************/
    4. /* This file is part of the uVision/ARM development tools.                    */
    5. /* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
    6. /* This software may only be used under the terms of a valid, current,        */
    7. /* end user licence from KEIL for a compatible version of KEIL software       */
    8. /* development tools. Nothing else gives you the right to use this software.  */
    9. /******************************************************************************/
    10.                   
    11. #include "Blinky.h"

    12. /* Function that initializes LEDs                                             */
    13. void InitLed (void) {
    14.   LPC_PINCON->PINSEL10 = 0;                      /* Disable ETM interface, enable LEDs */
    15.   LPC_GPIO0->FIODIR  = (1<<7);                   /* P0.7 defined as Outputs            */
    16. }

    17. void BlinkLed (void) {
    18.    /* Blink the LEDs on IRD board */
    19.    const INT8U LedValue[8] = { 0x01,0x03,0x07,0x0F,0x0E,0x0C,0x08,0x00 };
    20.    static INT32U LedCount;

    21.    I2cLedOut(LedValue[LedCount]);
    22.    if (++LedCount >= sizeof(LedValue)) {
    23.       LedCount = 0;
    24.    }
    25. }

    26. int main (void) {
    27.   INT32U i,j;
    28.   INT16U AdcValue, AdcPrintValue;
    29.        
    30.   SystemInit();
    31.   InitLed();                                   /* LED Initialization          */

    32.   for (i=0;10>i;i++)
    33.   {
    34.      LPC_GPIO0->FIOSET |= (1<<7);
    35.      for (j=0;LED_DELAY>j;j++);
    36.      LPC_GPIO0->FIOCLR |= (1<<7);
    37.      for (j=0;LED_DELAY>j;j++);
    38.   }

    39.   /* Enable and setup timer interrupt, start timer                            */
    40. //  PCLKSEL0     |= (1 << 2);                    /* Timer0 PCLK = CCLK          */
    41.   LPC_TIM0->MR0         = 23999;                   /* 1msec = 24000-1 at 12.0 MHz */
    42.   LPC_TIM0->MCR         = 3;                       /* Interrupt and Reset on MR0  */
    43.   LPC_TIM0->TCR         = 1;                       /* Timer0 Enable               */
    44. ////  VICVectAddr4  = (INT32U)T0_IRQHandler;       /* Set Interrupt Vector        */
    45. ////  VICVectCntl4  = 15;                          /* use it for Timer0 Interrupt */
    46. ////  VICIntEnable  = (1 << 4);                    /* Enable Timer0 Interrupt     */
    47.   NVIC_EnableIRQ( TIMER0_IRQn );                  //// Enable Timer 0 IRQ


    48.   /* Power enable, Setup pin, enable and setup AD converter interrupt         */
    49.   LPC_SC->PCONP        |= (1 << 12);                   /* Enable power to AD block    */
    50.   LPC_PINCON->PINSEL1  |= 0x40000;                     /* AD0.2 pin function select   */
    51.   LPC_PINCON->PINMODE1 &= ~(0x03 << 18);               /* configure P0.25 as input    */
    52.   LPC_PINCON->PINMODE1 |= (0x02 << 18);
    53.   LPC_ADC->ADINTEN      = (1 << 2);                    /* CH2 enable interrupt        */
    54.   LPC_ADC->ADCR         = 0x00200304;                  /* Power up, PCLK/4, sel AD0.2 */
    55. ////  VICVectAddr18     = (INT32U)ADC_IRQHandler;      /* Set Interrupt Vector       */
    56. ////  VICVectCntl18     = 14;                          /* use it for ADC Interrupt    */
    57. ////  VICIntEnable      = (1 << 18);                   /* Enable ADC Interrupt        */
    58.   NVIC_EnableIRQ( ADC_IRQn );

    59.   InitI2c ();                                  /* Init I2C                    */
    60.   InitSerial();                                /* Init UART                   */

    61.   while (1) {                           /* Loop forever                       */
    62.     AdcValue = gAdcCurrentValue;        /* Read AD_last value                 */
    63.    
    64.     if (g1sCounter) {
    65.       g1sCounter = 0;
    66.       
    67.       if (LPC_GPIO0->FIOPIN & (1<<7))   LPC_GPIO0->FIOCLR |= (1<<7);
    68.       else LPC_GPIO0->FIOSET |= (1<<7);

    69.       AdcPrintValue = AdcValue;           /* Get unscaled value for printout    */
    70.       printf ("AD value = %d\n\r\n", AdcPrintValue);
    71.     }

    72.     if (0 == gLedFlashCounter) {
    73.        gLedFlashCounter = gAdcCurrentValue;
    74.        BlinkLed();
    75.     }
    76.   }
    77. }
    复制代码

    11.jpg
    编译下载后,点灯成功。实际测试:对VR1逆时针调节LED闪烁变快,顺时针调节变慢。

    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    1 小时前
  • 签到天数: 1847 天

    连续签到: 2 天

    [LV.Master]伴坛终老

    203

    主题

    3万

    帖子

    64

    超级版主

    Rank: 8Rank: 8

    积分
    112625
    最后登录
    2025-7-20
    发表于 2019-2-18 14:28:10 | 显示全部楼层
    支持一下
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-20 23:57 , Processed in 0.084908 second(s), 21 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表