Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me fix my code: #include #include #include #include #include TM 4 C 1 2 3 GH 6 PM . h #include

Please help me fix my code:
#include
#include
#include
#include
#include "TM4C123GH6PM.h"
#include "MyDefines.h"
void Setup_GPIO(void);
void DelayMs (int ms);
#define CW 0
#define CCW 1
void StepperMotor(int s, bool direction);
typedef enum States {
S_1,
S_2
} STATES;
void toggleLed()
{
bool sw;
static STATES state = S_1;
// Read SW status to sw
sw = GPIOF ->DATA & (_PIN4);
switch (state){
case S_1:
if (sw == true){
//Change from S_1 to S_2
state = S_2;
// Toggle LED
GPIOF->DATA ^=(_PIN0);
}/* else {
state = S_1;
}*/
break;
case S_2:
break;
}
}
volatile uint32_t *Stepper =(uint32_t *)GPIOF +(_PIN4|_PIN0);
//------------------------------------------------------------------------------
int main()
{
int i =0;
bool SW1;
bool SW2;
Setup_GPIO();
*Stepper =0 ; // Step 0 value
while(1){
// If users press SW1, rotate CW for 5 steps
if (SW1==0){
StepperMotor(5,CW);
DelayMs(200);
// If users press SW2, rotate CCW for 5 steps
if (SW2==0){
StepperMotor(5, CCW);
DelayMs(200);
}
}
//------------------------------------------------------------------------------
void Setup_GPIO(void)
{
// GPIO Initialization and Configuration
//1. Enable Clock to the GPIO Modules (SYSCTL->RCGCGPIO |=(_PORTs);)
SYSCTL->RCGCGPIO |=(__);
// allow time for clock to stabilize (SYSCTL->PRGPIO)
while ((SYSCTL->PRGPIO & (_))!=(_)){};
//2. Unlock GPIO only PD7, PF0 on TM4C123G; PD7, PE7 on TM4C1294(GPIOx->LOCK =0x4C4F434B; and GPIOx->CR =_PINs;)
GPIOF->LOCK =0x4C4F434B; // Unlock for GPIOF
GPIOF->CR |=_PIN0; // Commit for PIN0
GPIOF->LOCK =0;
//3. Set Analog Mode Select bits for each Port (GPIOx->AMSEL =_PINs; 0=digital, 1=analog)
//4. Set Port Control Register for each Port (GPIOx->PCTL = PMCn <<_PTCL_PINn, check the PCTL table)
//5. Set Alternate Function Select bits for each Port (GPIOx->AFSEL =_PINs; 0=regular I/O,1=PCTL peripheral)
//6. Set Output pins for each Port (Direction of the Pins: GPIOx->DIR =_PINs; 0=input, 1=output)
//7. Set PUR bits for internal pull-up, PDR for pull-down reg, ODR for open drain (0: disable, 1=enable)
//8. Set Digital ENable register on all port.pins (GPIOx->DEN =_PINs; 0=disable, 1=enable)
}
//------------------------------------------------------------------------------
typedef enum STATES {
} STATES;
void StepperMotor(int s, bool direction)
{
static state = S_1;
int i;
for( i =0; i < s){
switch (state){
case S_1;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago