Can anybody help me with this c code so it can run a stepper motor?
-
The code below should be able to run a stepper motor in forward steps, reverse steps and forward 360 degrees. I also don't know how to code the send serial part of it. I'm really stuck on this. // Turn-table.cpp : main project file. #include "stdio.h" #include "reg51.h" #pragma SMALL DB OE void stop(); void forward_step(); void reverse_step(); void forward_cont(); //void sendCharacter(char h); unsigned char ReceiveSerial() { unsigned char c; TMOD = 0x20; //configure timer for the correct baud rate// TH1 = 0xe6; //1200 bps for 12 MHz clock// TCON = 0x00; //set timer to not running// SCON = 0x50; //set serial IO to receive and normal mode// TR1 = 1; //start timer to receive// while((SCON & 0x01) == 0); //wait for receive data// c = SBUF; //returns a character// return c; } void SendSerial(unsigned char c){ //initialise... set values for TMOD, TH1 and TCON// //set the Tx interupt in SCON to indicate sending data// //start timer// //write character to SBUF// //wait for completion of sent data// TI = 1; TR1 = 1; void sendCharacter(char) //sendCharacter(myChar); } //void sendChacracter(char h){ // p3.0 = h; //} drive_stepper(stop, forward_step, reverse_step, forward_cont) { static byte stepper_state = 0; unsigned byte i; void main(void){ //char s, f, r, fc; int s, f, r, fc; while(1){ //Use ReceiveSerial to read in a character// //Depending on character, make the motor move left or right// for(i=0;i<1000;i++) delay_ms(20); if (s == 0) stop(); else if (f == 1) forward_step(); else if (r == 2) reverse_step(); else if (fc == 3) forward_cont(); else stop() end if; } } void stop () { //assign all ports zero printf("stop"); } void forward_step() { //for loop for certain amount of time //assign a forward hex number on both ports printf("forward step"); } void reverse_step() { // assign reverse hex number on both ports printf("reverse step"); } void forward_cont() { //while!=button being pressed interrupts //assign full hex number to both ports 0xFFFF printf("forward cont"); }
-
Answer:
0 1 1 0 6 0 0 1 0 4 0 0 1 1 12 0 0 0 1 8 1 0 0 1 9 so that u make a lookup table that have the numbers {1,3,2,6,4,12,8,9} so if the porgram scan them from the right to the left the motor will be run and if the program scans them from the left to the right the motor will reverse i modified ur program assuming u r going to use portb try this code: #include "stdio.h" #include "reg51.h" #pragma SMALL DB OE void stop(); void forward_step(); void reverse_step(); void forward_cont(); //void sendCharacter(char h); unsigned int truth_table[]={1,3,2,6,4,12,8,9}; // the truth table of the stepper motor unsigned int truth_table_counter=1; // this will count the steps of the motor . . . . . . . . . . void stop () { //assign all ports zero printf("stop"); } void forward_step() { //for loop for certain amount of time //assign a forward hex number on both ports printf("forward step"); } void reverse_step() { // assign reverse hex number on both ports printf("reverse step"); } void forward_cont() { //while!=button being pressed interrupts //assign full hex number to both ports 0xFFFF printf("forward cont"); } p.s. replace the dots with the rest of the code
deanomcd at Yahoo! Answers Visit the source
Other answers
Is there not a manufactures helpline on the box or instructions? They will be able to take you through it step by step
Little Pigmy
Related Q & A:
- Can anyone help me get the code for my stereo?Best solution by Yahoo! Answers
- Can anybody help me in preparing a Project Report for eradication of Lantana in Himachal Pradesh and Uttarakha?Best solution by Yahoo! Answers
- Do anybody know any free online jobs site where you can get a free online job without having to pay for it?Best solution by Yahoo! Answers
- Can anyone help me with this C++ program?Best solution by Yahoo! Answers
- Can anyone help with a code for a ford fiesta radio?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.