3628 views|3 replies

1

Posts

0

Resources
The OP
 

at89c2051 programming problem [Copy link]

Hello everyone, I have a stupid problem. I downloaded a .C motor driver from the website. But when I put it into Keil software to edit HEX, it can't be compiled. I don't know if it's a software problem or my own technical problem. Please help me analyze the following program: stepper.c stepper.hex /* * STEPPER.C * sweeping stepper's rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */ #i nclude c:\mc5151io.h /* include i/o header file */ #i nclude c:\mc5151reg.h register unsigned char j,flag1,temp; register unsigned int cw_n,ccw_n; unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90} #define n 400 /* flag1 mask byte 0x01 run cw() 0x02 run ccw() */ main() { flag1=0; serinit(9600); disable(); /* no need timer interrupt */ cw_n = n; /* initial step number for cw */ flag1 |=0x01; /* initial enable cw() */ while(1){ { tick_wait(); /* wait for 10ms elapsed */ energize(); /* round-robin execution the following tasks every 10ms */ cw(); ccw(); } } } cw(){ if((flag1&0x01)!=0) { cw_n--; /* decrement cw step number */ if (cw_n !=0) j++; /* if not zero increment index j */ else {flag1&=~0x01; /* disable cw() execution */ ccw_n = n; /* reload step number to ccw counter */ flag1 |=0x02; /* enable cww() execution */ } } } ccw(){ if((flag1&0x02)!=0) { ccw_n--; /* decremnent ccw step number */ if (ccw_n !=0) j--; /* if not zero decrement index j */ else {flag1&=~0x02; /* disable ccw() execution */ cw_n = n; /* reload step number to cw counter */ flag1 |=0x01; /* enable cw() execution */ } } } tick_wait(){ /* cputick was replaced by simpler ASM code 10ms wait */ asm" JNB TCON.5,*"; /* wait for TF0 set */ asm" CLR TCON.5"; /* clear TF0 for further set */ asm" ORL TH0,#$DC"; /* reload TH0 with $DC, TL0 = 0 */ } energize(){ P1 = step[(j&0x07)]; /* only step 0-7 needed */ }



2.png (343.14 KB, downloads: 0)

2.png

3.png (18.91 KB, downloads: 0)

3.png

23.png (195.59 KB, downloads: 0)

23.png
This post is from Microchip MCU

Latest reply

Copy the entire c file and use it directly? This is a very sloppy approach. You should first find a normal project. Analyze the main content of this c file. Add variables and functions to the corresponding files in the original project. Debug it bit by bit. This is relatively less risky. In addition, if you analyze the code more in the early stage, it will be easier to modify the function later.  Details Published on 2018-1-29 13:08
 

6040

Posts

204

Resources
2
 
#i nclude c:\mc5151io.h /* include i/o header file */ #i nclude c:\mc5151reg.h There are problems with these two sentences, and they are very big problems. You can fix them yourself. If you don’t know how to fix them, don’t bother, as there will be more pitfalls in the future.
This post is from Microchip MCU
 
 
 

6040

Posts

204

Resources
3
 
Including header files is not only a syntax error, the key is whether you have these two header files?
This post is from Microchip MCU
 
 
 

3471

Posts

11

Resources
4
 
Copy the entire c file and use it directly? This is a very sloppy approach. You should first find a normal project. Analyze the main content of this c file. Add variables and functions to the corresponding files in the original project. Debug it bit by bit. This is relatively less risky. In addition, if you analyze the code more in the early stage, it will be easier to modify the function later.
This post is from Microchip MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list