在线时间796 小时
UID3067179
注册时间2014-10-23
NXP金币1063
TA的每日心情 | 开心 3 天前 |
---|
签到天数: 1318 天 [LV.10]以坛为家III
版主
- 积分
- 7575
- 最后登录
- 2024-4-27
|
看完手册,先加电看看板子运行情况。
一、加电运行
硬件连接上,我连接了5V电源和串口线。
1.1、运行视频
加电后,LED1~LED4顺序点亮,同时串口有数据输出
1.2、串口输出数据:
二、硬件分析
2.1、LED驱动电路
LED1~LED4是通过PCA9551芯片来驱动的,使用的是I2C方式。
2.2、串口部分
串口使用的是UART0通信
2.3、AD采样部分
AD采样使用的是P0.25引脚对应的VAR1电位器
三、程序部分
开发板官网程序: LPC1768 Dev kit
3.1、下载下面程序文件:
打开后,项目文件使用的低版本的KEIL开编译的,后续修改成高版本KEIL工程文件,这里只看下对应的主程序部分
主程序:
- /******************************************************************************/
- /* 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) {
- PINCON->PINSEL10 = 0; /* Disable ETM interface, enable LEDs */
- 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++)
- {
- GPIO0->FIOSET |= (1<<7);
- for (j=0;LED_DELAY>j;j++);
- GPIO0->FIOCLR |= (1<<7);
- for (j=0;LED_DELAY>j;j++);
- }
- /* Enable and setup timer interrupt, start timer */
- // PCLKSEL0 |= (1 << 2); /* Timer0 PCLK = CCLK */
- TIM0->MR0 = 23999; /* 1msec = 24000-1 at 12.0 MHz */
- TIM0->MCR = 3; /* Interrupt and Reset on MR0 */
- 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 */
- SC->PCONP |= (1 << 12); /* Enable power to AD block */
- PINCON->PINSEL1 |= 0x40000; /* AD0.2 pin function select */
- PINCON->PINMODE1 &= ~(0x03 << 18); /* configure P0.25 as input */
- PINCON->PINMODE1 |= (0x02 << 18);
- ADC->ADINTEN = (1 << 2); /* CH2 enable interrupt */
- 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 (GPIO0->FIOPIN & (1<<7)) GPIO0->FIOCLR |= (1<<7);
- else GPIO0->FIOSET |= (1<<7);
- AdcPrintValue = AdcValue; /* Get unscaled value for printout */
- printf ("AD value = %d\n\r", AdcPrintValue);
- }
- if (0 == gLedFlashCounter) {
- gLedFlashCounter = gAdcCurrentValue;
- BlinkLed();
- }
- }
- }
复制代码
3.2、程序源码:
IRD-LPC1768-DEV.zip
(2.11 MB, 下载次数: 5)
|
|