Question
#include inc/tm4c123gh6pm.h #include #define NVIC_ST_CTRL_COUNT 0x00010000 // Count flag #define NVIC_ST_CTRL_CLK_SRC 0x00000004 // Clock Source #define NVIC_ST_CTRL_INTEN 0x00000002 // Interrupt enable #define NVIC_ST_CTRL_ENABLE 0x00000001 //
#include "inc/tm4c123gh6pm.h"
#include
#define NVIC_ST_CTRL_COUNT 0x00010000 // Count flag
#define NVIC_ST_CTRL_CLK_SRC 0x00000004 // Clock Source
#define NVIC_ST_CTRL_INTEN 0x00000002 // Interrupt enable
#define NVIC_ST_CTRL_ENABLE 0x00000001 // Counter mode
#define NVIC_ST_RELOAD_M 0x00FFFFFF // Counter load value
void SysTick_Init(void){
NVIC_ST_CTRL_R = 0; // disable SysTick during setup
NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M; // maximum reload value
NVIC_ST_CURRENT_R = 0; // any write to current clears it
// enable SysTick with core clock
NVIC_ST_CTRL_R = NVIC_ST_CTRL_ENABLE+NVIC_ST_CTRL_CLK_SRC;
}
void SysTick_Wait(uint32_t delay){
volatile uint32_t elapsedTime;
uint32_t startTime = NVIC_ST_CURRENT_R;
do{
elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF;
}
while(elapsedTime <= delay);
}
void SysTick_Wait10ms(uint32_t delay){
uint32_t i;
for(i=0; i SysTick_Wait(500000); // wait 10ms (assumes 50 MHz clock) } } void GPIO_Init(void){ SYSCTL_RCGCGPIO_R |= 0x12; // 1) activate port E, and B while((SYSCTL_PRGPIO_R&0x012)==0){}; // allow time for clock to stabilize // 2) no need to unlock PD1-0 GPIO_PORTD_DIR_R |= 0x2C; // 3) make PD2 & 3 & 5 outputs GPIO_PORTD_DIR_R &= ~0x03; // 3) make PE0 & PE1 input GPIO_PORTD_AFSEL_R &= ~0x0B; // 4) regular port function GPIO_PORTD_DEN_R |= 0x12; // 5) enable digital I/O on PD2, 3, &5 } int main(void){ GPIO_Init(); SysTick_Init(); while(1){ if( (GPIO_PORTD_DATA_R & 0x09) == 0x09){ GPIO_PORTD_DATA_R |= 0x02; SysTick_Wait10ms(10); while ( (GPIO_PORTD_DATA_R & 0x09) == 0x09){ GPIO_PORTD_DATA_R |= 0x04; } } else if( (GPIO_PORTD_DATA_R & 0x09) == 0x01){ GPIO_PORTD_DATA_R = 0x04; SysTick_Wait10ms(10); GPIO_PORTD_DATA_R = 0x00; SysTick_Wait10ms(10);} else if( (GPIO_PORTD_DATA_R & 0x09) == 0x08){ GPIO_PORTD_DATA_R ^= 0x02; SysTick_Wait10ms(10); GPIO_PORTD_DATA_R ^= 0x04; SysTick_Wait10ms(10); } else GPIO_PORTD_DATA_R &= ~0x02; GPIO_PORTD_DATA_R &= ~0x04; } } for how to build be the rare code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started