Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this program code for Code Warrior Write a C language program to drive the stepper motor. The motor will have two

I need help with this program code for Code Warrior

Write a C language program to drive the stepper motor. The motor will have two speeds (fast and slow) and two directions (forward or backward). For the stepper motor to work, the Motor Enable switch must be set to the left position. The stepper motor is controlled by bits 3-0 of Port D. To run the stepper motor, appropriate bits of this port must be made outputs by writing ones to the data direction register for Port D. Bits from the dip switch connected to Port B are used to check the desired motor speed and direction. If bit 1 is high the motor should turn in a forward direction and if bit 1 is low the motor should turn in the backwards direction. If bit 2 of port B is high, the motor should turn at the slower speed and if bit 2 of port B is low it should turn at the faster speed.

The following commands are sent to the motor to turn it. Each command steps the motor one step. There must be a delay between each command sent to the motor.

Port D: Bit 3 Bit 2 Bit 1 Bit 0 Hex value step

0 1 0 1 = 0x05

1 0 0 1 = 0x09

1 0 1 0 = 0x0A

0 1 1 0 = 0x06

Your program should have no global variables and at least three C language functions. One should step the motor and another should delay. A main function should call these two functions.

Function Descriptions:

A Step Motor Function will determine and send one appropriate value to the stepper motor and then ends (release control back to the main function).

o This function is called from main()

o In the step motor function:

A character array defined with the values to control the stepper motor.

A variable to index into the array declared as a static variable (static char is fine) so that its value is retained between calls.

A C language if statement can be used in this function to check bit 1 of port B and execute a forward direction block of code if it is high and a reverse block of code if it is low.

o if the motor is going in the forward direction block of code:

The index variable will be incremented and

o if the motor is going in the reverse direction block of code:

The index variable will be decremented

o Important: For both direction blocks of code: When the index is outside of the array limits, it must be reset back to the beginning or ending of the array.

A Delay Function will :

o This function is called from main(). The main() function will determine and pass the appropriate delay value to this function.

o The delay function receives a delay count that is type unsigned int.

o In this delay function,

use a C language for loop that loops the number of times of the received delay count.

and then ends (releases control back to the main function).

Function main( ) must do the following:

o Function main must call the step function and then call the delay function with an appropriate argument.

o Before the call to the delay function: will need to check bit 2 of port B and if high pass the value 6000010 and if low pass the value 3000010.

o The main function runs an endless for loop provided by CodeWarrior.

o The main( ) function must start the motor upon program startup and keep it going regardless of direction or speed until the program closes.

o Write you program such that only code that requires continuous operation are in the endless for loop.

Debug the program by stepping through it and examining registers. A small number such as one can be passed to the delay function while debugging. Once the code is debugged, the delay counts can be increased and the processor run at speed. The motor should not miss-step when reversing direction.

The program should use standard C language conventions.

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

Students also viewed these Databases questions