Advertisement
Guest User

lm3s608 - timer

a guest
Mar 24th, 2012
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Defines the base address of the memories and peripherals */
  2. #include "../../../inc/hw_memmap.h"
  3.  
  4. /* Defines the common types and macros */
  5. #include "../../../inc/hw_types.h"
  6.  
  7. #include "../../../inc/hw_timer.h"
  8.  
  9. #include "../../../driverlib/pin_map.h"
  10.  
  11. /* Defines and Macros for GPIO API */
  12. #include "../../../driverlib/gpio.h"
  13.  
  14. /* Prototypes for the system control driver */
  15. #include "../../../driverlib/sysctl.h"
  16.  
  17. #include "../../../driverlib/adc.h"
  18.  
  19. #include "../../../driverlib/uart.h"
  20.  
  21. #include "../../../driverlib/interrupt.h"
  22.  
  23. #include "../../../driverlib/uartstdio.h"
  24.  
  25. #include "driverlib/timer.h"
  26.  
  27.  
  28.  
  29.  
  30.  
  31. void UartInit(void)
  32. {
  33. // Enable GPIO port A which is used for UART0 pins.
  34. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  35. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  36.  
  37. /* Make the UART pins be peripheral controlled. */
  38. GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  39.  
  40. // Initialize the UART for console I/O.
  41. UARTStdioInit(0);
  42. }
  43.  
  44. void TimerInit(void)
  45. {
  46. /* The Timer0 peripheral must be enabled for use. */
  47. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  48.  
  49.  
  50. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
  51.  
  52.  
  53. // GPIOPinConfigure(CCP1_PIN);
  54.  
  55.  
  56. GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_5);
  57.  
  58. // Configure Timer0B as a 16-bit periodic timer.
  59. TimerConfigure(TIMER0_BASE, TIMER_CFG_B_PWM | TIMER_CFG_B_PERIODIC);
  60.  
  61. // Set the Timer0B load value to 1ms.
  62. TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet());
  63.  
  64. // Set the Timer0B match value to load value / 3.
  65. TimerMatchSet(TIMER0_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_B) / 3);
  66.  
  67. /* Control the Timer Level */
  68. //TimerControlLevel(TIMER0_BASE, TIMER_B, true);
  69.  
  70. /* Enable Timer0B. */
  71. TimerEnable(TIMER0_BASE, TIMER_B);
  72.  
  73. }
  74.  
  75. int main(void)
  76. {
  77. /*Set the clocking to directly run from the crystal at 7.37MHz*/
  78. SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_7_37MHZ);
  79.  
  80. /* UART config */
  81. UartInit();
  82.  
  83. TimerInit();
  84.  
  85.  
  86. while(1)
  87. {
  88. UARTprintf("Timer %40d\r",TimerValueGet(TIMER0_BASE, TIMER_B));
  89. SysCtlDelay(SysCtlClockGet()/12);
  90.  
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement