Introduction of Pic16f877a Microcontroller
Introduction of Pic16f877a Microcontroller
ACKNOWLEDGEMENT
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
II. TABLE ON CONTANT
NO CONTANT PAGE
1 I Acknowledgement 1
2 II Table of contant 2
7 5.0 Result 16
8 6.0 Conclusion 16
9 7.0 Referrence 16
2
1.0 INTRODUCTION
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:
3
Example of a lookup table:
TABLE1 ADDWF PCL,1 ;W+PCL --> PCL is the 1st address in TABLE
4
PIC16F877A Microcontroller
5
2.0 PIC16F877A PIN CONFIGURATION
Pin
Pin Name Description
Number
6
23 RC4/SDI/SDA 4th pin of POCTC or Serial Data in pin
7
2.1 PIC16F877A FEATURES
Number of Pins 40
Comparators 2
8
2.2 LIST OF COMPONENTS
COMPONENTS UNITS
PIC16F877A
PUSH BUTTON
9
3.0 CIRCUIT EXPLANATION
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.
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’.
10
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.
4.0 SIMULATION
11
12
4.1 PROGRAM
13
14
5.0 RESULTS
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.
6.0 CONCLUSION
15
7.0 REFFERENCE
1) https://whatis.techtarget.com/definition/PIC-microcontrollers
2)https://medium.com/@nicholashadinh/smart-lamp-a-digital-system-and-
microprocessor-project-b5816adfc584
3) LAB 7
16