0% found this document useful (0 votes)
168 views5 pages

Application 1 - Running Led: Experiment 4

This document describes an experiment involving using a PIC microcontroller to run LEDs. It includes objectives to configure I/O ports, use subroutines, write and test a program. Equipment includes a PC, starter kit, programmer, power supply and LEDs. It provides theory on instruction cycles and timing. The procedure describes creating a project, entering code, assembling, downloading to the PIC, connecting a circuit and recording results. Questions involve drawing a flowchart and discussing the experiment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views5 pages

Application 1 - Running Led: Experiment 4

This document describes an experiment involving using a PIC microcontroller to run LEDs. It includes objectives to configure I/O ports, use subroutines, write and test a program. Equipment includes a PC, starter kit, programmer, power supply and LEDs. It provides theory on instruction cycles and timing. The procedure describes creating a project, entering code, assembling, downloading to the PIC, connecting a circuit and recording results. Questions involve drawing a flowchart and discussing the experiment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

E4160 SISTEM MIKROPEMPROSES & PENGAWAL MIKRO

EXPERIMENT 4:

APPLICATION 1 – RUNNING LED


A. OBJECTIVES
At the end of the practical session, student should be able to :

1. Configure I/O ports according to the circuit diagram.


2. Use subroutine in writing program.
3. Write and simulate the program according to the problem given.
4. Download and test the program on the hardware

B. EQUIPMENTS REQUIRED

1. PC installed MPLAB Software


2. Starter kit SK40C
3. ICSP Programmer
4. Power supply
5. LED and resistor

C. THEORY

The derives its timing from a 4-phase clock (clock cycle). Each word of instruction needs 4 clock cycle to
be executed. Time needed to complete an instruction during execution can be calculate using the formula
given below:

Time = Total instruction cycle x Clock cycle


Clock frequency

Total instruction cycle = the number of instruction cycles


executed by CPU.
Clock cycle = 4
Clock frequency = 20 MHz

1 JKE/POLISAS/E4160-exp. 4/JUN2011
E4160 SISTEM MIKROPEMPROSES & PENGAWAL MIKRO

NO D. PROCEDURE

Creating Project File

1 Create a New Project File with following setting:

Device: PIC16F877A
Active Toolsuite: Microchip MPASM Toolsuite
Project Name Lab4
Project Directory <your own choice>

2 Open a new file by clicking File> New, and start to enter into it Program Example 4.1. After a few lines
save as this program as ProgramLab4.asm

3 Continue entering the code. When complete, go to the Project menu again, click Add Files to Project...
and select the one you have just saved.

4 Assembler the program by pressing Project>Build All.


(If the error occurs, fix it and repeat step 4 again.)

5 Download ProgramLab4.hex file into PIC (SK40C). After finish downloading turn off SK40C.

6 Connect the circuit as Figure 4.1 on SK40C.

7 Turn on SK40C and record the result into Table 4.1.

NO E. RESULT
1
(ON = 1, OFF = 0)

LED
RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
Output
state
1
2
3
4
5
6
7
8

Table 4.1

(8 marks)

2 JKE/POLISAS/E4160-exp. 4/JUN2011
E4160 SISTEM MIKROPEMPROSES & PENGAWAL MIKRO

NO F. QUESTION

1. Draw the flowchart and for time delay subroutine of Program Example 4.1

(11 marks)

NO G. DISCUSSION

1.

(6 marks)
NO H. CONCLUSION

1.

(5 marks)

3 JKE/POLISAS/E4160-exp. 4/JUN2011
E4160 SISTEM MIKROPEMPROSES & PENGAWAL MIKRO

APPENDIX

Figure 4.1 : Circuit diagram

START

D1=0X20
D2=0X21
D3=0X22

PORTB=OUTPUT

CLEAR PORTB
(ALL LED OFF)

PORTB = ‘00000001’
(LED1 ON)

DELAY

RLF PORTB
(LED2 ON,LED1 OFF)

DELAY

RLF PORTB
(LED8 ON,LED1,2,3,4,5,6,7 OFF)

DELAY

Figure 4.2 : Flowchart

4 JKE/POLISAS/E4160-exp. 4/JUN2011
E4160 SISTEM MIKROPEMPROSES & PENGAWAL MIKRO

Program Example 4.1

;--------------------------Runlight1 ----------------------------
PROCESSOR 16F877A
#INCLUDE <P16F877A.INC>
__CONFIG 0X3F32

;***************** VARIABLE DEFINITIONS************************

D1 EQU 0X20 ;FOR DELAY


D2 EQU 0X21 ;FOR DELAY
D3 EQU 0X22 ;FOR DELAY

;Initialize I/O -------------------------------------


ORG 0X00 ;Program Start Here
BANKSEL TRISB ;Select Bank 1
MOVLW B'00000000'
MOVWF TRISB ;Select all PortB as output
BANKSEL PORTB ;Select Bank 0
CLRF PORTB ;Clear data on PORTB
GOTO START ;Goto label START

;Subroutine -----------------------------------------

DELAY MOVLW D'255'


MOVWF D3
MOVLW D'249'
MOVWF D2
MOVLW D'25'
MOVWF D1
DECFSZ D1
GOTO $-1
DECFSZ D2
GOTO $-5
DECFSZ D3
GOTO $-9
RETURN

;Main Program ---------------------------------------


START MOVLW B'00000001' ;Load data 0000001 into w
MOVWF PORTB ;Move data into PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
RLF PORTB ;Rotate left PortB
CALL DELAY ;Delay 1 s
GOTO START

END ; End Program here!!

5 JKE/POLISAS/E4160-exp. 4/JUN2011

You might also like