Answered step by step
Verified Expert Solution
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 TMCGHPMh
#include "MyDefines.h
void SetupGPIOvoid;
void DelayMs int ms;
#define CW
#define CCW
void StepperMotorint s bool direction;
typedef enum States
S
S
STATES;
void toggleLed
bool sw;
static STATES state S;
Read SW status to sw
sw GPIOF DATA & PIN;
switch state
case S:
if sw true
Change from S to S
state S;
Toggle LED
GPIOFDATA PIN;
else
state S;
break;
case S:
break;
volatile uintt Stepper uintt GPIOF PINPIN;
int main
int i ;
bool SW;
bool SW;
SetupGPIO;
Stepper ; Step value
while
If users press SW rotate CW for steps
if SW
StepperMotorCW;
DelayMs;
If users press SW rotate CCW for steps
if SW
StepperMotor CCW;
DelayMs;
void SetupGPIOvoid
GPIO Initialization and Configuration
Enable Clock to the GPIO Modules SYSCTLRCGCGPIO PORTs;
SYSCTLRCGCGPIO ;
allow time for clock to stabilize SYSCTLPRGPIO
while SYSCTLPRGPIO & ;
Unlock GPIO only PD PF on TMCG; PD PE on TMCGPIOxLOCK xCFB; and GPIOxCR PINs;
GPIOFLOCK xCFB; Unlock for GPIOF
GPIOFCR PIN; Commit for PIN
GPIOFLOCK ;
Set Analog Mode Select bits for each Port GPIOxAMSEL PINs; digital, analog
Set Port Control Register for each Port GPIOxPCTL PMCn PTCLPINn, check the PCTL table
Set Alternate Function Select bits for each Port GPIOxAFSEL PINs; regular IOPCTL peripheral
Set Output pins for each Port Direction of the Pins: GPIOxDIR PINs; input, output
Set PUR bits for internal pullup PDR for pulldown reg, ODR for open drain : disable, enable
Set Digital ENable register on all port.pins GPIOxDEN PINs; disable, enable
typedef enum STATES
STATES;
void StepperMotorint s bool direction
static state S;
int i;
for i ; i s
switch state
case S;
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