- Get link
- X
- Other Apps
Timer interrupt program using TM4C123GH6PM
Program
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
int main(void) {
uint32_t ui32Period;
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = 20000000;
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period - 1);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
while (1) {
}
}
void timerinterrupt(void) {
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the GPIO pin and+
// write back the opposite state
if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) {
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2, 0x00);
} else {
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x04);
}
}
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
int main(void) {
uint32_t ui32Period;
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = 20000000;
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period - 1);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
while (1) {
}
}
void timerinterrupt(void) {
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the GPIO pin and+
// write back the opposite state
if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) {
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2, 0x00);
} else {
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x04);
}
}
Procedure
1. Create a new folder on desktop location.
2.
Open cc studio on desktop.
3.
Browse the workspace location
Click on browseàdesktopàselect created folderàok button.
4.
ccstudio wizard is opened
Click on projectànew ccs projectàtarget [select Tiva c series].
5.
Select microcontroller “Tiva
TM4C123GH6PM”, click on connection and select
“Stellaris in-circuit debug interface”.
6. Name the project in project name bar and click on finish button.
7.
Click on restore button on left side.
8.
Now unfold the project and right click on project and select properties.
9.
Select include optionsàaddàbrowseàmy computeràlocal disc
càtiàTivaware_c_series_2.1.2.111àok. Now directory path is added
to
project then click on ok button.
10.
Select projectà Right click on
project à add files à select local disc cà
select tià
Tivaware_c_series_2.1.2.111 àselect driverlib
à ccs à debug à driverlib.lib à open button.
11. Select copy files and click ok button. Now
driver library file is added to the project.
12.
Enter the program and click on save button[ctrl+s].
13.
In Line
no 25 select the word TIMER INTERRUPTàright
click on that and select copy(ctrl+c).
14. select tm4c123gh6pm_startup_ccs.c and click on line no 44 and enter Extern void timer interrupt (void);[The word timer interrupt is copied from line no 25 and has been paste in line 44(ctrl+v)].
15.
Select line no 105 and delete itànow paste the word TIMER INTERRUPT in this lineàclick save button and close this
file(tm4c123gh6pm_startup_ccs.c).
16.
To build the project click on Build
button.
17. After building the project is finished. Connect TM4C launch pad to pc using USB cable.
18. Before debugging set the launch pad in debug mode by pushing wake up pin and click on debug button in
ccstudio. Then click on resume
button
TM4C123GH6PM Overall Documentation in video description
Video 👇
Comments
Post a Comment