Anda di halaman 1dari 16



First and foremost, we are very grateful to the almighty ALLAH S.W.T for letting us to
finish our project in subject Microprocessor & Microcontroller and give me strength
that we need in order to fulfill our duty as an Technology Electronic student.
Here, we wish to express our sincere appreciation to our lecturer, Sir Mohd Hakimi bin
Mohd Zohari for encouragement, guidance, suggestions, critics and friendship
throughout finishing this project.
Thanks also to all of the kind lecturers in Bachelor of Electronic Technology Section
for their accommodation, suggestion and opinion during the project progress in
university. In particular, we would like to thank all the staff and technicians, for their
cooperation, indirect or directly contribution upon completing our project.
Most importantly, special thanks also to our family for their external support when we
told them that we wanted to continue our education . Other than that, big thanks to
especially our friends for encouraging us to finish this project. Without their support the
ideas could not have been realized



1 I Acknowledgement 1

2 II Table of contant 2

3 1.0 Introduction 3-5

2.0 Pic16f877a pin configuration 6-7

4 2.1 Pin Feature 8

2.2 Component List 9

5 3.0 Circuit Explaination 10-11

6 4.0 Simulation 11-13

4.1 Program 13-15

7 5.0 Result 16

8 6.0 Conclusion 16

9 7.0 Referrence 16


Smart Lamp is a digital system project to simulate a better lamp operation using
microprocessor. It is an LED-based design with automatic switch function which is
controlled by switch. This lamp will turn on automatically when time indicates night
to bright up your room.

In addition, Smart Lamp will also turn on automatically during morning or daytime if
the room where it is located has little light intensity and there’s someone in the room.
On the other hand, Smart Lamp will turn off when it’s morning or daytime and there’s
no one in the room.

Program data table (lookup table) allows an access to elements of a frequently used
table with minimum operations. Lookup tables are an inherent PIC capability made
possible by the instruction ‘retlw’ (return with literal value in W). A table consists of
a way to select from a list of ‘retlw’. In PIC, to get the table element, programmer
needs to:

 Call the lookup table

 Add a fixed value to the Program Counter (PCL)
 Upon returning from the table, the ‘retlw’ instruction will provide the desired
lookup table element in the Working Register (W)

Example of a lookup table:

TABLE1 ADDWF PCL,1 ;W+PCL --> PCL is the 1st address in TABLE

RETLW 0x01 ;Return to main program with literal value 01h

in W

RETLW 0x02 ;Return to main program with literal value 02h

in W

RETLW 0x03 ;Return to main program with literal value 03h

in W

RETLW 0x04 ;Return to main program with literal value 04h

in W

The PIC microcontroller PIC16F877A is one of the most renowned microcontrollers in

the industry. This controller is very convenient to use, the coding or programming of
this controller is also easier. One of the main advantages is that it can be write-erase as
many times as possible because it use Flash memory technology. It has a total number
of 40 pins and there are 33 pins for input and output. PIC16F877A is used in many pic
microcontroller projects. PIC16F877A also have many application in digital electronics

PIC16F877A Microcontroller

PIC16F877A Pin Diagram


Pin Name Description

MCLR is used during programming,

1 MCLR/Vpp mostly connected to programmer like
2 RA0/AN0 Analog pin 0 or 0th pin of PORTA

3 RA1/AN1 Analog pin 1 or 1st pin of PORTA

4 RA2/AN2/Vref- Analog pin 2 or 2nd pin of PORTA

5 RA3/AN3/Vref+ Analog pin 3 or 3rd pin of PORTA

6 RA4/T0CKI/C1out 4th pin of PORTA

7 RA5/AN4/SS/C2out Analog pin 4 or 5th pin of PORTA

8 RE0/RD/AN5 Analog pin 5 or 0th pin of PORTE

9 RE1/WR/AN6 Analog pin 6 or 1st pin of PORTE

10 RE2/CS/AN7 7th pin of PORTE

11 Vdd Ground pin of MCU

12 Vss Positive pin of MCU (+5V)

13 OSC1/CLKI External Oscillator/clock input pin

14 OSC2/CLKO External Oscillator/clock output pin

15 RC0/T1OSO/T1CKI 0th pin of PORT C

16 RC1/T1OSI/CCP2 1st pin of POCTC or Timer/PWM pin

17 RC2/CCP1 2nd pin of POCTC or Timer/PWM pin

18 RC3/SCK/SCL 3rd pin of POCTC

19 RD0/PSP0 0th pin of POCTD

20 RD1/PSPI 1st pin of POCTD

21 RD2/PSP2 2nd pin of POCTD

22 RD3/PSP3 3rd pin of POCTD

23 RC4/SDI/SDA 4th pin of POCTC or Serial Data in pin

24 RC5/SDO 5th pin of POCTC or Serial Data Out pin

6th pin of POCTC or Transmitter pin of

25 RC6/Tx/CK

7th pin of POCTC or Receiver pin of

26 RC7/Rx/DT

27 RD4/PSP4 4th pin of POCTD

28 RD5/PSP5 5th pin of POCTD

29 RD6/PSP6 6th pin of POCTD

30 RD7/PSP7 7th pin of POCTD

31 Vss Positive pin of MCU (+5V)

32 Vdd Ground pin of MCU

33 RB0/INT 0th pin of POCTB or External Interrupt pin

34 RB1 1st pin of POCTB

35 RB2 2nd pin of POCTB

3rd pin of POCTB or connected to

36 RB3/PGM
37 RB4 4th pin of POCTB

38 RB5 5th pin of POCTB

6th pin of POCTB or connected to
39 RB6/PGC
7th pin of POCTB or connected to
40 RB7/PGD


PIC16F877A –Simplified Features

CPU 8-bit PIC

Number of Pins 40

Operating Voltage (V) 2 to 5.5 V

Number of I/O pins 33

ADC Module 8ch, 10-bit

Timer Module 8-bit(2), 16-bit(1)

Comparators 2

Communication Peripherals UART(1), SPI(1), I2C(1), MSSP(SPI/I2C)

External Oscillator Up to 20Mhz

Internal Oscillator Nil

Program Memory Type Flash

Program Memory (KB) 14KB


RAM Bytes 368

Data EEPROM 256 bytes





LED (Multiple Colours)



The circuit will start off with the LEDs light up in a sequential manner without the push
button. The word TRIS is used to define if the pin is being used as output or input while
the word PORT is used to make the pins HIGH or LOW. Push button and power source
is connected to pin no. 1 as it is an input pin while all the LEDs are connected to PORTB
as output pins. The other end of the push button is connected to GROUND as it will act
as a weak pull up resistor as when it is pushed, low current will flow through the circuit,
making the LEDs not light up when the button is pushed down.

TABLE ADDWF PCL,1 ;W+PCL --> PCL is the 1st

address in TABLE

RETLW B'00000001' ;to turn on D1

RETLW B'00000010' ;to turn on D2

RETLW B'00000100' ;to turn on D3

RETLW B'00001000' ;to turn on D4

RETLW B'00010000' ;to turn on D5

RETLW B'00100000' ;to turn on D6

RETLW B'01000000' ;to turn on D7

RETLW B'10000000' ;to turn on D8

The coding above is saved inside the PIC. It shows when the LED supposed to light up.
D1 lights up with code B’00000001’; D2 lights up with code B’00000010’; D3 lights
up with code B’00000100’; D4 lights up with code B’00001000’; D5 lights up with
code B’00010000’; D6 lights up with code B’00100000’; D7 lights up with code
B’01000000’ and D8 lights up with code B’10000000’.

The main program starts with ‘BANKSEL TRISB’ which we saved the table above
earlier so it will now read the table and execute it. ‘MOVLW’ copies the value of
B’00000000’ into the W register then ‘MOVWF’ copies the working content to TRISB
as in PORTB as outputs. Set point is 0 and MOVLW D’8’ is set to W-8 ; depending on
the number of line in the table.

Then it subtracts the value of W from register ‘F’ using 2’s complement method. If the
value is 0, the result is saved in W register otherwise ‘1’ is stored back in default register.
The content is then moved to a destination dependent upon the value of D8 and it will
be used in TABLE. MOVWF is where data is moved from W earlier to register ‘f’, as it
moves the return value from TABLE to PORT B. it will delay some time for the LED to
light up. INCF is where it will increase the value of POINT in register ‘f’. GOTO
NEXT_ON makes it loopback to the start with the next value. After all of the table has
been used up, it will keep on looping until power course is cut off.




From the simulation, when we push the button, all of the LED will light up continuously
and sequentially start from first led till the last led depends on the timer that have been
set in the program. The program in the PIC16F877A was generated from HEX file
which have been build by MPLAB software. All of the LED was set as PORTB which
are output in the program.

When the button was push, the program will address to LED bank starting from first
bank which have been set in binary form (00000001) for LED1 and move to the next
led which is set as (00000010) for LED2, (00000100) for LED3, (00001000) for LED4,
(00010000) for LED5, (00100000) for LED6, (01000000) for LED7, and the last bank
is (10000000) for LED8. And then, it will loop back to the NEXT_ON which is return
back to LED1, move to the next LED and it will continuously blink until the simulation
or the push button stop.


As a conclusion, we as a team able to get a result by simulate our circuit by using

Proteus8. We also run it with create our own program which is for lighting led with push
button. We also can apply it with briefly and do the this project with successful. In our
project we use program data table (lookup table) allows an access to elements of a
frequently used table with minimum operations. We hope one day people can apply this
project in their life and can provide it to being a better project Other than that we as a
team able to understand the flow of the program and build using Mplab we able to
expertise the coding for the program and build a version that we expected.




3) LAB 7