ECET209 Microprocessor systems and interfacing

MohamedDakheel3 6 views 28 slides Sep 15, 2025
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

Interfacing of Microprocessor systems


Slide Content

ECET 209MICROPROCESSOR SYSTEMS AND
INTERFACING
© Copyright Statement:
This ACM document and its content is copyright of the American College Of The Middle East –
© Copyright 2023, All Rights Reserved - American College of the Middle East (ACM), Egaila, Kuwait.
Any redistribution or reproduction of part or all the content in any form without the prior written approval from the copyright holder is prohibited.

CLASS 5
ASSEMBLY LANGUAGE
▪READ INPUTs (Review examples)
▪7-segment display
Copyright © American College of the
Middle East. 2025

Example 1
BSF STATUS,5 ; switching from bank0 to bank1
MOVLW 0xFF ;uploading all 1s to W (working register)
MOVWF TRISA; uploading value from W to TRISA in order
; to make PORTA as input
CLRF TRISB; uploading all 0s to TRISB in order to make
; PORTB as output
BCF STATUS,5; switching from bank1 to bank0
MAIN; label (can have any name)
BTFSC PORTA,1; checking if button connected to RA1 is pressed
GOTO LEDON; this line in not skipped in case button is pressed
GOTO LEDOF; in case button is not pressed we are coming here

LEDON ; label (can have any name)
MOVLW 0XFF; uploading all 1s to W
MOVWF PORTB; uploading all 1s from W to
; PORTB to turn on all LEDs
GOTO MAIN; jump to MAIN LABEL

LEDOF; label (can have any name)
CLRF PORTB; uploading all 0s to PORTB to turn
; off all LEDs
GOTO MAIN; jump to MAIN LABEL
END; END of the program (not necessary)
Copyright © American College of the
Middle East. 2023
Button is connected to bit1 PORTA (PA1)
When button is pressed → All LEDs of PORTB are ON
When button is not pressed → All LEDs of PORTB are OFF

Copyright © American College of the
Middle East. 2023

Write an Assembly Code to check the status of button connected to PA2 and if set to
turn on the LEDs connected to PB4, PB5, PB6 and PB7 of PIC16F877A:
If button PA2 is pressed, LEDs PB4, PB5, PB6 and PB7 are turned on
If button PA2 is not pressed, LEDs PB4, PB5, PB6 and PB7 are turned off
Copyright © American College of the
Middle East. 2022.
Example 2

Copyright © American College of the
Middle East. 2022.
Example 2
SOLUTION:
ORG 0x00 ;starting address in flash memory
BSF STATUS,5 ;go to bank1 from bank0 –set a bit5 of STATUS register
BSF TRISA,2 ;making bit2 of PORTA as input –clear a bit2 of TRISA reg
CLRF TRISB ;making all PORTB bits (pins) as outputs –clear all bits of TRISB reg
BCF STATUS, 5 ;go to bank0 from bank1 –clear a bit5 of STATUS register
MAIN ;label called MAIN
BTFSC PORTA,2 ;if bit2 of PORTA is pressed, the next line is not skipped and if not pressed –skip next line
GOTO LEDON ;jump to label called LEDON
GOTO LEDOFF ;jump to label called LEDOFF

LEDON ;label called LEDON
MOVLW B’11110000';uploading 11110000 or 0xF0 to working reg
MOVWF PORTB ;sending value from working reg to PORTB to turn on specific LEDs
GOTO MAIN ;jump to label called MAIN once LEDON routine is finished

LEDOFF ;label called LEDOFF
CLRF PORTB ;turning off all LEDs of PORTB –clear all bits of PORTB reg
GOTO MAIN ;jump to label called MAIN once LEDOFF routine is finished
END

Copyright © American College of the
Middle East. 2022.
Example 2
Result:
LEDON routine (PA2 button is pressed) LEDOFF routine (PA2 button is not pressed)

Write an Assembly Code to check the status of buttons connected to PA0, PA1:
If button PA0 is pressed, LEDs PB4, PB5, PB6 and PB7 are turned on
If button PA1 is pressed, LEDs PB0, PB1, PB2 and PB3 are turned on
If button PA0 and PA1 are not pressed, all LEDs of PORTB are turned off
Copyright © American College of the
Middle East. 2022.
Example 3

Example 3
BSF STATUS,5
BSF TRISA, 0
BSF TRISA, 1
CLRF TRISB
BCF STATUS,5
MAIN
BTFSC PORTA,0
GOTO LED1
BTFSC PORTA,1
GOTO LED2
GOTO ALL_OFF

LED1
MOVLW 0xF0
MOVWF PORTB
GOTO MAIN
LED2
MOVLW 0x0F
MOVWF PORTB
GOTO MAIN
ALL_OFF
CLRF PORTB
GOTO MAIN
Copyright © American College of the
Middle East. 2023
SOLUTION:

Copyright © American College of the
Middle East. 2023
Example 3
PA0 button is pressed
PA1 button is pressed
PA0 and PA1 buttons are not pressed

7-SEGMENT DISPLAY
Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY
COMMON CATHODE
Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY
Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY
Decimal DP g f e d c b a Hex
0 0 0 1 1 1 1 1 1 3F
1 0 0 0 0 0 1 1 0 06
2 0 1 0 1 1 0 1 1 5B
3 0 1 0 0 1 1 1 1 4F
4 0 1 1 0 0 1 1 0 66
5 0 1 1 0 1 1 0 1 6D
6 0 1 1 1 1 1 0 1 7D
7 0 0 0 0 0 1 1 1 07
8 0 1 1 1 1 1 1 1 7F
9 0 1 1 0 0 1 1 1 67
Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY ON
EASY PIC
PORTA
Copyright © American College of the
Middle East. 2022.

ORG 0x00
BSF STATUS, 5
CLRF TRISA
CLRF TRISD
MAIN
BCF STATUS, 5
MOVLW 0x0F
MOVWF PORTA
MOVLW 0x3F
MOVWF PORTD
END
Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY ON
PICSIMLAB
PORTA
Copyright © American College of the
Middle East. 2022.
DISP4DISP3 DISP2 DISP1

Copyright © American College of the
Middle East. 2020.
7 segment display (1)
Segments:
-PORTA controls DISP1, DISP2,
DISP3, DISP4
-PORTD controls segments
a,b,c,d,e,f,DP
e.g. PORTD=B’DP,g,f,e,d,c,b,a’
In EasyPIC for built-in display:

Copyright © American College of the
Middle East. 2020.
Examples for EasyPIC built-in display:
-PORTA=B’00001111’; or 0x0F
-PORTD=B ’11111111’; or 0xFF
-PORTA=B’00001001’; or 0x09
-PORTD=B ’10000110’; or 0x86
-PORTA=B’00001100’; or 0x0C
-PORTD=B ’01001111’; or 0x4F
7 segment display (2)

ORG 0x00
BSF STATUS, 5
CLRF TRISA
CLRF TRISD
MAIN
BCF STATUS, 5
MOVLW 0x0F
MOVWF PORTA
MOVLW 0x3F
MOVWF PORTD
END
Copyright © American College of the
Middle East. 2022.
ON EASYBOARD

7-SEGMENT DISPLAY
SHOW NUMBER “5”
IN THE FIRST TWO 7-SEG DISPLAYS
1Copyright © American College of the
Middle East. 2022.

ORG 0x00
BSF STATUS, 5
CLRF TRISA
CLRF TRISD
MAIN
BCF STATUS, 5
MOVLW 0x03
MOVWF PORTA
MOVLW 0x6D
MOVWF PORTD
END
ON EASYBOARD
Copyright © American College of the
Middle East. 2022.

ORG 0x00
BSF STATUS, 5
CLRF TRISA
CLRF TRISD
MAIN
BCF STATUS, 5
MOVLW 0x30
MOVWF PORTA
MOVLW 0x6D
MOVWF PORTD
END
ON PICSIMLAB
Copyright © American College of the
Middle East. 2022.
DISP4DISP3DISP2DISP1

Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY
SHOW NUMBER “3”
IN THE FIRST THREE 7-SEG DISPLAYS
Copyright © American College of the
Middle East. 2022.

7-SEGMENT DISPLAY
SHOW CHARACTER “S”
IN THE FIRST AND SECOND 7-SEG DISPLAY
Copyright © American College of the
Middle East. 2025.

7-SEGMENT DISPLAY
SHOW CHARACTER “h”
IN THE FOURTH AND SECOND 7-SEG DISPLAY
Copyright © American College of the
Middle East. 2025.

Instructions:
BSF –Set a bit to 1
BCF –Clear a bit to 0
CLRF –Clear all bits to 0
MOVLW –Move number to a working register
MOVWF –Move from a working register to
another register
ADDLW –Add number to a value in working
register
SUBLW –Subtract a value in working register
from the number written after instruction
BTFSC –Skips the next line in case logic is 0
BTFSS –Skips the next line in case logic is 1
GOTO –Helps to jump anywhere in the code
Registers:
PORTB –port B pins
PORTA –port A pins
TRISA –choosing the pins as input/output (1-
input, 0-output)
TRISB –
STATUS –5
th
bit is used to switch between the
banks
Copyright © American College of the
Middle East. 2025