各位路过的TX,我是一个入门者,前段时间拿到了TI LM3S 811评估板, 在练习32位周期触发模式,但是LED就是没有反应,纠结中...
其实也是参考黄智伟先生编写的32位ARM微控制器系统设计与实践第四章的例程.
请帮忙看看程序哪儿有问题,编译通过,就是LED无反应. 谢谢啦#define HWREG(x) (*((volatile unsigned long*)(x)))
#define SYSCTL_RCGC1 0x400fe104
//时钟选通控制寄存器,TIMER0选通#define SYSCTL_RCGC2 0x400fe108
//GPIOC接收时钟并运行#define SYSCTL_PERIPH_GPIOC 0x00000004#define SYSCTL_PERIPH_TIMER0 0x00010000
//依据时钟选通控制寄存器RCGCCn位定义
#define TIMER0_BASE 0x40030000#define TIMER_0_CTL 0x0000000c#define TIMER_0_CFG 0x00000000#define TIMER_0_TAMR 0x00000004#define TIMER_0_IMR 0x00000018#define TIMER_0_ICR 0x00000024#define TIMER_0_TAILR 0x00000028
#define TIMER_CTL_TEAN 0x00000001#define TIMER_CFG_32_BIT_OS 0x00000001#define TIMER_CFG_32_BIT_PER 0x00000002#define TIMER_A 0x000000ff#define TIMER_TIMA_TIMEOUT 0x00000001#define TIMER_INT_DATA 15000000
#define NVIC_EN0 0xe000e100#define INT_GPIOA 16#define INT_TIMER0A 35
#define GPIO_PORTC_BASE 0x40006000#define GPIO_0_DIR 0x00000400#define GPIO_0_AFSEL 0x00000420#define GPIO_0_DATA 0x00000000#define GPIO_0_DR2R 0x00000500#define GPIO_0_ODR 0x0000050c#define GPIO_0_DEN 0x0000051c
#define PINS1 0x00000020 // GPIO pin 5
__asm void CPUcpsie (void){
CPSIE I
BX LR}
void Timer0A_ISR(void){ HWREG(TIMER0_BASE+TIMER_0_ICR) = TIMER_TIMA_TIMEOUT; HWREG(GPIO_PORTC_BASE+(GPIO_0_DATA+(PINS1<<2))) =(HWREG(GPIO_PORTC_BASE+(GPIO_0_DATA)+(PINS1<<2)))^PINS1; HWREG(TIMER0_BASE+TIMER_0_CTL)|=TIMER_A&(TIMER_CTL_TEAN);}
int main(void){ HWREG(SYSCTL_RCGC1)|=SYSCTL_PERIPH_TIMER0 & 0x0ffffffff; HWREG(SYSCTL_RCGC2)|=SYSCTL_PERIPH_GPIOC & 0x0ffffffff;
HWREG(GPIO_PORTC_BASE+GPIO_0_DIR)|=PINS1; //GPIOPORTC5设置为输出 HWREG(GPIO_PORTC_BASE+GPIO_0_AFSEL)&=~PINS1; //GPIOPROTC5定义为普通I/O口 HWREG(GPIO_PORTC_BASE+GPIO_0_DR2R)|=PINS1; //2mA驱动 //HWREG(GPIO_PORTC_BASE+GPIO_0_ODR)|=PINS1; HWREG(GPIO_PORTC_BASE+GPIO_0_DEN)|=PINS1;
HWREG(GPIO_PORTC_BASE+(GPIO_0_DATA+(PINS1<<2)))=~PINS1;
HWREG(TIMER0_BASE+TIMER_0_CTL)&=~(TIMER_CTL_TEAN);
//禁止TIMER0 HWREG(TIMER0_BASE+TIMER_0_CFG)= TIMER_CFG_32_BIT_OS>>24;
//配置GPTMCFG为32为定时器模式,但右移24位why? HWREG(TIMER0_BASE+TIMER_0_TAMR)= TIMER_CFG_32_BIT_PER&255;
//配置为周期定时器模式 HWREG(TIMER0_BASE+TIMER_0_TAILR)= TIMER_INT_DATA /4;
//装载间隔值 HWREG(TIMER0_BASE+TIMER_0_IMR)|=TIMER_TIMA_TIMEOUT;
//TIMERA0中断使能 HWREG(TIMER0_BASE+TIMER_0_CTL)|=TIMER_A&(TIMER_CTL_TEAN);
//启动TIMER0 HWREG(NVIC_EN0)=1<<(INT_TIMER0A-INT_GPIOA);
//使能TIEMER0中断 CPUcpsie(); while(1);}
此帖出自
小平头技术问答
如果是直接操作寄存器方式,还得注意添加必要的延时处理。
一周热门 更多>