为什么我的程序在板子上没有效果,我调试的,到 IntEnable(INT_TIMER0A); //使能定时器0外设 这一句就走不了了!
我是刚刚才自学的,是不是定时器要设置什么?
#include<hw_types.h>
#include<hw_memmap.h>
#include<hw_ints.h>
#include<interrupt.h>
#include<sysctl.h>
#include<gpio.h>
#include<timer.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define LED_PERIPH SYSCTL_PERIPH_GPIOB
#define LED_PORT GPIO_PORTB_BASE
#define LED_PINS GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
#define WD_PERIPH SYSCTL_PERIPH_GPIOA
#define WD_PORT GPIO_PORTA_BASE
#define WELA GPIO_PIN_5|GPIO_PIN_4
// 定义全局的系统时钟变量
ulong TheSysClock=12000000UL;
uchar table[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void delay(int a)
{
for(;a>0;a--);
}
uint s,s1,s2;
void clockInit(void)
{
SysCtlLDOSet(SYSCTL_LDO_2_50V); // 设置LDO输出电压
SysCtlClockSet(SYSCTL_USE_OSC | // 系统时钟设置
SYSCTL_OSC_MAIN | // 采用主振荡器
SYSCTL_XTAL_6MHZ | // 外接6MHz晶振
SYSCTL_SYSDIV_1); // 不分频
TheSysClock = SysCtlClockGet(); // 获取当前的系统时钟频率
}
void init()
{
clockInit();
SysCtlPeripheralEnable(LED_PERIPH); //使能数码管 段 管脚外设
GPIOPinTypeGPIOOutput(LED_PORT,LED_PINS); //
SysCtlPeripheralEnable(WD_PERIPH); //使能数码管 位 段 锁存段外设
GPIOPinTypeGPIOOutput(WD_PORT,WELA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //使能定时器0外设
TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER); //设置定时器0为周期触发模式
TimerLoadSet(TIMER0_BASE,TIMER_A,6000000); //定时1S
TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT); //设置定时器为溢出中断
IntEnable(INT_TIMER0A); //使能定时器0外设
IntMasterEnable(); //使能处理器
TimerEnable(TIMER0_BASE,TIMER_A); //启动定时器0
s=0;
}
void disp()
{
s1=s/10;
s2=s%10;
GPIOPinWrite(WD_PORT,WELA,0xDf); //开段选,关位选
GPIOPinWrite(LED_PORT,LED_PINS,table[s1]); //送段码
GPIOPinWrite(WD_PORT,WELA,0XEF); //开位选,关段选
GPIOPinWrite(LED_PORT,LED_PINS,0xEf); //送位码
delay(5000);
GPIOPinWrite(LED_PORT,LED_PINS,0xfF); //消隐
GPIOPinWrite(WD_PORT,WELA,0xDf); //开段选,关位选
GPIOPinWrite(LED_PORT,LED_PINS,table[s2]); //送段码
GPIOPinWrite(WD_PORT,WELA,0XEF); //开位选,关段选
GPIOPinWrite(LED_PORT,LED_PINS,0xDf); //送位码
delay(5000);
GPIOPinWrite(LED_PORT,LED_PINS,0xfF); //消隐
}
int main(void)
{
init();
while(1)
{
disp();
}
}
void TIMER0A_ISR(void)
{
TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
s++;
if(s==60)
{
s=0;
}
}
此帖出自
小平头技术问答
;
; External declarations for the interrupt handlers used by the application.
;
;******************************************************************************
EXTERN GPIOBIntHandler
EXTERN Timer0IntHandler
EXTERN Uart0IntHandler
;******************************************************************************
;
; The vector table.
;
;******************************************************************************
EXPORT __Vectors
__Vectors
DCD StackMem + Stack ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NmiSR ; NMI Handler
DCD FaultISR ; Hard Fault Handler
DCD IntDefaultHandler ; MPU Fault Handler
DCD IntDefaultHandler ; Bus Fault Handler
DCD IntDefaultHandler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD IntDefaultHandler ; SVCall Handler
DCD IntDefaultHandler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD IntDefaultHandler ; PendSV Handler
DCD IntDefaultHandler ; SysTick Handler
DCD IntDefaultHandler ; GPIO Port A
DCD GPIOBIntHandler ; GPIO Port B
DCD IntDefaultHandler ; GPIO Port C
DCD IntDefaultHandler ; GPIO Port D
DCD IntDefaultHandler ; GPIO Port E
DCD Uart0IntHandler ; UART0
DCD IntDefaultHandler ; UART1
DCD IntDefaultHandler ; SSI
DCD IntDefaultHandler ; I2C
DCD IntDefaultHandler ; PWM Fault
DCD IntDefaultHandler ; PWM Generator 0
DCD IntDefaultHandler ; PWM Generator 1
DCD IntDefaultHandler ; PWM Generator 2
DCD IntDefaultHandler ; Quadrature Encoder
DCD IntDefaultHandler ; ADC Sequence 0
DCD IntDefaultHandler ; ADC Sequence 1
DCD IntDefaultHandler ; ADC Sequence 2
DCD IntDefaultHandler ; ADC Sequence 3
DCD IntDefaultHandler ; Watchdog
DCD Timer0IntHandler ; Timer 0A
DCD IntDefaultHandler ; Timer 0B
DCD IntDefaultHandler ; Timer 1A
DCD IntDefaultHandler ; Timer 1B
DCD IntDefaultHandler ; Timer 2A
DCD IntDefaultHandler ; Timer 2B
DCD IntDefaultHandler ; Comp 0
DCD IntDefaultHandler ; Comp 1
DCD IntDefaultHandler ; Comp 2
DCD IntDefaultHandler ; System Control
DCD IntDefaultHandler ; Flash Control
DCD IntDefaultHandler ; GPIO Port F
DCD IntDefaultHandler ; GPIO Port G
DCD IntDefaultHandler ; GPIO Port H
DCD IntDefaultHandler ; UART2 Rx and Tx
DCD IntDefaultHandler ; SSI1 Rx and Tx
DCD IntDefaultHandler ; Timer 3 subtimer A
DCD IntDefaultHandler ; Timer 3 subtimer B
DCD IntDefaultHandler ; I2C1 Master and Slave
DCD IntDefaultHandler ; Quadrature Encoder 1
DCD IntDefaultHandler ; CAN0
DCD IntDefaultHandler ; CAN1
DCD IntDefaultHandler ; CAN2
DCD IntDefaultHandler ; Ethernet
DCD IntDefaultHandler ; Hibernate
DCD IntDefaultHandler ; USB0
DCD IntDefaultHandler ; PWM Generator 3
DCD IntDefaultHandler ; uDMA Software Transfer
DCD IntDefaultHandler ; uDMA Error
一周热门 更多>