8086 Assembler Tutorial for Beginners (Part 12)

Controlling External Devices

הדרכה בתכנות אסמבלר 8086 למתחילים (חלק 12)  

בקרת התקנים חיצוניים

There are 3 devices attached to the emulator: Traffic Lights, Stepper-Motor and Robot. You can view devices using "Virtual Devices" menu of the emulator.

For technical information see I/O ports section of Emu8086 reference.

In general, it is possible to use any x86 family CPU to control all kind of devices, the difference maybe in base I/O port number, this can be altered using some tricky electronic equipment. Usually the ".bin" file is written into the Read Only Memory (ROM) chip, the system reads program from that chip, loads it in RAM module and runs the program. This principle is used for many modern devices such as micro-wave ovens and etc...

Traffic Lights

לאמולטור 3 התקני קלט/פלט מדומים: צומת רמזורים, מנוע צעד ורובוט. ניתנים להפעלה דרך התפריט "התקנים מדומים" של האמולטור.

למפרט טכני יש להפעיל את הדף התקני קלט/פלט  מתוך
אזכור ה- Emu8086.

בדרך כלל, יש אפשרות להשתמש בכל מעבד ממשפחת x86 לבקרת כל סוג של התקן המחובר למחשב. יתכן הבדל בין כתובות שערי קלט/פלט, זה ניתן לשינוי תוך שימוש בכמה התקנים אלקטרונים שונים.
בדרך כלל הקובץ "
bin." צרוב בתוך שבב של זיכרון קבוע (ROM).  מערכת הפעלה קוראת את פקודות התוכנית מהשבב הזה, טוען את התוכנית לתוך מקטע של  זיכרון RAM ומריצה את התוכנית.
כלל זה בשימוש במספר מכשירים מודרניים כמו תנורי מיקרו-גל ואחרים ...


מערכת רמזורים


Usually to control the traffic lights an array (table) of values is used. In certain periods of time the value is read from the array and sent to a port. For example: בדרך כלל משתמשים במערך נתונים (טבלה) למטרת הפעלת צומת רמזורים. בפרקי זמן קבועים התוכנית קוראת נתונים מתוך המערך ושולח אותם לשער בו מחובר הרמזור. למשל:

; directive to create BIN file:
;           BIN הוראות ליצירת קובץ מסוג
#MAKE_BIN#
#CS=500#
#DS=500#
#SS=500#
#SP=FFFF#
#IP=0#

; skip the data table:
;                   דלג את טבלת הנתונים
JMP start

table DW 100001100001b
      DW 110011110011b
      DW 001100001100b
      DW 011110011110b

start:

MOV SI, 0

; set loop counter to number
; of elements in table:
;          הגדר את הערך של כמות הנתונים
;                    :בטבלה עבור הלולאה
MOV CX, 4

next_value:

;         get value from table:
;                  קבל נתון מתוך הטבלה
MOV AX, table[SI]

; set value to I/O port
; of traffic lights:
;      הגדר ערך השער קלט/פלט של הרמזור
OUT 4, AX

; next word:     הנתון הבאה בגודל מילה
ADD SI, 2

CALL PAUSE

LOOP next_value

; start from over from
the first value
;           התחל מחדש את סידרת הנתונים
JMP start

; ==========================
PAUSE PROC
; store registers:     שמור ערך האוגרים
PUSH CX
PUSH DX
PUSH AX

; set interval (1 million          הגדר
; microseconds - 1 second):      השהייה
MOV     CX, 0Fh
MOV     DX, 4240h
MOV     AH, 86h
INT     15h

; restore registers:   שחזר ערך האוגרים
POP AX
POP DX
POP CX
RET
PAUSE ENDP
; ==========================

 

Stepper-Motor

מנוע  צעד

The motor can be half stepped by turning on pair of magnets, followed by a single and so on.

The motor can be full stepped by turning on pair of magnets, followed by another pair of magnets and in the end followed by a single magnet and so on. The best way to make full step is to make two half steps.

Half step is equal to 11.25 degrees.
Full step is equal to 22.5 degrees.

The motor can be turned both clock-wise and counter-clock-wise.

See stepper_motor.asm in Samples folder.

See also I/O ports section of Emu8086 reference.
 

Robot

ניתן להזיז את המנוע בחצי צעד על ידי חיבור בחשמל של זוג מגנטים, בהמשך צעד יחיד וכן הלאה.

המנוע יכול להסתובב צעד מלא על ידי הפעלת זוג מגנטים, בהמשך זוג אחר ולבסוף מגנט יחיד וכן הלאה.
הדרך הכי טובה לעשות צעד מלא זה לעשות שני חצי צעדים.

חצי צעד שווה ל- 11.25 מעלות.
צעד מלא שווה ל- 22.5 מעלות.

ניתן להפיל את המנוע בשני כיוונים: בכיוון השעון ונגד כיוון השעון.

ראה את הקובץ
stepper_motor.asm בתיקייה של דוגמאות בתוכנת האמולטור.

ראה גם החלק שערי קלט/פלט שבאזכור הכללי של תוכנת האמולטור.
 


רובוט

Complete list of robot instruction set is given in I/O ports section of Emu8086 reference.

To control the robot a complex algorithm should be used to achieve maximum efficiency. The simplest, yet very inefficient, is random moving algorithm, see robot.asm in Samples folder.

It is also possible to use a data table (just like for Traffic Lights), this can be good if robot always works in the same surroundings.

 

רשימה כוללת של פקודות הרובוט נכללת בחלק שערי קלט/פלט שבאזכור הכללי של תוכנת האמולטור.

לשליטת הרובוט עם השגת יעילות מרבית נדרש אלגוריתם מסובך . הכי פשוט, למרות שזה בלתי יעיל, זה להשתמש באלגוריתם של תנועות אקראיות. ראה את הקובץ
robot.asm בתיקייה של דוגמאות בתוכנת האמולטור.

גם יש אפשרות להשתמש בטבלת נתונים (כמו הטבלה של צומת הרמזורים), זה אפשרי רק אם הרובוט עובד תמיד באותו סביבה.

 

<<< to Part 11 <<   >> to Part 13 >>>

<<< לחלק 13 <<   >> לחלק 11 >>>