You are on page 1of 13

A Report

On
A Microprocessor Based
Black and White image scanner

Hardware Design and ALP

Done In Partial Fulfillment of the Course


Microprocessor Programming and Interfacing

Done By
Batch No. 40

U.BHAVANI SHANKER 2004A3PS727


THRIVIKRAMAN P.S. 2004A7A3113
RAMYA KRISHNA KOLLA 2004A7PS060
RAHUL KUMAR LAKHMANI 2004A7PS005

Birla Institute of Technology and Science


Pilani ,Rajasthan-333031
20 April, 2006
Question:

P19

Design a microprocessor based scanner which will scan a black and white
image and store it as binary data. The scanner has two stepper motors for
motion along two orthogonal coordinates. The rotational motion is converted
into translational motion through a lead screw mechanism. Five paired LED
photodiodes intended for B&W image scanning are placed one centimeter
apart. The maximum size scannable is 10cmX10cm.The photodiode signal is
analog signal which is amplified and available to you as 5V signal for white
image and 0V for black image. The analog signal is to be digitized and
stored sequentially in the RAM. The motor moves given direction signal and
a pulse. (0 for clockwise and 1 for anticlockwise).

SYSTEM DESCRIPTION:

The Microprocessor based Black and White image scanner consists of the
INTEL 8086 MPU as central processing unit. Two Intel 8255 Programmable
Peripheral Interfacing device are used to interface two stepper motors and a
0809 Analog-To-Digital Converter. The 5 paired photodiodes are interfaced
to the system through the ADC. Two 2716 ROMS are used to store the
program .Two 6116 RAMS are interfaced to the processor. Three 74LS373
octal latches are used to demultiplex the AD lines coming from the
processor. Two 74LS245 bi-directional buffers are also used to demultiplex
the AD lines coming from the processor. One more 74LS245 is used for the
RD’, WR’ and M/IO’ signal lines.
Hardware Description:

Device Numbers Purpose

Intel 8086 1 Microprocessor


Intel 8255A 2 Peripheral interfacing device
74LS373 3 Octal latches for address lines, BHE’
74LS245 3 Bidirectional buffer for data lines, RD’,WR’,M/IO’
2716 ROM(2K) 2 To store the code
6116 SRAM(2K) 2 To store the image
0809 ADC 1 Analog to digital converter, selects input diode
Stepper motors 2 X and Y directional movement of photodiodes

MEMORY ADDRESSES:

ROM: FF000H-FFFFFH
RAM: 00000H-00FFFH

NAME OF THE ADDRESS TO PURPOSE OF PORT


PORT IN 8255A(1) ACCESS THE
PORT
Port A 80H Stepper Motor 1 – Output port
Port B 82H Stepper Motor 2 – Output port
Port C 84H Lower – ADC select line signals Output po
Upper – not used Initialized as Output por
Control Register 86H To initialize 8255 ports

NAME OF THE ADDRESS TO PURPOSE OF PORT


PORT IN 8255A(2) ACCESS THE
PORT
Port A 88H To ADC – Input port
Port B 8AH Not used – Initialized as Output port
Port C 8CH Lower – PC0 to EOC – Input port
Upper – PC7 – ALE – Output
PC6 - Start - Output
PC5 – OE - Output
Control Register 8EH To initialize 8255 ports

Assumptions:

1. There is no power failure in between or the system operates on a UPS in


case of a power failure.

2. The 8086 Chip is already programmed with the specified code from an
external source.

3. There is a jump instruction at the address that the processor generates to


the place where our code is stored (i.e. to FF000H).

4. For one full rotation, the stepper motor covers 0.5 cm

5. The transmitter in the paired LED’s is on all the time.

6. The pixels to be read from the paper are 0.125 cm apart. Therefore there
are 8 gaps each of 0.125 cm in one centimeter. Therefore there are 81 points
to be read in each row and 81 points to be moved along each column.

7. Size of the image is 10x10cm always.


8. From the photodiode, we get 0 V or +5 V and no intermediate value.

9. The stepper motor requires a software delay of 1 millisecond while it


rotates into position.

10. The starting position is from the top-left corner of the page. Motion of
the photodiodes would be from left to right and top to bottom of a page in
the read operation.

Algorithm:

1. The 10x10cm image is divided into pixels of size 0.125 cm each.


2.
LED1 LED2

1 cm

Memory Block

Each centimeter is divided into 8 parts so that each part takes up one bit of a
byte, the entire byte itself representing one centimeter. In this way, bit 7
would be the starting position and bit 0 would be the last position within a
centimeter. Therefore, on the first read operation, the first 5 centimeters in a
row are read and 5 bytes would be occupied.

3. The memory has already been initialized as 0’s. If a diode is read as 5V,
then 1 would be written into the corresponding bit else no operation as
already initialization as 0’s.

4. After the first read, the photodiodes have to be moved by 4.125 cm to read
the second half of the row. Therefore the next 5 bytes would be placed in
memory, the last point being unread.
5. This point is read separately by choosing only the required photodiode
and this bit is stored separately in the next byte.

6. In this way, one row consisting of 81 points would occupy 10+1 bytes

7. The entire photodiode system is moved back to the start at the left and
then vertically downwards by 0.125cm and then the read operation
commences as from step 2.

8. The entire page therefore comprises of 81 columns and 81 rows. Each row
taking 11 bytes would imply that the entire page would take 11x81 = 891
bytes of memory for storing the image read.

ALP:

;CODE begins at FFF00H


;So a JMP INSTRUCTION is written at FFFF0H
;which redirects the flow of execution
.model tiny
.data

SMOTOR1 EQU 80H


SMOTOR2 EQU 82H
MUX_ADC EQU 84H
ADC EQU 88H
SIGNAL_ADC EQU 8CH

IM_BUFFER DB 891 DUP(0)


POS1 DB 33H ;position of stepper motor 1
POS2 DB 33H ;position of stepper motor 2

.code
.startup

MOV AX,0000H ; initialize DS


MOV DS,AX

MOV AL,80H ;control word to initialize 8255A(1)


OUT 86H,AL

MOV AL,91H ;control word to initialize 8255A(2)


OUT 8EH,AL

MOV CX,81 ; row movement counter


MOV SI,OFFSET IM_BUFFER ; image storage area

NEXTROW: PUSH CX
MOV DL,0
MOV CX,8
READAGAIN1: CALL READPIX
MOV AL,POS1
ROR AL,1 ; rotates motor through one step
OUT SMOTOR1,AL
CALL DELAY_MOT
MOV POS1,AL
INC DL
LOOP READAGAIN1

;first half of row has been read.


;Whole assembly is to be moved by 4.125 cm

MOV CX,33
MOV AL,POS1

AGAIN1: ROR AL,1


OUT SMOTOR1,AL
CALL DELAY_MOT
LOOP AGAIN1

MOV POS1,AL

;now the next half of the row has to be read

ADD SI,5
MOV DL,0
MOV CX,8

READAGAIN2: CALL READPIX


MOV AL,POS1
ROR AL,1
OUT SMOTOR1,AL
CALL DELAY_MOT
MOV POS1,AL
INC DL
LOOP READAGAIN2
;both halves of the row have been read.
;Only the last pixel is to be read
;reading the last pixel

MOV AL,POS1
ROR AL,1
OUT SMOTOR1,AL
CALL DELAY_MOT
MOV POS1,AL

MOV AL,80H ;enable ALE(ALE = 1)


OUT SIGNAL_ADC,AL

MOV AL,05H ;enable the last photodiode


OUT MUX_ADC,AL

MOV AL,40H ;start pulse


OUT SIGNAL_ADC,AL

MOV CX,1

;provide a delay of 2 microsecs to the start signal

NOP
NOP
NOP
NOP
X1: LOOP X1

MOV AL,0
OUT SIGNAL_ADC,AL
NOTOVER: IN AL,SIGNAL_ADC
AND AL,1 ;checking EOC
JZ NOTOVER

;conversion over

MOV AL,20H ;output enable = 1


OUT SIGNAL_ADC,AL
IN AL,ADC ;AL contains output of ADC now

CMP AL,00H
JZ SKIP
OR [SI+5],80H

SKIP: MOV CX,48


MOV AL,POS1

AGAIN2: ROL AL,1


OUT SMOTOR1,AL

;move motor1 back to start

CALL DELAY_MOT
LOOP AGAIN2

MOV POS1,AL
MOV AL,POS2
ROR AL,1
OUT SMOTOR2,AL

;move motor2 vertically

CALL DELAY_MOT
MOV POS2,AL
ADD SI,6
POP CX
LOOP NEXTROW

.exit

READPIX PROC NEAR


;takes SI and DL as arguments

PUSH CX
MOV BX,0
;BX holds the diode being selected currently through MUX

MOV CX,5

NEXTBYTE: MOV AL,80H ; enable ALE


OUT SIGNAL_ADC,AL

MOV AL,BL ;select diode using BX


OUT MUX_ADC,AL

MOV AL,40H
OUT SIGNAL_ADC,AL ;start pulse

MOV CX,1 ; delay of 2 microsecs


NOP
NOP
NOP
NOP
X1: LOOP X1

MOV AL,0
OUT SIGNAL_ADC,AL ;make pulse 0

GOBACK: IN AL,SIGNAL_ADC
AND AL,1 ; check EOC
JZ GOBACK

;conversion over

MOV AL,20H
OUT SIGNAL_ADC,AL ;OE = 1
IN AL,ADC ;AL contains ADC output now

CMP AL,00H
JZ FORWARD
MOV AL,80H
PUSH CX
MOV CL,DL
SHR AL,CL
POP CX
OR [BX+SI],AL ;stores in memory

FORWARD: INC BX
LOOP NEXTBYTE
POP CX
RET

READPIX ENDP

DELAY_MOT PROC NEAR


;procedure to provide 1 ms delay for movement of motor

PUSH CX
MOV CX,501

X2: NOP
LOOP X2
POP CX
RET

DELAY_MOT ENDP

end

You might also like