0% found this document useful (0 votes)
4 views

MicroLabPDF

Uploaded by

Roukoz l
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

MicroLabPDF

Uploaded by

Roukoz l
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

‫بسم هللا الرحمن الرحيم‬

MicroProcessor Lab

Marah Zaid C.E #122

Exp 1: Binary Input/Outputs

What is required is: to write an assembly code to read the state of switches (K1 -
K8) of the MML8086K3 trainer board. Then, display the read pattern to the LEDs
(L1 - L8) by using 8255A adapter.
.‫ ثم نضوي الضو اللي مقابل إلها‬، ‫بدنا نشوف مين الكبسة المكبوسة‬

First, what is 8255?


8255A PPI (Programmable Peripheral Interface adapter): Contains three ports (A, B,
C). Each of them has 8 I/O bits, resulting in 24 I/O in all.

It has three basic modes:


(0) ⇒ basic input/output
(1) ⇒ strobed input/output
(2) ⇒ bidirectional bus.

PORT A can be set for Modes 0, 1, 2. PORT B for 0, 1 and PORT C for mode 0 and
BSR (Bit Set/Reset).

Port C was divided into two parts: PC upper (PCU) ⇒ PC7 - PC4 and PC lower
(PCL) ⇒ PC3 - PC0.

In the end, 8255 is divided into two groups:


1. Group A (GA) : contains PA and PCU
2. Group B (GB) : contains PB and PCL

In addition to these three ports, there is a control word register CWR, and all the
registers each have an address, as in the following image:

1
Port Address

Register Address

Control word register (CWR) 0FF2BH

PORT A 0FF28H

PORT B 0FF29H

PORT C 0FF2AH

To write the code, you must first write to the control word register using the Out
instructions: CWR‫الزم نفعل ال‬

Reminder :
Out DX,AL (write)
DX contain the port address
and AL contain what you need to write to this port
In Al,Dx (Read)

:‫ التالي‬format ‫ ؟ حسب الـ‬CWR ‫ إيش رح نكتب على الـ‬،‫اوك‬

8255A Control Word Format:

D7 D6 D5 D4 D3 D2 D1 D0

1 GA mode PA PCU GB mode PB PCL


always 1 00 - mode 1 1 - input 1 - input 0 - mode 0 1 - input 1 - input
for I/O 01 - mode 2 0 - output 0 - output 1 - mode 1 0 - output 0 - output
mode 1X - mode 3

We used Mostly mode 1 , so D6 D5 and D2 ⇒ 0/0/0


in this experiment we used port A as output (connected with leds), so D4 ⇒ 0
and port B as input (connected with switches ), so D2 ⇒ 1
port C not used, so D3 and D0 ⇒ 0/0

so we put in Al ⇒ 10000010b == 82h

2
Steps to write code:
1. write to CWR
2. read buttons from PB
3. write to PA (Leds)

so, our code:

================================================================

Exp 2: 8253 timer / counter

The 8253 IC is a Programmable Interval Timer (PIT) designed by Intel, commonly


used for generating accurate time delays or counting events in microprocessor
systems. It contains three independent 16-bit counters/timers, each capable of being
programmed for various timing operations such as generating precise time delays,
square waves, and event counting.

3
Gate0 == Enable ⇒ +5V

Clk0 ⇒ 1MZ

Key Features:

1. 3 Independent Counters: Each counter can function independently and be


programmed to operate in six different modes, such as interrupt on terminal
count, hardware retriggerable one-shot, and square wave generation.

2. 16-bit Counters: Each counter is 16 bits wide, allowing for timing delays from
microseconds to seconds, depending on the clock input frequency, frequency
range of 0 - 2 MHz.

3. Modes of Operation: The 8253 supports six distinct modes of operation:


○ Mode 0: Interrupt on Terminal Count
○ Mode 1: Hardware Retriggerable One-Shot
○ Mode 2: Rate Generator
○ Mode 3: Square Wave Generator
○ Mode 4: Software Triggered Strobe
○ Mode 5: Hardware Triggered Strobe

4. Programmable Control Word: Counter is programmed through a control


word to set the mode, binary/BCD counting, and other parameters.

4
5. Clock Input & Gate Control: Each counter has a clock input and a gate
input, allowing external signals to control the counting process.

Each counter has an address:

Selects Address

Counter 0 0040H

Counter 1 0041H

Counter 2 0042H

Control word register (CWR) 0043H

The idea is : to write to CWR, then write to a specific counter using the address.

mode ‫ بدنا نكتب عليه ونختار ال‬counter ‫ عشان نحدد أي‬CWR ‫أول اشي رح نكتب على‬
Ok, What should we write on CWR?
Let's see this picture!

5
Let's start with the first part:

What is required is: Initialize counter 0 in mode 3 (square wave) with a frequency of
10kHz. Assume input frequency is 1MHz.

counter 0, so ⇒ D7=0 and D6=0


mode 3 (square wave), so ⇒ D3=0 , D2=1 and D1=1
Binary counter 16-bits, so ⇒ D0=0
What about D5 and D4 ? We will choose 01, but why? Let’s explain !

Before that, we must show the value that we write on the counter 0. . .
input frequency is 1MHz and the frequency for square wave 10kHz
1*10^6 / 10*10^3 = 100 , so the value on counter0 must be 100
mov dx,40h ;the address of counter0
mov al,100 ;Quotient
out dx,al

100 d = 64 h ⇒ al = 64 h (100 in range 0 - 255, so we choose least


significant byte only)

6
And The output ⇒

What if it is required 1kHz ⇒ 1MHz / 1kHz = 1000


1000 d = 03E8 H not in range (0 - 255) ⇒ must be passed least sig. first then most
sig. so D5 D4 ⇒ 1 1
code:

Part 2:
Initialize counter 0 in mode 2 (Rate generator) with a period of 100µs. Assume input
frequency is 1MHz
period = 100 * 10^(-6) ⇒ frequency = 1/ period ⇒ frequency=10 kHz
same as part 1 ⇒ 1 MHz / 10 kHz = 100
but mode 2 (Rate generator) ⇒ D3=0 , D2=1 and D1=0

7
‫⇒ ‪And The output‬‬

‫================================================================‬

‫لِيمسح الدمع من عينيك إن نزال‬ ‫️♥‬ ‫ُيؤتي َك من لُطفه ما لست تعرف ُه‬
‫إ ّياك يا صاحبي أن تق ُتل األمال‬ ‫️♥‬ ‫هللاُ أكر ُم من ُيعطي على ٍ‬
‫قدر‬

‫‪8‬‬
Exp 3:A musical electronic Organ

In this experiment, we will read the push buttons (connected on port A in the 8255) to
determine which one is pressed, then based on the pressed push button, there is a
different frequency value ​for each push button, then based on the frequency value
we write on the counter 1 in the 8253.

‫ بناء‬،‫) لتحديد أي الكبسات مضغوط عليها‬8255 ‫ في‬port A ‫في هذه التجربة سنقوم بقراءة الكبسات (مشبوكات على‬
.8253 ‫ في‬1 ‫ ثم بناء على قيمة التردد نكتب على العداد‬،‫على الكبسة المضغوطة يوجد قيمة تردد مختلفة لكل كبسة‬

NOTE:
‫ يعني فعلنا الكاونتر وبس نكتب‬1 ‫ لما نكتب عليه‬enable (gate( ‫ َك‬port B ‫رح نستخدم البت األول في‬
.‫ يعني ألغينا تفعيله‬0

Audio Amplifier: An audio amplifier is an electronic device that increases the strength
(amplitude) of audio signals that pass through it. An audio amplifier amplifies
low-power audio signals to a level which is suitable for driving loudspeakers.

STEPS TO WRITE THE CODE:

1. Initialize 8255 and 8253.


2. Turn off the counter 1.
3. Read push buttons.
4. Turn On the counter 1.
5. Writing to Counter based on the push buttons pressed.

9
push 1 2 3 4 5 6 7
button

Frequency 440 493.88 554.37 587.33 659.26 739.99 830.61


(HZ)

1MHz/ freq. 2272 2024 1803 1702 1516 1351 1204

In Hex 8E0 7E8 70B 6A6 5EC 547 4B4

10
‫أول اشي بنكون ملغيين تفعيل الكاونتر يعني معطيين االينيبل ‪( 0‬بورت ‪ ، )B‬ثم بس نقرأ الكبسة بنروح بنفعل الكاونتر‬
‫من خالل البروسيجر ‪turnOnOrgan‬‬

‫‪NOTE: There is a slight difference in the way the procedure is written in the lab, as‬‬
‫‪follows:‬‬

‫‪11‬‬
Exp 4: 8279 Keyboard / Display Interface

Objectives:
1. To know the basic principle of 8279 and microcomputer interface.
2. Use 8279 to interface the six 7-segment display array.
3. Use 8279 to interface the 4x4 matrix keyboard.

The 8279 is a programmable keyboard/display interface device designed for


microprocessor-based systems such as Intel 8086/8088. Its primary function is to manage
the interaction between a keyboard and a display without placing a heavy processing burden
)‫ كاوتبوت‬seg-7‫ كوسيط ندخل عليها الكيبورد كانبوت وال‬8255 ‫ (يعني مثالً بدون ما نستخدم‬.on the microprocessor

Key features include:

● Simultaneous keyboard and display operations.


● Scanned keyboard mode for matrix keyboards.
● Scanned sensor mode for interfacing with various sensors.
● 8-character keyboard FIFO (First In First Out) buffer for efficient data handling.
● Supports a 1x6-character display.
● Display RAM with right or left entry for storing up to 6 characters.
● Programmable scan timing, allowing flexible configurations for different applications.

It can handle both 7-segment displays and matrix keyboards, which makes it ideal for
systems where both input and output are essential, like calculators or user interface systems
in embedded hardware.

Pinout Definition 8279


● A0: Selects data (0) or control/status (1).
● BD: Output that blanks the displays.
● CLK: Used internally for timing.

12
● CN/ST: Control/strobe, connected to the control key on the keyboard.
● CS (Chip Select): Used to activate the chip. When low, the chip is enabled to
communicate with the processor.
● DB7-DB0: Consists of bidirectional pins that connect to the data bus on micro.
● IRQ: Interrupt request, becomes 1 when a key is pressed, data is available.
● OUT A3-A0/B3-B0: Outputs that send data to the most significant/least significant
nibble of display.
● RD (Read): Used to read data from the chip.
● WR (Write): Used to write data to the chip.
● RESET: Used to reset the chip, returning it to its initial state.
● RL7-RL0: Return lines are inputs used to sense key depression in the keyboard
matrix.
● Shift: Shift connects to Shift key on keyboard.
● SL3-SL0: Scan line outputs scan both the keyboard and displays.

.ً‫ معا‬keyboard ‫ و‬seg display-7 ‫ بنستخدمها عشان نتحكم في‬8279 ‫باختصار هاي القطعة‬

‫ بينما في البارت الثاني رح نقرأ أي كبسة‬، seg-7 ‫في البارت األول رح نستخدمها حتى نظهر رمز معين على‬
. seg-7 ‫ ثم بنا ًء على هاي الكبسة رح نظهر الرمز تبعها على‬، ‫مكبوسة من الكيبورد‬

: ‫ هم‬، ‫ أوامر‬3 ‫ لهاي القطعة من خالل‬Initialization ‫في البداية الزم نعمل‬

1. Keyboard/Display Mode Set


2. Program Clock
3. Clear

، address => FF81 ‫ كيف هذول رح نعملهم ؟ الزم نبعث داتا معينة على ال‬، ‫اوك‬

addresses 2 ‫هو احنا عنا‬

‫ اوك ايش هي الداتا اللي رح نبعثها؟‬، ) FF81 => control / FF80 => Data (

: ‫ بنا ًء على ايش من هذول األوامر رح أعمل‬Most significant bits 3 ‫في البداية الزم نحدد آخر‬

D7 D6 D5 D4 D3 D2 D1 D0

The command word format is 8 bit, the three most significant bits selects the various
operations which are given as:

000 Keyboard / Display Mode Set

001 Program Clock

13
010 Read FIFO / Sensor RAM

011 Read Display RAM

100 Write Display RAM

101 Display Write Inhibit / Blanking

110 Clear

111 End Interrupt / Error Mode Set

‫* اللي به ّمونا أو رح نستخدمهم في هاي التجربة ملونين باألخضر‬

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ‫بسم هللا نبلش في أول وحدة‬

Keyboard/Display Mode Set :

D7 D6 D5 D4 D3 D2 D1 D0

0 0 0 D D K K K

DD represents the display mode and KKK represents the keyboard mode.

DD => Eight 8-bit character display with left entry. (00)

KKK => Encoded scan Keyboard with 2-key lockout. (000)

‫ سيستجيب فقط ألول مفتاح تم الضغط عليه ويهمل‬8279 ‫ فإن‬،‫يعني أنه إذا تم الضغط على مفتاحين في نفس الوقت‬
.‫الثاني‬

Code =>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ‫ننتقل لثاني وحدة؟‬

Program Clock:

The different keys of the keyboard are scanned one by one in a sequence to detect a key
press by the 8279; and also key de-bouncing is implemented by this device. All these
functions require the timing signal. The 8279, therefore, needs an internal clock. The
frequency of this clock should be around 100 KHz.

D7 D6 D5 D4 D3 D2 D1 D0

0 0 1 P P P P P

14
‫ زي بالتجربة اللي قبل بنقسم‬، ً ‫ تقريبا‬55KH ‫ ألنه بدنا الفريكونسي تكون‬18 ‫ لي‬، P => 18 ‫رح نحط في ال‬
.18 ً ‫ بيطلع الجواب تقريبا‬1MHz / 55 KHz

Code =>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ‫ثالث وحدة؟‬

Clear:

D7 D6 D5 D4 D3 D2 D1 D0

1 1 0 CD CD CD CF CA

The bits D7 D6 D5 represent command word 6 (1 1 0). CA Clears All (it clears both display
RAM and FIFO). CF Clears FIFO Status and resets the IRQ line. CDCDCD Clears all rows
of the display RAM to a selectable blanking code.

.1 ‫احنا بدنا نمسح كلشي َفبنعبيهم كلهم‬

Code =>

>>>>>>>>>>>>>>>>>>>> ‫إيش النيكست سيب؟ هسا هيك بتكون القطعة هاي جاهزة لحتى نستخدمها‬

PART ONE: Display Section

15
seg-7 ‫أول مطلوب في هذا البارت أنه نطبع رمز معين على‬

:‫ رح نفعلها من خالل األمر التالي‬، seg-7 )6( ‫ اللي بدي أظهر عليها ألنه عنا‬seg-7 ‫أول اشي الزم نفعل الـ‬

Write Display RAM:

To display information, the seven segment data is to be written in the internal display buffer.
To enable writing seven segment data into the display buffer, the write display RAM
command has to be written into the command word register. The command word for the
same is as shown:

D7 D6 D5 D4 D3 D2 D1 D0

1 0 0 A1 A A A A

The bits D7 D6 D5 represent command word 4 (1 0 0).


A1 represents Auto Increment.
AAAA (D3 D2 D1 D0) is the address of the digit that the CPU writes into the buffer.
Four bit address is provided to select any one of the 16 digits.
>= seg-7 ‫يعني اذا بدي أختار أول‬
10000000 (80H)

:‫ التالي‬format ‫ ؟ حسب الـ‬seg-7 ‫ضايل شغلة وحدة وهي كيف رح نمثل هذا الرمز المعين على‬

D7 D6 D5 D4 D3 D2 D1 D0

d c b a dp g f e

.1 ‫ واللي بدي أطفيه بعطيه‬0 ‫ يعني الضو اللي بدي أضويه بعطيه‬، common anode ‫مع االنتباه أنهم‬
FF80 ‫ وكل رمز بنبعثه على عنوان‬GP. 2 ‫الرمز اللي رح نظهره‬

d c b a dp g f e

0 0 1 0 1 0 0 0 G

1 1 0 0 0 0 0 0 P.

0 1 0 0 1 0 1 0 2

16
‫>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>‬

‫ثاني مطلوب في هذا البارت ‪ :‬نعمل ‪BCD Counter 0-9‬‬


‫نفس الفكرة حنظهر رقم على ‪ ، seg-7‬بس الفرق رح نخزن القيم في ‪array‬‬

‫‪d‬‬ ‫‪c‬‬ ‫‪b‬‬ ‫‪a‬‬ ‫‪dp‬‬ ‫‪g‬‬ ‫‪f‬‬ ‫‪e‬‬

‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0C‬‬

‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪9F‬‬

‫‪2‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪4A‬‬

‫‪17‬‬
3 0 0 0 0 1 0 1 1 0B

4 1 0 0 1 1 0 0 1 99

5 0 0 1 0 1 0 0 1 29

6 0 0 1 0 1 0 0 0 28

7 1 0 0 0 1 1 1 1 8F

8 0 0 0 0 1 0 0 0 08

9 0 0 0 0 1 0 0 1 09

18
‫‪PART TWO: Display Section‬‬

‫في هذا البارت بدل ما أنا أعطى ‪ 8279‬رمز معين تظهره على ‪ ، seg-7‬رح أقرأ من الكيبورد كبسة معينة ثم بنا ًء‬
‫عليها بظهر الرمز تبعها‪.‬‬

‫اللي بهمونا في الكيبورد هم ‪ 16‬كبسة موجودين في يسار الشكل التالي‪:‬‬

‫كل كبسة إلها رقم عمود ورقم صف‪ ،‬مرتبين في هذا الجدول‪:‬‬

‫‪Col 0‬‬ ‫‪Col 1‬‬

‫‪Row 0‬‬ ‫‪7‬‬ ‫‪1‬‬

‫‪Row 1‬‬ ‫‪4‬‬ ‫‪0‬‬

‫‪Row 2‬‬ ‫‪8‬‬ ‫‪2‬‬

‫‪Row 3‬‬ ‫‪5‬‬ ‫‪F‬‬

‫‪Row 4‬‬ ‫‪9‬‬ ‫‪3‬‬

‫‪Row 5‬‬ ‫‪6‬‬ ‫‪E‬‬

‫‪Row 6‬‬ ‫‪A‬‬ ‫‪C‬‬

‫‪Row 7‬‬ ‫‪B‬‬ ‫‪D‬‬

‫كيف بدنا نعرف أي كبسة مكبوسة مثالً؟‬

‫بنقرأ من عنوان ‪ FF80‬قيمة ‪ ،‬هاي القيمة بتكون بتحتوي على رقم الصف ورقم العمود لهاي الكبسة ‪ ،‬فإذا كان رقم‬
‫الصف ‪ 5‬ورقم العمود ‪ 1‬يعني الكبسة ‪ E‬مكبوسة وهكذا‪.‬‬

‫القيمة اللي بقرأها بتكون على الشكل التالي‪:‬‬

‫‪19‬‬
CNTL SHIFT D5 D4 D3 D2 D1 D0
________ ROW _________ _______ COLUMN _______

: Arrays 2 ‫رح نعمل‬

. ‫ األولى رح نخزن فيها موقع كل كبسة‬array ‫ال‬

CNTL SHIFT D5 D4 D3 D2 D1 D0

0 0 0 0 0 1 0 0 1 09H

1 0 0 0 0 0 0 0 1 01H

2 0 0 0 1 0 0 0 1 11H

3 0 0 1 0 0 0 0 1 21H

4 0 0 0 0 1 0 0 0 08H

5 0 0 0 1 1 0 0 0 18H

6 0 0 1 0 1 0 0 0 28H

7 0 0 0 0 0 0 0 0 00H

8 0 0 0 1 0 0 0 0 10H

9 0 0 1 0 0 0 0 0 20H

A 0 0 1 1 0 0 0 0 30H

B 0 0 1 1 1 0 0 0 38H

C 0 0 1 1 0 0 0 1 31H

D 0 0 1 1 1 0 0 1 39H

E 0 0 1 0 1 0 0 1 29H

F 0 0 0 1 1 0 0 1 19H

. seg-7 ‫ الثانية رح نخزن فيها القيمة تبعتها اللي رح أظهرها بال‬array ‫و ال‬

d c b a dp g f e

0 0 0 0 0 1 1 0 0 0C

1 1 0 0 1 1 1 1 1 9F

20
‫‪2‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪4A‬‬

‫‪3‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0B‬‬

‫‪4‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪99‬‬

‫‪5‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪29‬‬

‫‪6‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪28‬‬

‫‪7‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪8F‬‬

‫‪8‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪08‬‬

‫‪9‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪09‬‬

‫‪A‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪88‬‬

‫‪B‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪08‬‬

‫‪C‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪6C‬‬

‫‪D‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0C‬‬

‫‪E‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪68‬‬

‫‪F‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪E8‬‬

‫اللي رح نكتبه في الكود باختصار‪:‬‬


‫نقرأ قيمة من ‪FF80‬‬
‫ثم نقارن هاي القيمة مع عناصر ال‪ array‬األولى‪ ،‬ليش؟ عشان إذا هاي القيمة تطابقت مع إحدى عناصر ال‪array‬‬
‫يعني في كبسة منهم مكبوسة ‪.‬‬
‫ثم نروح على ال‪ array‬الثانية‪ ،‬حسب القيمة اللي بتقابل هاي الكبسة بنظهر على ال ‪.seg-7‬‬

‫نوخذ مثال عشان نفهم ؟ مثالً أنا كبست على الكبسة ‪ A‬كيف حيتنفذ الكود ؟‬
‫أول اشي بحط مؤشر على بداية ال ‪ array‬األولى ‪ di‬ومؤشر آخر على بداية ال ‪ array‬الثانية ‪si‬‬
‫بقرأ قيمة من ‪ FF80‬هاي القيمة حتكون ‪ 30H‬ألني كابسة على ‪A‬‬
‫بقارنها مع اللي بأشر عليه ‪ di‬بكون على بداية ال ‪ array‬بالتالي مش نفس الكبسة اللي كابسة عليها‬
‫بروح بزيد قيمة ‪ di‬وكمان بزيد قيمة ‪ si‬ألني بدي كل كبسة مع الرمز تبعها اللي بقابلها ‪ ،‬ثم برد بقارن القيمة اللي‬
‫بأشر عليها ‪ di‬مع القيمة اللي قرأتها‬
‫وهكذا بضل أزيد في المؤشرين لحتى تتساوى القيمة اللي بأشر عليها ‪ di‬مع القيمة اللي قرأتها‬
‫وقتها إيش بعمل ؟ بظهر القيمة اللي بأشر عليها ‪ si‬على ال ‪ ،seg-7‬وانتهى !‬

‫‪21‬‬
================================================================

22
Exp 5: ADC0809 analog-to-digital conversion

The ADC0809 is an 8-bit analog-to-digital converter (ADC) with a 8-channel


multiplexer. It is commonly used for converting analog signals into digital signals in
various electronic systems.

Key Components of the ADC0809:

1. Analog Inputs (IN0-IN7): The ADC0809 has 8 analog input channels (IN0 to IN7),
which allow it to select one of the 8 analog input signals for conversion. In our circuit,
the channels are connected to potential analog sources.

2. Multiplexer: The built-in 8-channel multiplexer allows selecting one of the 8 input
channels (IN0 to IN7) for analog-to-digital conversion. This selection is done using
the address lines ADD-A, ADD-B, and ADD-C.

3. Reference Voltage (ref(-), ref(+)): The reference voltage pins (ref(-) and ref(+))
are used to define the range of the input voltage for conversion. The input voltage
should be within the range of these reference voltages to get accurate digital
conversion.

4. Digital Output (D0-D7): The output of the conversion is an 8-bit digital value. The
least significant bit (LSB) is D0, and the most significant bit (MSB) is D7. These bits
represent the digital equivalent of the analog input signal.

23
5. Control Signals:
○ START: Starts the analog-to-digital conversion process.
○ ALE (Address Latch Enable): Used to latch the input address into the
multiplexer.
○ EOC (End of Conversion): This signal goes high to indicate the end of
conversion.
○ OE (Output Enable): Controls when the digital output is placed on the output
bus.
○ CLOCK: A clock signal is required to control the timing of the conversion.

6. Logic Gates (74LS02): The 74LS02 chip in the circuit contains NOR gates, which
are used here to control the enabling of the ADC and its operations based on the
clock and other control signals (such as read (RD) and write (WR)).

What is required is: Use the ADC to convert an analog value (potentiometer) to
digital value, then re-convert it into analog value in order to display it on the
seven-segment displays.

How does the ADC convert an analog value to digital value?

𝑛
𝐷𝑖𝑔𝑖𝑡𝑎𝑙 = (𝑎𝑛𝑎𝑙𝑜𝑔 * 2 )/𝑉𝑐𝑐

In our experiment we have, n = 8 (8-bit ADC) and Vcc = 5V, so

8
𝐷𝑖𝑔𝑖𝑡𝑎𝑙 = (𝑎𝑛𝑎𝑙𝑜𝑔 * 2 )/5 ==> 𝐷𝑖𝑔𝑖𝑡𝑎𝑙 = 𝑎𝑛𝑎𝑙𝑜𝑔 * 51

How to convert the digital output of the ADC to analog, in order to display it on
the seven-segment displays?

𝑛
𝑎𝑛𝑎𝑙𝑜𝑔 = (𝐷𝑖𝑔𝑖𝑡𝑎𝑙 * 𝑉𝑐𝑐)/2

8
𝑎𝑛𝑎𝑙𝑜𝑔 = (𝐷𝑖𝑔𝑖𝑡𝑎𝑙 * 5)/2 ==> 𝑎𝑛𝑎𝑙𝑜𝑔 = 𝐷𝑖𝑔𝑖𝑡𝑎𝑙 / 51

24
How to get the ones digit and the fraction digits?

How to interface seven-segment displays using 8255? (common Anode)

Use one port for the data, and another port to select the seven-segment display, in
our experiment we used port A for the data and port B for the selection process.

NOTE: the data will be:


a b c d e f g dp

We will create 2 arrays, one for the ones digit -dp is ON, the other is for the fraction
-dp is OFF.

ones :
num dp g f e d c b a Hex

0 0 1 0 0 0 0 0 0 40H

1 0 1 1 1 1 0 0 1 79H

2 0 0 1 0 0 1 0 0 24H

3 0 0 1 1 0 0 0 0 30H

4 0 0 0 1 1 0 0 1 19H

5 0 0 0 1 0 0 1 0 12H

6 0 0 0 0 0 0 1 0 02H

7 0 1 1 1 1 0 0 0 78H

8 0 0 0 0 0 0 0 0 00H

9 0 0 0 1 1 0 0 0 18H

25
‫‪fractions:‬‬

‫‪num‬‬ ‫‪dp‬‬ ‫‪g‬‬ ‫‪f‬‬ ‫‪e‬‬ ‫‪d‬‬ ‫‪c‬‬ ‫‪b‬‬ ‫‪a‬‬ ‫‪Hex‬‬

‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪C0H‬‬

‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪F9H‬‬

‫‪2‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪A4H‬‬

‫‪3‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪B0H‬‬

‫‪4‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪99H‬‬

‫‪5‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪92H‬‬

‫‪6‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪82H‬‬

‫‪7‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪F8H‬‬

‫‪8‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪80H‬‬

‫‪9‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪98H‬‬

‫‪STEPS TO WRITE THE CODE:‬‬

‫‪1.‬‬ ‫‪Initialize 8255.‬‬


‫‪2.‬‬ ‫‪Send zero to ADC to start the conversion.‬‬
‫‪3.‬‬ ‫‪Read the Digital value from ADC.‬‬
‫‪4.‬‬ ‫‪Convert it to analog and display it using 7-seg.‬‬

‫اللي رح نعمله بالكود نقرأ قيمة من ال ‪ ، ADC‬القيمة هاي حتكون ‪ ، digital‬ألنه زي ما حكينا ال‬
‫‪ ADC‬بوخد ‪ Analog input‬وبط ّلع ‪.digital output‬‬
‫ثم بعد ما قرأنا قيمة من ال ‪ ADC‬المطلوب مننا نحول هاي القيمة ل ‪ analog‬حسب المعادالت السابقة ‪،‬‬
‫ثم نظهر هاي القيمة ( ‪ ) analog‬على ‪.seg-7‬‬

‫نشرح الكود من خالل مثال‪>>>>>>>>>>>>>>>>>>>>>>>>>>>> :‬‬

‫ال ‪ adc‬مشبوك مع ‪ ، address FF80 H‬أول خطوة نكتب على هذا العنوان ‪ 0‬عشان ن ّفعل ال ‪ ،adc‬ثم‬
‫بنعمل ‪ delay‬وبنقرأ قيمة من هذا العنوان هاي القيمة ‪Digital‬‬

‫‪26‬‬
‫على فرض أنا مدخلة لل ‪ Adc‬قيمة ‪ ، analog = 2.5‬بالتالي القيمة اللي حنقرأها من ال ‪adc = 128‬‬
‫بتكون مخزنة في ‪ ، Al‬مهمتي هسا أحول هاي القيمة ل ‪ analog‬يعني أرد أرجعها ل ‪ 2.5‬من خالل‬
‫المعادالت‪.‬‬
‫بنقسم القيمة اللي قرأتها (‪ )128‬على ‪ >= 51‬ناتج القسمة بتخزن في ‪ ، al = 2‬وباقي القسمة بتخزن في‬
‫‪ah = 26‬‬
‫رح نظهر أول اشي على ‪ seg-7‬ناتج القسمة وهو ‪ ( 2‬بنبعث هاي القيمة للعداد ‪ cx = 2‬وبنمشي في‬
‫‪ loop‬وبنضل نزيد في مؤشر ال‪ array‬حتى يوصل عند كود ‪) 2‬‬
‫ثم بنفعل ال ‪ seg-7‬اللي بدي اياها من خالل الكتابة على ‪ address ff29‬الخاص في بورت ‪B‬‬
‫ثم بنكتب على ‪ address ff28‬الخاص في بورت ‪ : A‬القيمة الي بأشر عليها المؤشر حاليا ً وهي كود ‪2‬‬
‫وهيك بكون أظهرت العدد الصحيح على ال ‪ ،Seg-7‬ضل اللي بعد الفاصلة >>>>>>>>>>>>>>>>>>>‬
‫بنضرب باقي القسمة في ‪ >= 10‬بصير ‪ ، 260‬ثم بنقسمه على ‪ ، 51‬بنشوف ناتج القسمة إيش هو ألنه هو‬
‫اللي بهمني حاليا ً ألنه أنا بدي بس أول عدد بعد الفاصلة العشرية‪ ،‬بتخزن ناتج القسمة في ‪al = 5‬‬
‫ثم عشان نظهره على ‪ seg-2‬نفس الفكرة ( بنبعث هاي القيمة للعداد ‪ cx = 5‬وبنمشي في ‪ loop‬وبنضل‬
‫نزيد في مؤشر ال ‪ array‬حتى يوصل عند كود ‪) 5‬‬
‫ثم بنفعل ال ‪ seg-7‬اللي بدي اياها من خالل الكتابة على ‪ address ff29‬الخاص في بورت ‪B‬‬
‫ثم بنكتب على ‪ address ff28‬الخاص في بورت ‪ : A‬القيمة الي بأشر عليها المؤشر حاليا ً وهي كود ‪5‬‬
‫وهيك بكون أظهرت العدد العشري على ال ‪Seg-7‬‬

‫‪27‬‬
NOTE: we added delay after each display; to display different values on different
seven-segment displays at the same time.

================================================================

.‫وارض عنها وأرضِ ها‬


َ ‫ اللهم حقق لِمرح ما تتمنى‬:‫ثانية من وقتك‬
❤ ‫ولك بالمثل‬

28
Exp 6: DAC0832 digital-to-analog conversion

Objectives:
1. Understanding of the basic principles of digital/analog conversion, and master
the use of DAC0832 chips.
2. To know the application of DAC0832.

In electronics, digital-to-analog converter (DAC) is a system that converts a digital


signal into an analog signal. The DAC0830 is an advanced CMOS 8-bit multiplying
DAC designed to interface directly with the 8080, 8048, 8085, Z80, and other popular
microprocessors. DACs are commonly used in music players to convert digital data
streams into analog audio signals. They are also used in televisions and mobile
phones to convert digital video data into analog video signals which connect to the
screen drivers to display monochrome or color images.

In this lab, we will use the DAC0832 to create a simple function generator
(square, and sine waves).

29
PART ONE: SQUARE WAVE

STEPS TO WRITE THE CODE:


1. Write to DAC - value 255
2. Wait for delay (DON)
3. Write to DAC - value 0
4. Wait for delay (DOFF)

30
PART TWO: SINE WAVE

Range of Sin [-1,1] ========> ‫] ؟‬0,5[ ‫كيف رح نحوله ل‬


⇒ 2.5 * (sin(x)+1) ⇒ 2.5 sin(x) + 2.5
2.5 output value (analog)

But the equation for the input:


DACInput = 127 + 127 sin(radiant(θ))

‫ بنعوض ابتدا ًء من الصفر وبنصير نزيد‬،‫ بنا ًء على هاي المعادلة‬digital ‫ قيم‬DAC ‫يعني رح ندخل على‬
‫ قيمة‬36 ‫واحد واحد لحتى نوصل‬

31
Exp 7: LED 16x16 Dot Matrix Display

The LED 16x16 dot matrix display is made up of 256 LEDs arranged in 16 rows and
16 columns. It operates using a common-cathode configuration, meaning all LED
cathodes are connected in columns and all anodes in rows. By controlling the rows
and columns, each LED can be turned on or off individually, allowing for the display
of text, images, and animations.
To control the display, you activate specific rows and columns to light up certain
LEDs. For example, pulling a row high and a column low will turn on the LED at the
intersection. This setup minimizes the number of pins required to control all LEDs
(32 pins in total).
Rows are active-high, but columns are active-low.

The display is refreshed quickly by scanning through rows and columns, creating an
illusion of continuous images or animations.

The image shows an example of the circuit where different rows and columns are
connected to a microprocessor to control the display.

Our experiment uses two 8x8 dot matrix displays as 16x8 displays, which means
they have eight rows and sixteen columns. The matrix is connected to the 8255 IC.
Columns have two ports and rows have one port.

Rows Port C (FF2AH)

First 8 columns Port A (FF28H)

Second 8 columns Port B (FF29H)

32
‫‪PART ONE: Display a one number from:‬‬

‫‪The following code for number 6‬‬

‫‪R‬‬ ‫‪D‬‬
‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫)‪(7‬‬
‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪2‬‬ ‫)‪(6‬‬
‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪3‬‬ ‫)‪(5‬‬
‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪4‬‬ ‫)‪(4‬‬
‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪5‬‬ ‫)‪(3‬‬
‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪6‬‬ ‫)‪(2‬‬
‫‪0‬‬ ‫‪0‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪1‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪7‬‬ ‫)‪(1‬‬
‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪0‬‬ ‫‪8‬‬ ‫)‪(0‬‬

‫‪C‬‬ ‫‪1 2 3 4 5 6 7 8‬‬

‫اعملنا ‪ Arrays 2‬وحدة للصفوف ووحدة لألعمدة ‪ ،‬بنمشي على مصفوفة األعمدة وبنفعل عمود عمود بكل‬
‫لفة ‪ ،‬وبنمشي على مصفوفة الصفوف حسب الضو اللي بدنا نضويه بنبعث القيمة‪.‬‬
‫يعني مثالً بأول لفة بفعل العمود األول كله بس الضواو اللي رح يضووا حسب شو فعلت من الصفوف فما رح‬
‫يضوي اشي‪ ،‬ثاني لفة رح يضوي من العمود الثاني الصف الثالث والرابع والخامس والسادس وهكذا‪.‬‬
‫احنا بنمشي عمود عمود بس بسبب السرعة رح يبين كأنه ضووا كلهم بنفس الوقت‪.‬‬

‫‪33‬‬
‫‪PART TWO: Basic animation on 8x16 LED matrix‬‬

‫المطلوب في هذا البارت هو كتابة برنامج يقوم بعرض حركة بسيطة على شاشة ‪LED 8x16‬‬
‫العملية المطلوبة هي تشغيل عمود واحد فقط من األعمدة الـ ‪ 16‬بشكل متتابع بدءاً من العمود األول (‪ )C1‬حتى العمود‬
‫األخير (‪ ،)C16‬ثم العودة بالعكس إلى العمود األول مرة أخرى‪.‬‬
‫الكود ممكن ينكتب بطريقتين‪ :‬األول عمل مصفوفة لألعمدة (تفعيل عمود عمود) والثانية استخدام أمر ‪ROL‬‬

‫‪34‬‬
‫‪Exp 8: Controlling a DC Motor‬‬

‫‪The purpose of this experiment is to examine the operation of a DC motor to learn its‬‬
‫‪basic wiring connections and how to control its speed by using DAC.‬‬

‫توضح الصورة التالية دائرة تشغيل محرك ‪ DC‬على لوحة ‪ .MML8086K3‬يتم تضخيم اإلشارة الناتجة من‬
‫ال‪ DAC‬للتحكم في المحرك‪ .‬يستقبل ال‪ DAC‬رقما ً بين ‪ 0‬و ‪ 255‬من المعالج الدقيق للتحكم في سرعة المحرك‪.‬‬

‫‪DC MOTOR:‬‬

‫هو جهاز يحول الطاقة الكهربائية إلى طاقة حركية‪ ،‬يعمل المحرك عن طريق توليد مجال مغناطيسي يتفاعل مع الملفات‬
‫الداخلية‪ ،‬مما يؤدي إلى دوران العمود المتصل بالمحرك‪ .‬يمكن التحكم في سرعة المحرك بسهولة عن طريق تغيير‬
‫الجهد أو التيار الذي يتم تزويده به‪.‬‬

‫ُتستخدم محركات الـ ‪ DC‬في العديد من التطبيقات مثل األجهزة المنزلية‪ ،‬الروبوتات‪ ،‬والمركبات الكهربائية‪ ،‬نظراً‬
‫لقدرتها على توفير عزم دوران ثابت وسهولة التحكم في سرعتها‪.‬‬

‫‪35‬‬
We are using a DAC0832 to drive the motor and contour; its speed. The push
buttons will increase and decrease the speed of the motor by 10 each time
Values below 0 or above 255 will be ignored

Addresses in the Experiment:


DC motor I/O ff80H

push buttons 8255 port A ff28H

:‫اللي رح نعمله باختصار‬


‫ وحدة بتعمل زيادة لسرعة الموتور ووحدة بتعمله نقصان‬8255 ‫ في‬A ‫في عنا كبستين موصولين مع بورت‬
.‫ بنقرأ أي كبسة اللي مكبوسة عشان نتحكم في سرعة الموتور‬، 10 ‫بمقدار‬

36
Exp 9: Controller a Stepper Motor

Stepper motors are DC motors that move in discrete steps. They have multiple coils
that are organized in groups called "phases". By energizing each phase in sequence,
the motor will rotate, one step at a time. By controlling the stepping of the motor, you
can achieve very precise positioning and/or motor speed. For this reason, stepper
motors are the motor of choice for many precision moon control applications.

The resolution of a stepper motor is often expressed as degrees per step.


For example, a 1.8° motor is the same as a 200 step/revolution motor.

Ex: 1.8° ====> 1 step


360° ====> ?
steps = (360 *1) / 1.8 = 200 Steps

The difference between Unipolar and Bipolar Stepper Motor:

Unipolar Bipolar

37
Operating Modes:

1. full step (on one-phase): the motor is operated with only one phase energized at
a me. This mode requires the least amount of power from the driver of any of the
other modes. (‫)بفعل ملف وبعطل الباقي‬

:‫بالكود‬
D7 D6 D5 D4 D3 D2 D1 D0
first step ⇒ 0 0 0 1 0 0 0 1
second step ⇒ 0 0 1 0 0 0 1 0

‫ وما‬Rotate ‫ بس عشان تزبط عملية ال‬bits 4 ‫ اللي بلزمونا بس‬، rotate ‫وهكذا بنضل نعمل‬
.bits 4 ‫ ألصفار كررنا قيمة الـ‬rotate ‫يصير يعمل‬

2. Half step: it is a combination of one phase on and two phase on full step modes.
This results in half the basic step angle. This smaller step angle provides smoother
operation due to the increased resolution of the angle.

:‫بالكود‬
D7 D6 D5 D4 D3 D2 D1 D0
first step ⇒ 0 0 0 0 0 0 0 1
second step ⇒ 0 0 0 0 0 0 1 1
third step ⇒ 0 0 0 0 0 0 1 0

and so on ….

38
Stepper motor FF28H (port A)

Push buttons FF29H (port B)

PART ONE: Rotate the stepper motor continuously

For full step ⇒

For half step ⇒

39
PART TWO: Use two push buttons to control the rotation of the stepper
motor.
When btn1 is pressed, the motor rotates in a clockwise direction continuously,
and btn2 rotates the motor in a counterclockwise direction.

‫ بنفحص مين هو اللي كابسين عليه‬portB ‫ من‬Buttons ‫بنقرأ ال‬


rotate right ‫ أو‬rotate left ‫ اللي مكبوس بعمل‬button ‫حسب ال‬

40
PART THREE: Update Task 2 by rotating left the stepper motor a single
rotation (360°) whenever a first button is pressed and rotating right the
stepper motor a half rotation (180°) whenever a second button is
pressed.

.Steps ‫ و بنمشي في لوب بعدد ال‬، Steps ‫بنحسب عدد ال‬

41
Exp 10: Graphical 128x64 Dot Matrix LCD

The Graphical LCDs are thus used to display customized characters and images.
The LCD used in this lab has 128×64 dots and has a yellow-green color backlight.

The 128x64 LCD is divided into two equal halves with each half being controlled by a
separate controller, and the whole LCD is divided equally into 8 pages. Each page
consists of 8 rows and 64 columns. So two horizontal pages make 128 (64×2)
columns and 8 vertical pages make 64 rows (8×8). The paging scheme of the
graphical LCD can be easily understood from the following table:

) pixels 64 ‫ كل قسم‬right ‫ و‬left ‫ (مقسم لقسمين‬pixels 128 ‫ والعرض‬pixels 64 ‫الطول‬


‫ صفوف‬8 ‫ عمود و‬64 ‫ يحتوي على‬page ‫ كل‬pages 8 ‫كل قسم عبارة عن‬

42
‫يتم توصيل الـ ‪ LCD‬مع ‪ ، 8255‬يتم استخدام ‪ports 2‬‬
‫‪port A (FF28H) ⇒ DATA‬‬
‫‪port C (FF2AH) ⇒ CONTROL‬‬

‫وظائف إشارات التحكم (‪ )Control Signals‬المستخدمة في توصيل شاشة ‪:GLCD‬‬

‫‪:)RS) Register Select‬‬

‫● تحدد هذه اإلشارة ما إذا كانت البيانات المرسلة هي بيانات أو أوامر‪.‬‬


‫● إذا كانت ‪ ،RS = 1‬فإن البيانات المرسلة إلى الشاشة ُتعتبر بيانات (مثل الحروف أو الصور)‪.‬‬
‫● إذا كانت ‪ ،RS = 0‬فإن البيانات المرسلة ُتعتبر أوامر تحكم (مثل إعداد الشاشة أو تحريك المؤشر)‪.‬‬

‫‪:)RW) Read/Write‬‬

‫● تحدد ما إذا كان النظام يقوم بقراءة أو كتابة البيانات‪.‬‬


‫● إذا كانت ‪ ،RW = 1‬يتم قراءة البيانات من الشاشة‪.‬‬
‫● إذا كانت ‪ ،RW = 0‬يتم كتابة البيانات إلى الشاشة‪.‬‬

‫‪:)E) Enable‬‬

‫● تعمل هذه اإلشارة كنبضة‪.‬‬


‫● يتم تفعيل العملية (القراءة أو الكتابة) عند تفعيل النبضة (من منخفض إلى مرتفع ثم منخفض)‪.‬‬

‫‪ CS1‬و ‪: CS2‬‬
‫‪ Chip Select 2).‬و ‪(Chip Select 1‬‬

‫● تستخدم لتحديد أي نصف من الشاشة يتم التعامل معه‪.‬‬


‫● إذا كانت ‪ CS1 = 1‬و ‪ ،CS2 = 0‬يتم التعامل مع النصف األيسر من الشاشة‪.‬‬
‫● إذا كانت ‪ CS1 = 0‬و ‪ ،CS2 = 1‬يتم التعامل مع النصف األيمن من الشاشة‪.‬‬

‫‪:)RST) Reset‬‬

‫● هذه اإلشارة ُتستخدم إلعادة ضبط الشاشة‪.‬‬


‫● عندما تكون اإلشارة منخفضة (‪ ،)RST = 0‬يتم إعادة تعيين إعدادات الشاشة إلى الوضع االفتراضي‪.‬‬

‫‪43‬‬
ِ ‫ الخاص‬Group byte B ‫رح نستخدم في هاي التجربة‬
:8255 ‫ب‬
port C ‫ معين في‬bit ‫ ل‬reset ‫ أو‬set ‫بمكننا نعمل‬

D7 D6 D5 D4 D3 D2 D1 D0

0 X X X
BSR DON’T CARE PORT C BIT SELECT 1 = SET
MODE 0 = RESET

EXAMPLES:
1. To set bit PC0, you write the following value to the control register (not Port
C): 0000 0001B
Mov dx,0ff2bh ; address of cwr
Mov al,00000001b
Out dx,al
2. To reset bit PC7, you write the following value to the control register (not Port
C): 0000 1110B
Mov dx,0ff2bh ; address of cwr
Mov al,00001110b
Out dx,al

How do we select the left half?


CS1 = 1 and CS2 = 0
PC6 ‫ مشبوك مع‬CS2 ‫ و‬PC4 ‫ مشبوك مع‬CS1 ‫) بنالحظ أنه‬8255 ‫ب‬
ِ GLCD ‫من الرسمة (توصيل‬
.‫ زي األمثلة اللي فوق‬BSR MODE ‫ من خالل‬PC6 ‫ ل‬RESET ‫ و‬PC4 ‫ ل‬SET ‫ نعمل‬: ‫ اللي رح نعمله‬،‫اوك‬

How do we select the right half?


CS1 = 0 and CS2 = 1
.BSR MODE ‫ من خالل‬PC4 ‫ ل‬RESET ‫ و‬PC6 ‫ ل‬SET ‫بنعمل‬

44
The basic operation with a graphical LCD requires the following steps:
1. LCD Initialization (send the command “Display ON”)
Refer to the Instruction List, data appears when DB0 is set to 1 and
disappears when DB0 is 0. When the display is off, there is no effect on the
data which is stored in DDRAM.
a. Activate both halves of the display (CS1 = 1, CS2 = 1)
b. Specify the value of the Display ON/OFF command.
c. Use the SendCommand procedure to write the command to the
instruction register of the LCD.

D0 = 0 => OFF / D0 = 1 => ON ‫ بنفعله كيف؟ حسب الجدول إذا كان‬، left half ‫بنختار‬

Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0

ON / OFF L L L L H H H H H L/H

.SendCommand procedure ‫ من خالل‬GLCD ‫ نبعثها ل‬AL = 00111111


‫ وبنعيد نفس الخطوات‬right half ‫ وبنختار ال‬delay ‫ثم بنستنى‬

>> Sending command to LCD (sendCommand):


1. Send the command value (from the list above) to the data bus (PA)
2. Reset RS to 0 (select Instruction register) to control bus (PC)
3. Reset R/W to 0 (write mode) to control bus (PC)
4. Reset Enable (E) to 0 to control bus (PC)
5. Wait for some delay
6. Set Enable (E) to 1 to control bus (PC)
7. Wait for some delay
8. Reset Enable (E) to 0 to control bus (PC) (this is necessary to latch data into
input register)

45
‫ أو‬SET ‫ عشان نعمل لهم‬، PC2 ‫ مشبوك مع‬E ‫ و‬PC1 ‫ مشبوك مع‬R/W ‫ و‬PC0 ‫ مشبوك مع‬RS ‫بنالحظ أنه‬
.PORT C 8255 ‫ب‬ ِ ‫ الخاص‬BRS MODE ‫ حسب الخطوات السابقة بنستخدم‬RESET
PCTL is The address of CWR 8255

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

2. Set Cursor: Page Selection (X address) and Column Selection (Y


address) (SetCursor procedure)

46
>> SetCursor Procedure (select page and column numbers):
Use the (sendCommand) procedure to send the following values:
1. Select the column address (Y address). You can choose any value from
column 0 to 63. The address starts at 0x40 to address 0x7F (from the list
below).

Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0

Y address L L L H Y address (0-63)

2. Select the page address (X address) You can choose any value from page 0
to 7. The address starts at 0xB8 to address 0xBF (from the list below).

Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0

X address L L H L H H H Page (0-7)

3. Select the row address (Z address). Usually, this address is kept in the first
row. The address is 0xC0 (from the list below)

Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0

Z address L L H H Start Line (0-63)

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
3. Data Display.

Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0

Write H L Write Data

Read H H Read Data

47
● The block of data to be displayed should be prepared in a form of array. You
can find a proposed encoding of characters in an attached file. Each block is
designed as 7x8 pixels (7 columns by 8 rows).
● To print a block to the display, you have to loop through all the bytes of the
block and send them to display via the SendData procedure. Note that it is not
necessary to increment the Y address (column address) after displaying each
byte since it is done automatically.

>> Sending data to be displayed to LCD (sendData):


To send a value of a single column of a page to be displayed on the LCD (1 byte),
you have to do the following:
1. Send the byte (column) value to the data bus (PA)
2. Set RS to 1 (select data register) to control bus (PC)
3. Reset R/W to 0 (write mode) to control bus (PC)
4. Reset Enable (E) to 0 to control bus (PC)
5. Wait for some delay
6. Set Enable (E) to 1 to control bus (PC)
7. Wait for some delay
8. Reset Enable (E) to 0 to control bus (PC) (this is necessary to latch data into
input register)

48
================================================================
PART 1:
Print a single character (A) at the left-top side of the LCD (left half, first column, first
page).

49
50
51
PART 2:
Print (Hello) starting at the same previous position (refer to charMapping file to
retrieve character code.
‫ لكل حرف‬array ‫نفس الكود السابق بس الفرق أنه رح نعمل‬

52
PART 3: Clear the GLCD

53
Exp 11: Memory Read/Write

Objectives:
● To know the application of static RAM
● To master the R/W data programming method of static RAM

NOTES:
◄ SIZE OF RAM : 64 K
◄ ADDRESS RANGE : 00000H - 0FFFFH
◄ Static RAM (or SRAM) is a type of random-access memory (RAM) that uses
latching circuitry (flip-flop) to store each bit.
◄ SRAM is volatile memory; data is lost when power is removed.

The difference between SRAM and DRAM: (‫)فيهم زيادة عن المانيوال ما بعرف إذا كلهم مطلوبين‬

Feature SRAM (Static RAM) DRAM (Dynamic RAM)

Memory Cell Uses flip-flops to store Uses capacitors and


data transistors

Speed Faster Slower

Power Consumption Consumes more power Consumes less power

Density Lower density (larger size Higher density (smaller


per bit) size per bit)

Cost More expensive Less expensive

Typical Use Cache memory (e.g., Main memory (e.g.,


CPU cache) system RAM)

Data Retention Retains data as long as Needs constant


power is supplied refreshing to retain data

Complexity More complex circuitry Simpler circuitry

Experiment Procedure:
1. Memory Write:

Reminder 1: DS ⇒ Data segment


Reminder 2: BX is the default offset for DS.

54
Reminder 3:
No immediate to segment moves, so mov DS,0 X
Solution: mov AX,0
mov DS,AX
Reminder 4:
starting address (DS, CS, ES, SS( )1 : ‫عشان أوصل ِإلشي بالميموري بلزمني أحدد‬
offset (2
Reminder 5:
To calculate the physical address : (Starting * 10H) + offset

2. Memory Read:
★ Control the speed of the DC motor by using the byte values from the
SRAM (stored in step 1), where the byte at address 100h represents
the first speed and so on.
★ Use 4 push buttons to control the speed of the DC motor (BTN0 for the
first speed, and so on).
★ Assume that the push buttons are connected to Port A from 8255 IC.

55
‫================================================================‬
‫<< بالتوفيق >>‬

‫‪56‬‬

You might also like