完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
如果要定时相应的时间定时器该怎么配置?
|
|
相关推荐
3 个讨论
|
|
可以参考这个例程
//***************************************************************************** // // periodic_16bit.c - Example demonstrating a periodic 16-bit timer. // // Copyright (c) 2010-2015 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // This is part of revision 2.1.1.71 of the Tiva Firmware Development Package. // //***************************************************************************** #include #include #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/timer.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" //***************************************************************************** // //! addtogroup timer_examples_list //! 16-Bit Periodic Timer (periodic_16bit)//! //! This example shows how to configure Timer0B as a periodic timer with an //! interrupt triggering every 1ms. After a certain number of interrupts, the //! Timer0B interrupt will be disabled. //! //! This example uses the following peripherals and I/O signals. You must //! review these and change as needed for your own board: //! - TIMER0 peripheral //! //! The following UART signals are configured only for displaying console //! messages for this example. These are not required for operation of //! Timer0. //! - UART0 peripheral //! - GPIO Port A peripheral (for UART0 pins) //! - UART0RX - PA0 //! - UART0TX - PA1 //! //! This example uses the following interrupt handlers. To use this example //! in your own application you must add these interrupt handlers to your //! vector table. //! - INT_TIMER0B - Timer0BIntHandler // //***************************************************************************** //***************************************************************************** // // Number of interrupts before the timer gets turned off. // //***************************************************************************** #define NUMBER_OF_INTS 1000 //***************************************************************************** // // Counter to count the number of interrupts that have been called. // //***************************************************************************** static volatile uint32_t g_ui32Counter = 0; //***************************************************************************** // // This function sets up UART0 to be used for a console to display information // as the example is running. // //***************************************************************************** void InitConsole(void) [ // // Enable GPIO port A which is used for UART0 pins. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for UART0 functions on port A0 and A1. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); // // Enable UART0 so that we can configure the clock. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Use the internal 16MHz oscillator as the UART clock source. // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Select the alternate (UART) function for these pins. // TODO: change this to select the port/pin you are using. // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, 16000000); ] //***************************************************************************** // // The interrupt handler for the Timer0B interrupt. // //***************************************************************************** void Timer0BIntHandler(void) [ // // Clear the timer interrupt flag. // TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // // Update the periodic interrupt counter. // g_ui32Counter++; // // Once NUMBER_OF_INTS interrupts have been received, turn off the // TIMER0B interrupt. // if(g_ui32Counter == NUMBER_OF_INTS) [ // // Disable the Timer0B interrupt. // IntDisable(INT_TIMER0B); // // Turn off Timer0B interrupt. // TimerIntDisable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // // Clear any pending interrupt flag. // TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); ] ] //***************************************************************************** // // Configure Timer0B as a 16-bit periodic counter with an interrupt // every 1ms. // //***************************************************************************** int main(void) [ #if defined(TARGET_IS_TM4C129_RA0) || defined(TARGET_IS_TM4C129_RA1) || defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif uint32_t ui32PrevCount = 0; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // #if defined(TARGET_IS_TM4C129_RA0) || defined(TARGET_IS_TM4C129_RA1) || defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // The Timer0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for Timer operation. // InitConsole(); // // Display the example setup on the console. // UARTprintf("16-Bit Timer Interrupt ->"); UARTprintf("n Timer = Timer0B"); UARTprintf("n Mode = Periodic"); UARTprintf("n Number of interrupts = %d", NUMBER_OF_INTS); UARTprintf("n Rate = 1msnn"); // // Configure Timer0B as a 16-bit periodic timer. // TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); // // Set the Timer0B load value to 1ms. // #if defined(TARGET_IS_TM4C129_RA0) || defined(TARGET_IS_TM4C129_RA1) || defined(TARGET_IS_TM4C129_RA2) TimerLoadSet(TIMER0_BASE, TIMER_B, ui32SysClock / 1000); #else TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000); #endif // // Enable processor interrupts. // IntMasterEnable(); // // Configure the Timer0B interrupt for timer timeout. // TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // // Enable the Timer0B interrupt on the processor (NVIC). // IntEnable(INT_TIMER0B); // // Initialize the interrupt counter. // g_ui32Counter = 0; // // Enable Timer0B. // TimerEnable(TIMER0_BASE, TIMER_B); // // Loop forever while the Timer0B runs. // while(1) [ // // If the interrupt count changed, print the new value // if(ui32PrevCount != g_ui32Counter) [ // // Print the periodic interrupt counter. // UARTprintf("Number of interrupts: %dr", g_ui32Counter); ui32PrevCount = g_ui32Counter; ] ] ] |
|
|
|
|
|
只有小组成员才能发言,加入小组>>
TMS320F28377D:新做了以377d为芯片的板子,上电后芯片复位引脚出现方波请问如何解决?
1888 浏览 0 评论
TPS55340通电后输入端保险丝烧断,芯片输入和GND之间短路
3641 浏览 4 评论
5027 浏览 0 评论
请问如何用DM368对RGB格式的图片数据进行编码生成JPEG格式图片?
1732 浏览 1 评论
9353 浏览 8 评论
CC3100BOOST使用CC3200lunchXL进行烧录
664浏览 2评论
707浏览 1评论
TMS320F28034: 利用C2prog通过SCI给TMS320F28034烧录程序,出现错误提示:Bootloading... failed (invalid echo)!
668浏览 1评论
1186浏览 1评论
求DLPC350 Programmer’s Guide User's Guide 中文版说明书
1189浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-20 08:46 , Processed in 0.693787 second(s), Total 56, Slave 48 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号