在线时间954 小时
UID336767
注册时间2011-12-29
NXP金币611
TA的每日心情 | 开心 2018-7-23 21:04 |
---|
签到天数: 103 天 [LV.6]常住居民II
金牌会员
- 积分
- 15343
- 最后登录
- 1970-1-1
|
继续学习状态可配置定时器SCT。
之前学习了基本的状态变换实现控制LED闪烁,可见【LPC824lite】SCT状态机输出,虽然不占用CPU,但是闪烁时需要用2个状态,2个事件。
其实可以只是用一个事件就可以实现,这时就需要冲突解决寄存器的控制。
在参考手册中有相关寄存器的描述,通过下面描述我们可以看到,可对一个事件设置输出OUT的SET和CLR动作,这样当事件被触发时,必然会冲突,该SET还是CLR呢,这是就由冲突解决寄存器来完成,可以设置SET或CLR起作用,当然也可以设置为TOGGLE,这时就可以自动的将SET和CLR事件交替执行实现引脚翻转了。
发现库中有这个函数,有相应的说明
其实到目前为止,感觉LPC824的这个库基本上是可有可无的,因为SCT部分有很多直接寄存器操作了!
开发板的LED1接到P0.7
开关矩阵将SCT的OUT0连接到P0.7上
SCT的初始化函数
在主函数中直接调用初始化函数,之后闪烁由系统自动完成
完整程序:
- /*
- ===============================================================================
- Name : 011_lpc824_sct_conflict.c
- Author : $(lkl0305)
- Version : 1.0
- Copyright : $(copyright)
- Description : main definition
- ===============================================================================
- */
- #if defined (__USE_LPCOPEN)
- #if defined(NO_BOARD_LIB)
- #include "chip.h"
- #else
- #include "board.h"
- #endif
- #endif
- #include <cr_section_macros.h>
- // TODO: insert other include files here
- // TODO: insert other definitions and declarations here
- void SCT_Init(void)
- {
- Chip_SCT_Init(LPC_SCT);
- Chip_SCT_Config(LPC_SCT, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK);
- Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
- Chip_SWM_DisableFixedPin(SWM_FIXED_ADC0);
- Chip_SWM_MovablePinAssign(SWM_SCT_OUT0_O, 7);
- Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
- LPC_SCT->STATE_U = 0x00000000;
- LPC_SCT->REGMODE_U = 0x00000000;
- Chip_SCT_SetMatchCount(LPC_SCT, SCT_MATCH_0, SystemCoreClock / 1);
- Chip_SCT_SetMatchReload(LPC_SCT, SCT_MATCH_0, SystemCoreClock / 1);
- LPC_SCT->EV[0].STATE = (1 << 0);
- LPC_SCT->EV[0].CTRL = (0 << 0) | (1 << 12);
- LPC_SCT->OUT[0].CLR = (1 << 0);
- LPC_SCT->OUT[0].SET = (1 << 0);
- Chip_SCT_SetConflictResolution(LPC_SCT, 0, SCT_RES_TOGGLE_OUTPUT);
- LPC_SCT->LIMIT_U |= (1 << 0);
- Chip_SCT_ClearControl(LPC_SCT, SCT_CTRL_HALT_L);
- }
- int main(void) {
- #if defined (__USE_LPCOPEN)
- // Read clock settings and update SystemCoreClock variable
- SystemCoreClockUpdate();
- #if !defined(NO_BOARD_LIB)
- // Set up and initialize all required blocks and
- // functions related to the board hardware
- Board_Init();
- // Set the LED to the state of "On"
- // Board_LED_Set(0, true);
- #endif
- #endif
- // TODO: insert code here
- SCT_Init();
- // Force the counter to be placed into memory
- volatile static int i = 0 ;
- // Enter an infinite loop, just incrementing a counter
- while(1) {
- i++ ;
- }
- return 0 ;
- }
复制代码
文件下载:
011_lpc824_sct_conflict.rar
(996 Bytes, 下载次数: 14)
|
|