在线时间990 小时
UID3359265
注册时间2017-3-4
NXP金币2436
TA的每日心情 | 奋斗 2 小时前 |
---|
签到天数: 2479 天 连续签到: 10 天 [LV.Master]伴坛终老
金牌会员
 
- 积分
- 11196
- 最后登录
- 2025-7-20
|
我还没到上班的时候,快递小哥借着公司没人,迟迟不送,催了几次才在昨天拿到。
看大家有些很早就拿到了,东西基本都差不多。照例,先跑例程。
FDI公司给的点灯例程:Blinky_with_IRD_LPC1768,我用的keil uVision5.24,报错很多啊...
包装盒上写的还是keil uVision3的版本,材料也是2009年的,看来主要是版本的问题。不过,10年前这套板子值不少钱啊。
看了下代码,例程大概的意思是:开发板启动后,左下角的4个LED灯依次点亮,然后熄灭。通过ADC采样VR1可调电阻,调节可调电阻VR1,改变闪烁的频率。
根据原理图,LED1-4是由PCA9551PW驱动的,这是一款8位I²C总线LED驱动器,具有可编程闪烁速率。任何不用于控制LED的位均可用作通用并行输入/输出(GPIO)扩展。
本开发套件的前四个输出PIN4-7接了SW1-4的按键,并没有接LED。后四位输出PIN9-12接了LED1-4。采用I2C总线输入,PIN15与14分别接LPC1768的P0.27和P0.28管脚,其工作在SDA0和SCL0模式。
VR1可调电阻接于LPC1768的P0.25管脚,其配置为ADC输入,引脚的数字部分禁能AD0.2。
修改例程如下:
- /******************************************************************************/
- /* BLINKY.C: LED Flasher */
- /******************************************************************************/
- /* This file is part of the uVision/ARM development tools. */
- /* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
- /* This software may only be used under the terms of a valid, current, */
- /* end user licence from KEIL for a compatible version of KEIL software */
- /* development tools. Nothing else gives you the right to use this software. */
- /******************************************************************************/
-
- #include "Blinky.h"
- /* Function that initializes LEDs */
- void InitLed (void) {
- LPC_PINCON->PINSEL10 = 0; /* Disable ETM interface, enable LEDs */
- LPC_GPIO0->FIODIR = (1<<7); /* P0.7 defined as Outputs */
- }
- void BlinkLed (void) {
- /* Blink the LEDs on IRD board */
- const INT8U LedValue[8] = { 0x01,0x03,0x07,0x0F,0x0E,0x0C,0x08,0x00 };
- static INT32U LedCount;
- I2cLedOut(LedValue[LedCount]);
- if (++LedCount >= sizeof(LedValue)) {
- LedCount = 0;
- }
- }
- int main (void) {
- INT32U i,j;
- INT16U AdcValue, AdcPrintValue;
-
- SystemInit();
- InitLed(); /* LED Initialization */
- for (i=0;10>i;i++)
- {
- LPC_GPIO0->FIOSET |= (1<<7);
- for (j=0;LED_DELAY>j;j++);
- LPC_GPIO0->FIOCLR |= (1<<7);
- for (j=0;LED_DELAY>j;j++);
- }
- /* Enable and setup timer interrupt, start timer */
- // PCLKSEL0 |= (1 << 2); /* Timer0 PCLK = CCLK */
- LPC_TIM0->MR0 = 23999; /* 1msec = 24000-1 at 12.0 MHz */
- LPC_TIM0->MCR = 3; /* Interrupt and Reset on MR0 */
- LPC_TIM0->TCR = 1; /* Timer0 Enable */
- //// VICVectAddr4 = (INT32U)T0_IRQHandler; /* Set Interrupt Vector */
- //// VICVectCntl4 = 15; /* use it for Timer0 Interrupt */
- //// VICIntEnable = (1 << 4); /* Enable Timer0 Interrupt */
- NVIC_EnableIRQ( TIMER0_IRQn ); //// Enable Timer 0 IRQ
- /* Power enable, Setup pin, enable and setup AD converter interrupt */
- LPC_SC->PCONP |= (1 << 12); /* Enable power to AD block */
- LPC_PINCON->PINSEL1 |= 0x40000; /* AD0.2 pin function select */
- LPC_PINCON->PINMODE1 &= ~(0x03 << 18); /* configure P0.25 as input */
- LPC_PINCON->PINMODE1 |= (0x02 << 18);
- LPC_ADC->ADINTEN = (1 << 2); /* CH2 enable interrupt */
- LPC_ADC->ADCR = 0x00200304; /* Power up, PCLK/4, sel AD0.2 */
- //// VICVectAddr18 = (INT32U)ADC_IRQHandler; /* Set Interrupt Vector */
- //// VICVectCntl18 = 14; /* use it for ADC Interrupt */
- //// VICIntEnable = (1 << 18); /* Enable ADC Interrupt */
- NVIC_EnableIRQ( ADC_IRQn );
- InitI2c (); /* Init I2C */
- InitSerial(); /* Init UART */
- while (1) { /* Loop forever */
- AdcValue = gAdcCurrentValue; /* Read AD_last value */
-
- if (g1sCounter) {
- g1sCounter = 0;
-
- if (LPC_GPIO0->FIOPIN & (1<<7)) LPC_GPIO0->FIOCLR |= (1<<7);
- else LPC_GPIO0->FIOSET |= (1<<7);
- AdcPrintValue = AdcValue; /* Get unscaled value for printout */
- printf ("AD value = %d\n\r\n", AdcPrintValue);
- }
- if (0 == gLedFlashCounter) {
- gLedFlashCounter = gAdcCurrentValue;
- BlinkLed();
- }
- }
- }
复制代码
编译下载后,点灯成功。实际测试:对VR1逆时针调节LED闪烁变快,顺时针调节变慢。
|
|