rotate_ conditional and io

112
Rotate and Shift

Upload: mohd-jamal-mohd-moktar

Post on 05-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 1/112

Rotate and Shift

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 2/112

Rotate and Shift

Contains instructions to rotate and shiftbits around.

Logical Shift Left/Right (LSL/LSR):Shifts bits to left or right by inserting zeros.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 3/112

LSL (Logical Shift Left)

0

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 4/112

LSR (Logical Shift Right)

0

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 5/112

Example: LSLD0 = $000000AAD1 = $00000008LSL.W D1,D0

0 0 A AD0.W =

A A 0 0D0.W =LSL

0 0

Pushed out

0000 0000 1010 1010 0000 0000

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 6/112

Example: LSRD0 = $000000AALSR.W #4,D0

0 0 A AD0.W =

0 0 0 AD0.W =

LSR 0

Pushed out

0 0 A AD0.W =

0000 0000 0000 1010 1010

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 7/112

ROL & ROR (Rotate Left/Right)

Pushes out MSB, and moves the bits tothe back.

C set to last bit pushed out.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 8/112

ROL (Rotate Left)

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 9/112

ROR (Rotate Right)

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 10/112

Example: ROLD0 = $000000ABD1 = $00000003ROL.B D1,D0

0 1 0 1D0.B = 1 1 0 1

1 0 1 0D0.B = 1 0 1 1

1 0 1 0D0.B = 1 0

Pushed out… 

1 0 1 1 1

 And sent to back… 

New D0 = $0000005D

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 11/112

Example: RORD0 = $000000ABROR.B #4,D0

1 0 1 0D0.B =

1 0 1 1D0.B =

Pushed out… 

1 0 1 1

1 0 1 0

1 0 1 0D0.B = 1 0 1 11 0 1 1

 And sent to front… 

New D0 = $000000DA

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 12/112

Branch Instructions

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 13/112

Branch Instructions

Branch instructions are instructions thattransfer execution of the program to

another location. The new location is marked by a label.

The format is BRA <label>.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 14/112

Unconditional Branching Example

Instruction #1

Instruction #2

BRA HERE

Instruction #3

Instruction #4

HERE Instruction #5

Instruction #6

Never executed.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 15/112

Infinite Loop Example

REPEAT Instructions #1

Instructions #2… 

Instructions #n

BRA REPEAT

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 16/112

Compare and Branch

In BRA, the program will branch unconditionallywhen it encounters the BRA command.

A branch instruction may also be given a

condition:Called Bcc (Branch when condition is true). If the tested condition is true, then branch to <label>. If the tested condition is not true, then just execute

next line. To test the condition, the CMP (Compare)

instruction is used.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 17/112

Bcc Flowchart

START

Evaluate condition

using CMP

Condition =TRUE?

Go to LABEL Execute next line

FINISH

TRUE FALSE

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 18/112

Conditions (cc)

Bcc

BGT

BGE

BEQ

BNE

BLE

BLT

D0.B > D1.B

D0.B ≥ D1.B

D0.B = D1.B

D0.B ≠ D1.B

D0.B ≤ D1.B

D0.B < D1.B

CMP.B D1,D0

*(Antonakos, pg. 84)

BRA: Branch Unconditionally.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 19/112

Bcc Format

LABEL Instructions #1

Instructions #2

… Instructions #n

Test Condition (CMP)

Bcc LABEL

Instructions after Bcc… 

If condition = TRUE

If conditions = FALSE

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 20/112

Bcc Format

Test Condition (CMP)

Bcc LABEL

Instructions #1

Instructions #2

… 

Instructions #n

LABEL Instructions after LABEL… 

If conditions = TRUE,Instructions 1 nwill not be executed

If conditions = FALSE,Instructions after LABELexecuted line-by-line.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 21/112

If…Else 

If…Else is tests a condition, and

determines whether it is true or not.

If the condition is true, execute a block ofstatements.

Else, execute another block of statements.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 22/112

Example: If…Else Using Bcc 

Check the byte stored in D3. If D3 > 10,clear the byte. Else, add 3 to the value

stored in D3.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 23/112

FlowchartSTART

Move valueto D3

D3 > 10?

Clear D3 D3 = D3 + 3

FINISH

True False

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 24/112

Assembly Code

START ORG $1000

MOVE.B #11,D3

CMP.B #10,D3

BGT MORE

BLE LESS

MORE CLR.B D3

BRA FINISH

LESS ADD.B #3,D3

FINISH END START

D3.B > 10

D3.B < 10

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 25/112

Example: If…Else Using Bcc 

Check the value of 1 byte stored atmemory location $2000. If the value is

equal to zero, then replace it with $FF.Else, do not change its value.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 26/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 27/112

Program

START ORG $1000

MOVE.B $2000,D0

CMP.B #0,D0

BEQ ISZERO

BNE NOTZERO

ISZERO MOVE.B #$FF,$2000

BRA HABIS

NOTZERO NOP (NO OPERATION)

HABIS END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 28/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 29/112

Flowchart

Graphical method to plan flow of ourprograms.

Shows program‟s step-by-step operation. Easy to understand and analyze.

Can be used to write organized programs.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 30/112

Flowchart

Basic shapes:

Terminator.

Process.Decision.

Input/Output.

Connectors.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 31/112

Basic Shapes – Terminator

Indicates beginning and end of flowchart.

Once at beginning, once at end.

Examples:

START FINISH

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 32/112

Basic Shapes - Process

Describes actions to be done.

Represented as rectangles.

Short description of process in rectangle.

Example:

A = A + B Reset Ports Clear D0

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 33/112

Basic Shapes - Decision

Shows alternative program flow based oncondition.

Represented as diamond shape. Should have 2 arrows, representing

TRUE and FALSE program flows.

Can be used in “if…else”, “while”, and “for”situations.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 34/112

Basic Shapes - Decision

Examples:

D0 = 3?

TRUE FALSE

Port is active?TRUE

FALSE

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 35/112

Basic Shapes – Input/Output

Shows the process of inputting oroutputting data.

Represented using rhombus. Examples:

Input D0 Show calculationresults

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 36/112

Basic Shapes - Connectors

Used to link large process flows together.

Represented using circles, with numbers

inside. Numbers indicate connection.

Examples:

1 3

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 37/112

Example: Connector

START

Input D0

Input D1

1

D0 = D0 x D1

1

FINISH

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 38/112

Writing the Program

Once flowchart is complete, write code toimplement program.

Follow program flow closely. Check and fix problems if necessary.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 39/112

Example 1

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 40/112

Example 1D0

D1

START

Input D0

Input D1

1

D0 = D0 x D1

1

FINISH

Write a program that calculatesthe area of a rectangle usingM68000 assembly language.The length and width of therectangle is stored in D0 and D1.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 41/112

Translation to Assembly

START

Input D0

Input D1

D0 = D0 x D1

FINISH

START ORG $1000

MOVE.W #$0012,D0

MOVE.W #$0034,D1

MULU D1,D0

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 42/112

Complete Program

START ORG $1000

MOVE.W #$0012,D0

MOVE.W #$0034,D1

MULU D1,D0

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 43/112

Example 2

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 44/112

Example 2

Two numbers are stored in memorylocations $5000 (A) and $6000 (B).

If A is larger than B, then move A tomemory location $7000.

If B is larger than A, then move B to

memory location $7000.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 45/112

Flowchart & ProgramSTART

ENTER DATAINTO A & B

A > B?

STORE AAT $7000

STORE BAT $7000

FINISH

START ORG $1000

MOVE.B #3,$5000

MOVE.B #4,$6000

MOVE.B $5000,D0

MOVE.B $6000,D1

CMP.B D1,D0

BGT SIMPANA

BLE SIMPANBSIMPANA MOVE.B D0,$7000

BRA HABIS

SIMPANB MOVE.B D1,$7000

HABIS END START

TRUE FALSE

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 46/112

Example 3

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 47/112

Example 3

Memory locations $1100 to $1109contains 10 bytes of data. Write a

program that adds together the 10 bytesand stores them in D1.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 48/112

Flowchart

START

Input numbersinto memory

locations.

D0 = 10

Load startingaddress into A0

Clear D1

FINISH

D0 = 0?

D1 = D1 + (A0)

FALSE

Go to next

memory location

D0 = D0 - 1

TRUE

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 49/112

START

Input numbersinto memory

locations.

Load startingaddress into A0

ORG $1000

MOVE.B #$11,$1100

MOVE.B #$22,$1102

MOVE.B #$33,$1104MOVE.B #$44,$1106

MOVE.B #$55,$1108

MOVE.B #$66,$110A

MOVE.B #$77,$110C

MOVE.B #$88,$110E

MOVE.B #$99,$1110

MOVE.B #$11,$1112

MOVE.L #$001100,A0

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 50/112

D0 = 10

Clear D1

D0 = 0?

D1 = D1 + (A0)

FALSE

D0 = D0 - 1

MOVE.B #10,D0

CLR.B D1

Go to nextmemory location

CMP.B #$0,D0, LOOP…BNE LOOP

ADD.B (A0),D1

ADD.L #1,A0

FINISH

SUB.B #1,D0

END

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 51/112

Complete Program

START ORG $1000

MOVE.B #$11,$1100

MOVE.B #$22,$1102

MOVE.B #$33,$1104MOVE.B #$44,$1106

MOVE.B #$55,$1108

MOVE.B #$66,$110A

MOVE.B #$77,$110C

MOVE.B #$88,$110E

MOVE.B #$99,$1110

MOVE.B #$11,$1112

MOVE.L #$1100,A0

MOVE.B #10,D0

CLR.B D1

LOOP ADD.B (A0),D1

ADD.L #1,A0SUB.B #1,D0

CMP.B #0,D0

BNE LOOP

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 52/112

I/O Interfacing

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 53/112

I/O Interfacing

M68k can also be used to control devices suchas: Switches.

7-Segment.

LED (Light Emitting Diodes).

DC Motors.

M68k cannot control the devices directly, it hasto use the M68230 I/O chip to control thedevices.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 54/112

M68230 Interfacing

Memory

CS*

M68k

M68230

Port A

Port B

Port C

Data BusDevice #1

Device #2

Device #3

(LED, Switches, Motor,7-Segment, Keypad, etc.)

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 55/112

Registers in M68230

M68230 contains 23 registers.

Before using the M68230, the M68230 needs tobe initialized.

Initialization is done by configuring certainregisters in the M68230: Port General Control Register.

Port X Control Register (A, B).

Port X Data Direction Register (A, B, C).

Port X Data Register (A, B, C).

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 56/112

Port Addresses: Example

PI/T ADDRESSABLE REGISTER    ABBREVIATION   ADDRESS 

Port General Control Register PGCR $800001

Port A Data Direction Register PADDR $800005

Port B Data Direction Register PBDDR $800007

Port C Data Direction Register PCDDR $800009

Port A Control Register PACR $80000D

Port B Control Register PBCR $80000F

Port A Data Register PADR $800011

Port B Data Register PBDR $800013

Port C Data Register PCDR $800019

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 57/112

Initializing M68230 Registers

To set the M68230 to device bit I/O mode,the settings are:

Set PGCR to $00.Set PACR and PBCR to $80.

Set PADDR and PBDDR based on datadirection.

For input devices, set bit to 0. For output devices, set bit to 1.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 58/112

M68230 Initialization

PGCR EQU $800001

PADDR EQU $800005

PBDDR EQU $800007

PCDDR EQU $800009

PACR EQU $80000DPBCR EQU $80000F

PADR EQU $800011

PBDR EQU $800013

PCDR EQU $800019

MOVE.B #$00,PGCRMOVE.B #$80,PACR

MOVE.B #$80,PBCR

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 59/112

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 60/112

Example: LED

PB0

PB1

PB2

PB3

PB4

PB5

PB6

PB7

M68230

MOVE.B #$FF,PBDDR

E l LED & S it h

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 61/112

Example LED & Switches(PADDR = $00, PBDDR = $FF)

PA0 PB0

PA1 PB1

PA2 PB2

PA3 PB3

PA4 PB4

PA5 PB5

PA6 PB6

PA7 PB7

M68230LED0

LED1

LED2

LED3

LED4

LED5

LED6

LED7

+5V

R

R

R

R

R

R

R

R

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 62/112

Example: 7-Segment

B0

B1

B2

B3

B4

B5

B6

B7

a

b

c

d

e

f

g

M68230

MOVE.B #$FF, PBDDR 

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 63/112

Example: 7-Segment + BCD

DecoderB0

B1

B2

B3

B4

B5

B6

B7

a

b

c

d

e

f

g

M68230

BCD 7-Seg

Decoder

MOVE.B #$0F,PBDDR

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 64/112

Port X Data Registers (PXDR)

Can either be PADR, PBDR or PCDR.

Contains the data sent/received by the

hardware.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 65/112

Example: Read Data from Switches

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 66/112

Example: Read Data from Switches(MOVE.B PADR,D0)

PA0 PB0

PA1 PB1

PA2 PB2

PA3 PB3

PA4 PB4

PA5 PB5

PA6 PB6

PA7 PB7

M68230+5V

R

R

R

R

R

R

R

R

If a switch is closed (activated), itwill generate a „1‟ inside the PXDR. In this example, the data fromswitches is stored inside D0 in theM68000 data register.

MOVE.B PADR,D0

Using this command, the valueinside D0 will be:

D0 = $00000000  

D0 = $000000C3

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 67/112

7-Segment

Consists of 7-LEDsarranged together.

Can display numbers and

characters. Each segment is marked

with a letter (a to g).

To display characters,

need to turn on/off certainsegments.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 68/112

Displaying Numbers

b c d e f g Numbera

1 0 0 0 0 0 11

1 0 1 1 0 1 21

1 1 1 0 0 1 31

1 1 0 0 1 1 40

0 1 1 0 1 1 51

0 1 1 1 1 1 60

1 1 0 0 0 0 71

1 1 1 1 1 1 81

1 1 0 0 1 1 91

1 1 1 1 1 0 01

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 69/112

Example: Display 4 on 7-Segment

B0

B1

B2

B3

B4

B5

B6

B7

a

b

c

d

e

f

g

M68230

MOVE.B #$ 66, PBDR 

In this example, to display „4‟

on the 7-segment, b, c, e, f,and g must be turned on, andthe rest turned off. This can bedone by sending $66 to the

PBDR.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 70/112

The 7448 BCD to 7 Segment

Decoder The 7448 decoder can simplify the transfer of

data to the 7-segment.

It converts BCD values directly into thenecessary signals to turn on the 7-segment.

If the decoder is present, there is no need toconsider the values of a-b-c-….-g, just send the

number to be displayed and it is automaticallyshown.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 71/112

7-Segment + BCD Decoder

B0

B1

B2

B3

B4

B5

B6

B7

a

b

c

d

e

f

g

M68230

BCD 7-Seg

Decoder

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 72/112

Displaying NumbersA3 A2 A1 A0 Number

0 0 0 1 1

0 0 1 0 2

0 0 1 1 3

0 1 0 0 4

0 1 0 1 5

0 1 1 0 6

0 1 1 1 7

1 0 0 0 8

1 0 0 1 9

0 0 0 0 0

a

b

c

d

e

f

g

BCD 7-Seg

Decoder

A3

A2

A1

A0

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 73/112

Sample Programs

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 74/112

Example 1

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 75/112

Example 1: Set LED

PB0

PB1

PB2

PB3

PB4

PB5

PB6

PB7

M68230A set of LEDs are connected toPort B in M68230. Write a programthat turns on LED3 and LED4, andturns off the rest.

LED0

LED1

LED2

LED3

LED4

LED5

LED6

LED7

Port Address

PGCR $800001

PACR $800005

PBCR $800007

PADDR $800009

PBDDR $80000D

PCDDR $80000F

PADR $800011

PBDR $800013

PCDR $800019

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 76/112

Discussion

Port B should be initialized before beingused.

To turn on LED, the voltage at Port B bitsshould be high.

To turn off LED, the voltage at Port B

should be low.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 77/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 78/112

Solution

START ORG $1000

PGCR EQU $800001

PBCR EQU $800007

PBDDR EQU $80000D

PBDR EQU $800013

INIT MOVE.B #$00,PGCR

MOVE.B #$80,PBCR

MOVE.B #$FF,PBDDR

ONLED MOVE.B #%00011000,PBDR

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 79/112

Example 1: Set LED

PB0

PB1

PB2

PB3

PB4

PB5

PB6

PB7

M68230LED0

LED1

LED2

LED3

LED4

LED5

LED6

LED7

0

0

0

1

1

0

0

0

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 80/112

Example 2

E l 2 R d S i h &

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 81/112

Example 2: Read Switches &Output to LED

A set of switches are connected to Port A,and a set of LEDs are connected to Port B

in M68230. Write a program that readsthe value in the switches and turns on therespective LEDs.

Circuit Diagram

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 82/112

Circuit Diagram

PA0 PB0

PA1 PB1

PA2 PB2

PA3 PB3

PA4 PB4

PA5 PB5

PA6 PB6

PA7 PB7

M68230 LED0

LED1

LED2

LED3

LED4

LED5

LED6

LED7

+5V

R

R

R

R

R

R

R

R

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 83/112

Port Assignments

Port Address

PGCR $A00001

PACR $A0000D

PBCR $A0000FPADDR $A00005

PBDDR $A00007

PCDDR $A00009

PADR $A00011

PBDR $A00013

PCDR $A00019

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 84/112

Discussion

Both Port A & B should be initializedbefore being used.

When the switch is ON, 5 V is passed toM68230 (logic 1).

When the switch is OFF, 0 V is passed to

M68230 (logic 0).

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 85/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 86/112

Solution – Complete Program

START ORG $1000

PGCR EQU $A00001

PACR EQU $A0000D

PBCR EQU $A0000F

PADDR EQU $A00005

PBDDR EQU $A00007

PADR EQU $A00011

PADR EQU $A00013

INIT MOVE.B #$00,PGCR

MOVE.B #$80,PACR

MOVE.B #$80,PBCR

MOVE.B #$00,PADDR

MOVE.B #$FF,PBDDR

LOOP MOVE.B PADR,D0

MOVE.B D0,PBDR

BRA LOOP

END START

Sample Output

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 87/112

Sample Output

PA0 PB0

PA1 PB1

PA2 PB2

PA3 PB3

PA4 PB4

PA5 PB5

PA6 PB6

PA7 PB7

M68230 LED0

LED1

LED2

LED3

LED4

LED5

LED6

LED7

+5V

R

R

R

R

R

R

R

R

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 88/112

Example 3

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 89/112

Example 1 The M68230 is connected to thehardware shown. Write a program

that turns on all LEDs when bothswitches are closed. Else, turn off allLEDs. The port assignments are shownbelow:

Port Address

PGCR $A00001

PACR $A0000D

PBCR $A0000F

PADDR $A00005

PBDDR $A00007

PCDDR $A00009

PADR $A00011

PBDR $A00013

PCDR $A00019

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 90/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 91/112

Program

START ORG $1000

PGCR EQU $A00001

PACR EQU $A0000D

PBCR EQU $A0000F

PADDR EQU $A00005

PBDDR EQU $A00007PADR EQU $A00011

PBDR EQU $A00013

INIT MOVE.B #$00,PGCR

MOVE.B #$80,PACR

MOVE.B #$80,PBCR

MOVE.B #$00,PADDR

MOVE.B #$FF,PBDDR

MOVE.B #$00,PBDR

READSW MOVE.B PADR,D0

AND.B #$C0,D0

CMP.B #$C0,D0

BEQ ONLED

BNE OFFLED

ONLED MOVE.B #$FF,PBDR

BRA HABIS

OFFLED MOVE.B #$00,PBDR

HABIS

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 92/112

Example 4

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 93/112

Example: 7-Segment

A0

A1

A2

A3

A4

A5

A6

A7

a

b

c

d

e

f

g

M68230

Based on the circuit given,display the number “3” on the 7-segment.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 94/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 95/112

Program

PGCR EQU $800001

PADDR EQU $800005

PBDDR EQU $800007

PCDDR EQU $800009

PACR EQU $80000D

PBCR EQU $80000F

PADR EQU $800011PBDR EQU $800013

PCDR EQU $800019

MOVE.B #$00,PGCR

MOVE.B #$80,PACR

MOVE.B #$FF,PADDR

MOVE.B #$79,PADR

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 96/112

Example 5

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 97/112

Example: Displaying „C‟ on 7-Seg

B0

B1

B2

B3

B4

B5

B6

B7

a=1

b=0

c=0

d=1

e=1

f=1

g=0

M68230

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 98/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 99/112

Program

START ORG $1000

PGCR EQU $800001

PADDR EQU $800005

PBDDR EQU $800007PCDDR EQU $800009

PACR EQU $80000D

PBCR EQU $80000F

PADR EQU $800011

PBDR EQU $800013

PCDR EQU $800019

MOVE.B #$00,PGCR

MOVE.B #$80,PBCR

MOVE.B #$FF,PBDDR

MOVE.B #$B9,PBDR

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 100/112

Example 6

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 101/112

Example 6The M68230 is connected to thehardware shown. Write a programthat tests the switch at Port A. If the

switch is turned on, display 3 at the7-segment, and turn on the LEDat Port B. The port assignments areshown below:

Port Address

PGCR $800001

PACR $80000D

PBCR $80000F

PADDR $800005

PBDDR $800007

PCDDR $800009

PADR $800011

PBDR $800013

PCDR $800019

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 102/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 103/112

Program

START ORG $1000

PGCR EQU $800001

PACR EQU $80000D

PBCR EQU $80000F

PADDR EQU $800005

PBDDR EQU $800007PADR EQU $800011

PBDR EQU $800013

INIT MOVE.B #$00,PGCR

MOVE.B #$80,PACR

MOVE.B #$80,PBCR

MOVE.B #$00,PADDR

MOVE.B #$F1,PBDDR

MOVE.B #$00,PBDR

READSW MOVE.B PADR,D0

AND.B #$02,D0

CMP.B #$02,D0

BEQ ON7SEG

BNE OFF7SEG

ON7SEG MOVE.B #$31,PBDR

BRA HABIS

OFF7SEG MOVE.B #$00,PBDR

HABIS

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 104/112

Example 7

Th M68230 i t d t th

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 105/112

Example 7The M68230 is connected to thehardware shown. Write a programthat continuously tests the switches

at Port A and displays the correspondingvalue at the 7-segment. The portassignments are shown below:

Port Address

PGCR $800001

PACR $80000D

PBCR $80000F

PADDR $800005

PBDDR $800007

PCDDR $800009

PADR $800011

PBDR $800013

PCDR $800019

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 106/112

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 107/112

Program

START ORG $1000

PGCR EQU $800001

PACR EQU $80000D

PBCR EQU $80000F

PADDR EQU $800005

PBDDR EQU $800007

PADR EQU $800011PBDR EQU $800013

INIT MOVE.B #$00,PGCR

MOVE.B #$80,PACR

MOVE.B #$80,PBCR

MOVE.B #$00,PADDR

MOVE.B #$0F,PBDDR

ULANG MOVE.B PADR,D0

AND.B #$03,D0

CMP.B #$00,D0

BEQ DISP0

CMP.B #$01,D0

BEQ DISP1

CMP.B #$02,D0

BEQ DISP2

CMP.B #$03,D0

BEQ DISP3

BRA ULANG

DISP0 MOVE.B #$00,PBDR

BRA ULANG

DISP1 MOVE.B #$01,PBDR

BRA ULANGDISP2 MOVE.B #$02,PBDR

BRA ULANG

DISP3 MOVE.B #$03,PBDR

BRA ULANG

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 108/112

Example 8

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 109/112

Example

The M68230 is connectedto the circuit shown.Write a program todisplay „10‟ on the

7-segment when theswitch is activated.Else, display „55‟ when

the switch is not activated.

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 110/112

Flowchart

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 111/112

Program

START ORG $1000

PGCR EQU $800001

PACR EQU $80000D

PBCR EQU $80000F

PADDR EQU $800005

PBDDR EQU $800007PADR EQU $800011

PBDR EQU $800013

INIT MOVE.B #$00,PGCR

MOVE.B #$80,PACR

MOVE.B #$80,PBCR

MOVE.B #$00,PADDR

MOVE.B #$FF,PBDDR

READSW MOVE.B PADR,D0

AND.B #$01,D0

CMP.B #$00,D0

BEQ DISP55

CMP.B #$01,D0BEQ DISP10

BRA READSW

DISP55 MOVE.B #$55,PBDR

BRA READSW

DISP10 MOVE.B #$10,PBDR

BRA READSW

END START

7/31/2019 Rotate_ Conditional and Io

http://slidepdf.com/reader/full/rotate-conditional-and-io 112/112

The End