Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me code a motor controller that uses 89C420

Status
Not open for further replies.

Robo

Junior Member level 3
Joined
Jan 21, 2005
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
327
Hi,

Project: uses 89C420 to control two motors.

Goal: send high/low signal to 89C420 -> control motors' direction of movement

Circuit schematic: (picture attached)

Physical circuit: (picture attached)

Description: As shown in the circuit schematic, I used Max232 as the driver. I also connected my two motors to P0.0 to P0.3 ports, and used uVision2 as my software.

Problem: I've limited knowledge in programming. Could anyone give me a little help on coding? I'd like to send high/low signal to ports P0.0 to P0.3 of 89C420. How could I do that?
 

Re: 89C420 Motor Control

At this stage let us assume that you have 11 095 200 Hz crystal, and the transmission through serial port will occure at 9600bps (pretty common speed).
You will need to run Windows Hyperterminal and once you press a key from the keyboard an ASCII code will be sent through serial port. I have chosen, as an example, keys such as q, w , e, ...
So th part of code may look like this:

CLR P1.0 ; P1.0 and P1.1 motor 1
CLR P1.1
CLR P1.2 ; P1.2 and P1.3 motor 2
CLR P1.3

CLR RI
Ser_Wait_Loop:
JB RI, Ser_Next; Wait for a character..
SJMP Ser_Wait_Loop

Ser_Next:
CLR RI
MOV A, SBUF
CJNE A, #'q', Check_Next1 ; key q was pressed ..
CLR P1.0 ; motor 1 on clockwise
SETB P1.1
SJMP Ser_Wait_Loop

Check_Next1:
CJNE A, #'w', Check_Next2; key w was pressed .. motor 1 stop
CLR P1.0
CLR P1.1
SJMP Ser_Wait_Loop

Check_Next2:
.... motor 1 c-clockwise ..

Once you understand this sample, you can continue with other functions.
This code has to be compiled and as hex file sent to microcontroller.
Do you know how to do it?

IMPORTANT NOTE: On your picture you connected motor directly to microcontroller's pins. I don't think you should do it. The internal puu-ups are to weak to drive almost anything but another ports or gates. Better option will be to use transistors or standard gates to drive these micro-motors, .. and don't forget about protective diodes connected in reverse in parallel to motors ..

Capacitor from Pin2 of MAX232 should be tied up to +5V and not as on your diagram to GND, and for MAX232 capacitances are 10µF (0.1µF is valid for MAX202) !!!
 

Re: 89C420 Motor Control

Thx.

In response to your post, I've the following two questions:

1. Is Windows Hyberterminal the only program I need to do this project? I'm asking this because I've previously read some posts that recommend Keil uVision2.

2. How do I create and send hex code to microcontroller?

Yeah, I'll be using two H-bridges to drive the two motors, instead of driving the motors directly.
 

Re: 89C420 Motor Control

If you program the microcontroller in such a way that it will "know" how to interpret commands consisting of ASCII characters, the only software is a Windows-base terminal such as Hyperterminal.
There are some other terminal programs, and one of them is InTerm ( free download from here: http://www.rfinnovations.com.au/Uploads/Images/RFI-Interm%20Rev1.1(1).zip ). Advantage of this on is, that you can create strings of ASCII or HEX characters/numbers and send the whole string by pressing one button; very convenient feature ..

After you write the code it has to be compiled (C or Assembler), and as a result you will have a YourCODE.HEX file. This hex file has to downloaded/programmed into your microcontroller.
You will have to go to MAXIN-IC web site and download MTK (microcontroller Tool Kit). This will allow you to program your microcontroller through the serial port (RS-232).
Use this link: **broken link removed**
On your PCB you will need to add 74125 3-state gates circuit which will allow you to switch from programming mode to running mode. About this you can also read in the above link ..

Good luck and regards ..
 

Re: 89C420 Motor Control

Umm... I tried Hyperterminal, but I couldn't type on that white screen. So I guess I can only transfer my .hex code using Hyperterminal. But before I can obtain the .hex file, I've to compile it using Keil uVision2 (??)

Ok. I tried to run and compile the following codes, but it says "error 56: cant open file". What might be the problem?

/*Moto_v2*/

void main(void)
{

/*P1.0 and P1.1 motor 1*/
CLR P1.0;
CLR P1.1;

/*P1.2 and P1.3 motor 2*/
CLR P1.2;
CLR P1.3;

CLR RI;

Ser_Wait_Loop:

/*Wait for a character*/
JB RI, Ser_Next;
SJMP Ser_Wait_Loop;

Ser_Next:

CLR RI;
MOV A, SBUF;

/*key q was pressed*/
CJNE A, #'q', Check_Next1;

/*motor 1 on clockwise*/
CLR P1.0;
SETB P1.1;
SJMP Ser_Wait_Loop;

Check_Next1:

/*key w was pressed .. motor 1 stop*/
CJNE A, #'w', Check_Next2;
CLR P1.0;
CLR P1.1;
SJMP Ser_Wait_Loop;
}
 

Re: 89C420 Motor Control

In Hyperterminal if you want to see characters on your screen you have to go to FILE ..Properties .. Settings .. ASCII setup .. and check box: ECHO typed characters locally.

Here is your code compiled on an ordinary assembler:
1 $NOPAGING
2 $MOD252
3
0000 4 ORG 0000H
5
6 ;/*P1.0 and P1.1 motor 1*/
0000 C290 7 CLR P1.0
0002 C291 8 CLR P1.1
9
10 ;/*P1.2 and P1.3 motor 2*/
0004 C292 11 CLR P1.2
0006 C293 12 CLR P1.3
13
0008 C298 14 CLR RI
15
000A 16 Ser_Wait_Loop:
17
18 ;/*Wait for a character*/
000A 209802 19 JB RI, Ser_Next
000D 80FB 20 SJMP Ser_Wait_Loop
21
000F 22 Ser_Next:
23
000F C298 24 CLR RI
0011 E599 25 MOV A, SBUF
26
27 ;/*key q was pressed*/
0013 B47106 28 CJNE A, #'q', Check_Next1;
29
30 ;/*motor 1 on clockwise*/
0016 C290 31 CLR P1.0
0018 D291 32 SETB P1.1
001A 80EE 33 SJMP Ser_Wait_Loop
34
001C 35 Check_Next1:
36
37 ;/*key w was pressed .. motor 1 stop*/
001C B47706 38 CJNE A, #'w', Check_Next2
001F C290 39 CLR P1.0
0021 C291 40 CLR P1.1
0023 80E5 41 SJMP Ser_Wait_Loop
42
0025 02000A 43 Check_Next2: LJMP Ser_Wait_Loop
44 END

VERSION 1.2h ASSEMBLY COMPLETE, 0 ERRORS FOUND
CHECK_NEXT1. . . . . . . . . . . C ADDR 001CH
CHECK_NEXT2. . . . . . . . . . . C ADDR 0025H
P1 . . . . . . . . . . . . . . . D ADDR 0090H PREDEFINED
RI . . . . . . . . . . . . . . . B ADDR 0098H PREDEFINED
SBUF . . . . . . . . . . . . . . D ADDR 0099H PREDEFINED
SER_NEXT . . . . . . . . . . . . C ADDR 000FH
SER_WAIT_LOOP. . . . . . . . . . C ADDR 000AH
 

Re: 89C420 Motor Control

There is something that I don't understand.

What do you mean by "ordinary assembler" Do you compile it using Hyperterminal (I don't see the compile function in Hyperterminal), or uVision2 (I got a message saying there is an error opening my file).

How do you get the ASCII screen you attached above?
 

Re: 89C420 Motor Control

By ordinary assembler I mean ASM51.EXE. (this file and MOD52 file are attached)
After you run a text file with named yourcode with asm51, it will generate yourcode.HEX file and yourcode.LST file, which is actually quoted in my previous post ..
 

Re: 89C420 Motor Control

I am trying to use ASM51. But when I type C:\filename.txt and press enter, the program exits. Basically it exits whenever I pressed enter...
 

Re: 89C420 Motor Control

Put ASM51.EXE, MOD252 and yourcode.TXT file in the same subdirectory. Call it ASSEMBLER.
And try to run it again.
As your text files are short the program processes them very fast and the only thing you may notice will be two new files in the same subdirectory: *.hex and *.lst.
If you need to read more about ASM51 here is its manual:
**broken link removed**
rgs
IanP
 

89C420 Motor Control

IanP,

thanks for pointing out the mistake in the schematics (I drew it up for someone, seemed that it found it's way here). Pin2 definetly should be tied to +5V, but the diagram was ment to show a MAX232A rather than a MAX232 so the 0.1uF is what I was using :)

Thanks, I'll try and correct the original thread!

-abionnnn
 

Re: 89C420 Motor Control

I followed what you and the manual said, which is to put ASM51.EXE, MOD252 and yourcode.TXT file in the same subdirectory, and ran the program once. However, once I pressed enter, the DOS screen disappearred and no .hex file was created...

Is there any other easy way to generate .hex code?
 

Re: 89C420 Motor Control

Try this way:
START -- All Programs -- Accessories -- Command Prompt

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Default

To change directory to where you have asem51 and yourfile.txt ype:
cd C:\assembler

C:\Assembler

C:\Assembler>asm51.exe

ERROR: An Extended Memory Manager is already installed.
XMS Driver not installed.

8051 Cross-Assembler, Version 1.2h
(c) Copyright 1984, 1985, 1986, 1987, 1988, 1989, 1990
by MetaLink Corporation
Source file drive and name [.ASM]: forum_04.txt
First pass
Second pass
ASSEMBLY COMPLETE, 0 ERRORS FOUND
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top