Micro Controller
Micro Controller
INTRODUCTION TO MICROCONTROLLERS
NEHA KARDAM
OpenWA
Olympia, WA
Introduction to Microcontrollers Copyright © 2024 by Lake Washington Institute of Technology is licensed under a Creative Commons
Attribution 4.0 International License, except where otherwise noted.
CONTENTS
Acknowledgments 1
Licenses and permissions 2
About this pressbook iii
About the course : Introduction to Microcontroller iv
Appendix 121
ACKNOWLEDGMENTS | 1
ACKNOWLEDGMENTS
The Lake Washington Institute of Technology is grateful for the critical support of the National Science
Foundation (NSF) Grant #2100136. This grant has been instrumental in propelling our research and
development efforts in engineering through the creation of Open Educational Resources (OER) course
materials.
I would also like to extend my sincere gratitude to Katherine Kelley and Priyanka Pant. Their expertise and
dedication were invaluable in this project. Their encouragement played a key role in motivating me to develop
these OER materials and the accompanying pressbook.
2 | LICENSES AND PERMISSIONS
This pressbook on “Introduction to Microcontroller” is licensed under a Creative Commons Attribution 4.0
International License ([Link] This license allows you to freely
access and use the information presented here, with some key requirements:
• Attribution (BY): You must give credit to the author, Neha Kardam, whenever you use any part of this
pressbook.
• No Derivatives (ND): You cannot modify or alter the content of the pressbook in any way.
• Non-Commercial (NC): You cannot use this pressbook for any commercial purposes that primarily
aim to generate profit. However, you are free to print copies for educational or personal use.
This publication, “Introduction to Microcontroller,” was developed in Summer 2024 and was created as
part of the National Science Foundation Advanced Technological Education grant titled, Creation and
Modernization of Technological Education in Electronics and Welding through Open Educational Resources
that are Free to Share, Use, and Revise (NSF ATE #2100136), awarded to Lake Washington Institute of
Technology in 2021. In this three-year grant, three Electronics Technology courses were updated to accessible
OER materials with hybrid delivery elements where possible. Faculty Librarian Katherine Kelley, and Dean of
Instruction Priyanka Pant led the project. Electronics materials were authored by Electronics Professor, Neha
Kardam.
This material is based upon work supported by the National Science Foundation under Grant No.
2100136. Any opinions, findings, and conclusions or recommendations expressed in this material are those of
the author(s) and do not necessarily reflect the views of the National Science Foundation.
4 | ABOUT THE COURSE : INTRODUCTION TO MICROCONTROLLER
Course Highlights:
1. Comprehensive introduction to microcontrollers and microprocessors
2. In-depth study of assembly language programming
3. Hands-on experience with PIC16F18875 and PIC16(L)F18855/75 microcontrollers
4. Practical lab assignments covering various aspects of microcontroller programming
5. Focus on both theoretical concepts and practical applications
6. Introduction to advanced features like ADC2 module and its configuration
7. Real-world project implementations including home security systems and temperature indicators
Course Structure
I. Introduction to Microcontrollers
• Fundamentals of Microprocessors and Microcontrollers: Learn the basic functions and architecture
of microprocessors and microcontrollers.
• Microprocessor Architecture: Understand the internal architecture and operation of
microprocessors.
• Introduction to Microcontroller Systems: Explore the components and functionalities of
microcontroller systems.
• Getting Started with Microcontroller Programming: Begin programming microcontrollers with
practical examples and exercises.
ABOUT THE COURSE : INTRODUCTION TO MICROCONTROLLER | 5
This course is ideal for students pursuing careers in embedded systems, electronics engineering, or any field
involving microcontroller-based design. By the end of the course, students will have the skills to program
microcontrollers, understand their internal architecture, and implement them in various applications.
Investing in Your Future Success
By choosing LWTech’s “Introduction to Microcontrollers” course, you’ll gain valuable skills such as:
PART I
INTRODUCTION TO
MICROCONTROLLERS
In this chapter, we will explore the foundational concepts of microprocessors and microcontrollers.
Understanding their basic functions is crucial for grasping more advanced topics in microcontroller
programming and applications. Microprocessors and microcontrollers are integral to modern computing,
embedded systems, and a wide range of electronic devices.
8 | INTRODUCTION TO MICROCONTROLLERS
FUNDAMENTALS OF MICROPROCESSORS AND MICROCONTROLLERS | 9
FUNDAMENTALS OF MICROPROCESSORS
AND MICROCONTROLLERS
Figure 1: Microprocessor (“IBM PCMCIA Data-Fax Modem V.34 FRU 42H4326 – ZiLOG
microprocessor Z80182-9359” by Raimond Spekking is licensed under CC BY-SA 4.0.)
Microcontroller: A microcontroller is a compact integrated circuit designed to govern a specific operation
in an embedded system. It includes a processor, memory (RAM, ROM, EPROM), and input/output (I/O)
peripherals on a single chip. Microcontrollers are used in automatically controlled devices such as automobile
engine control systems, medical devices, remote controls, office machines, appliances, power tools, toys, and
other embedded systems.
FUNDAMENTALS OF MICROPROCESSORS AND MICROCONTROLLERS | 11
• 1971: Intel introduced the first microprocessor, the Intel 4004, a 4-bit processor capable of performing
basic arithmetic and logic operations.
• 1972-1978: The second generation saw the development of 8-bit microprocessors like the Intel 8008
and 8080, which were used in early personal computers.
• 1978-1980: The third generation introduced 16-bit processors such as the Intel 8086 and Motorola
68000, which offered improved performance and capabilities.
• 1981-1995: The fourth generation brought 32-bit processors like the Intel 80386, which became
12 | FUNDAMENTALS OF MICROPROCESSORS AND MICROCONTROLLERS
Microcontrollers:
• 1971: The first microcontroller, the TMS 1000, was developed by Texas Instruments, combining a
processor, memory, and I/O on a single chip.
• 1974: Intel introduced the 8048, which became widely used in embedded systems such as PC
keyboards.
• 1993: The introduction of EEPROM memory allowed for electrically erasable and programmable
microcontrollers, facilitating rapid prototyping and in-system programming.
• Present: Modern microcontrollers are highly integrated and used in a wide range of applications, from
consumer electronics to industrial automation.
Power
Higher Lower
Consumption
Processing
Higher Lower
Power
Development
More complex Simpler
Complexity
FUNDAMENTALS OF MICROPROCESSORS AND MICROCONTROLLERS | 13
• Fetch, Decode, Execute: The microprocessor fetches instructions from memory, decodes them to
understand the required operations, and executes them.
• Arithmetic and Logic Operations: Performs basic arithmetic operations (addition, subtraction) and
logic operations (AND, OR, NOT).
• Data Transfer: Moves data between different parts of the system, such as from memory to registers.
• Control Operations: Manages the control signals to coordinate the activities of the system
components.
• Embedded Control: Designed to perform specific control tasks within an embedded system.
• I/O Operations: Interfaces with external devices through built-in I/O ports.
• Timers and Counters: Includes peripherals for timing and counting operations.
• Analog to Digital Conversion: Converts analog signals to digital form for processing.
Applications:
Deepen your understanding: Watch the accompanying lecture video to get deeper into the concepts covered
in the reading.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
14 | MICROPROCESSOR ARCHITECTURE
MICROPROCESSOR ARCHITECTURE
• Program Counter (PC): Holds the address of the next instruction to be executed.
• Instruction Register (IR): Stores the current instruction being decoded and executed.
• Memory Address Register (MAR): Holds the memory address for read/write operations.
• Memory Data Register (MDR): Temporarily stores data being transferred to/from memory.
• General Purpose Registers: Used for various data storage needs during processing.
MICROPROCESSOR ARCHITECTURE | 15
2. Data Bus:
• Bidirectional
• Transfers data between microprocessor and memory/I/O devices
• Width affects the amount of data transferred per cycle (e.g., 8-bit bus can transfer values 0-255)
3. Control Bus:
• Bidirectional
• Carries control signals (read, write, interrupt, etc.)
• Coordinates operations between microprocessor and other components
This hierarchy is designed to optimize access times and storage capacity. Frequently used data is kept in faster,
more expensive memory closer to the CPU, while less frequently used data is stored in slower, cheaper memory
farther from the CPU.
16 | MICROPROCESSOR ARCHITECTURE
1. Fetch:
2. Decode:
3. Execute:
This cycle repeats continuously as the CPU processes instructions. The efficiency of this cycle significantly
impacts the overall performance of the microprocessor.
For further explanation: A video lecture following this reading material provides additional insights and
clarifications
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
MICROPROCESSOR ARCHITECTURE | 17
References:
[1] [Link]
[2] [Link]
[3] [Link]
[4] [Link]
18 | INTRODUCTION TO MICROCONTROLLER SYSTEMS
INTRODUCTION TO MICROCONTROLLER
SYSTEMS
4. Timers/Counters:
These components measure time intervals and count events, crucial for tasks like generating PWM signals or
measuring input frequencies.
5. Interrupt Controller:
Manages interrupt requests from various sources, allowing the microcontroller to respond to external events
quickly
6. Communication Interfaces:
Many microcontrollers include built-in interfaces such as UART, SPI, I2C, and sometimes USB or Ethernet
for communication with other devices.
INTRODUCTION TO MICROCONTROLLER SYSTEMS | 19
• Real-time operation: Many embedded systems must respond to events within strict time constraints.
• Resource constraints: Embedded systems often have limited processing power, memory, and energy
resources.
• Reliability: These systems must operate reliably, often in harsh environments or safety-critical
applications.
• Integration: Embedded systems are tightly integrated with their surrounding hardware and
environment.
2. 16-bit Microcontrollers:
3. 32-bit Microcontrollers:
2. AVR:
3. ARM:
Each microcontroller family has its strengths and is suited for different types of applications. The choice
between them often depends on factors such as processing requirements, power constraints, development
ecosystem, and familiarity with the platform.
In the next chapter, we’ll explore how to start programming these microcontrollers and implement basic
input/output operations.
Deepen your understanding: Watch the accompanying lecture video to delve deeper into the concepts
covered in the reading.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
22 | GETTING STARTED WITH MICROCONTROLLER PROGRAMMING
Assembly Language
Assembly language is a low-level programming language that provides direct control over the hardware. It is
specific to a particular microcontroller [Link]:
Cons:
Example:
GETTING STARTED WITH MICROCONTROLLER PROGRAMMING | 23
C Language
C is a high-level programming language widely used for microcontroller programming due to its balance
between control and ease of [Link]:
Cons:
Example:
Programmers
• Hardware Programmers: Transfer code from a PC to the microcontroller. Examples include AVRISP
for AVR and PICkit for PIC.
• Bootloaders: Software that allows programming via serial or USB without additional hardware.
Digital I/O
Digital I/O pins can be configured as either inputs or outputs.
Example:
GETTING STARTED WITH MICROCONTROLLER PROGRAMMING | 25
Analog I/O
Many microcontrollers have built-in Analog-to-Digital Converters (ADC) for reading analog signals.
Example:
PART II
INTRODUCTION TO ASSEMBLY
LANGUAGE
In the ‘Introduction to Assembly Language’ module, students will learn:
• Definition and Key Features: Understand what assembly language is and its suitability for time-
critical and hardware-specific tasks.
• Advantages and Disadvantages: Explore the benefits of efficiency and control provided by assembly
language, as well as its complexities and lack of portability.
• Basic Concepts: Familiarize with mnemonics, labels, operands, directives, and comments, and learn
how to use these elements to write assembly programs.
• The Assembly Process: Learn the steps involved in creating and running an assembly language
program, including writing the source code, assembling, linking, loading, and executing the program.
• Practical Skills: Develop the ability to write efficient code, directly control hardware, optimize
performance, and implement specialized applications such as interrupt service routines and device
drivers.
By the end of this module, students will have a solid foundation in assembly language, enabling them to
program microcontrollers effectively and understand the inner workings of computer hardware at a low level.
28 | INTRODUCTION TO ASSEMBLY LANGUAGE
FUNDAMENTALS OF ASSEMBLY LANGUAGE | 29
FUNDAMENTALS OF ASSEMBLY
LANGUAGE
Introduction
In this course, we will delve into the world of assembly language, a low-level programming language that
provides direct control over a computer’s hardware. Assembly language is essential for understanding how
software interacts with hardware, and it is particularly useful for tasks that require precise timing, direct
hardware manipulation, or optimized performance.
• Processor-specific: Each assembly language is tailored to a particular processor family, meaning the
instructions are specific to that architecture.
• Direct hardware manipulation: Assembly language allows programmers to interact directly with
hardware components such as registers, memory locations, and I/O devices.
• Efficiency: Programs written in assembly language typically require less memory and execution time
compared to those written in high-level languages.
• Suitability for specific tasks: Assembly language is ideal for time-critical and hardware-specific tasks,
such as writing interrupt service routines and device drivers.
1. Efficient use of memory and processing power: Assembly language allows for optimal use of the
computer’s resources.
2. Direct hardware control: Programmers can directly manipulate hardware components, providing
30 | FUNDAMENTALS OF ASSEMBLY LANGUAGE
Disadvantages:
1. Complexity: Assembly language is more difficult to learn and use compared to high-level languages.
2. Limited portability: Programs written in assembly language are typically specific to a particular
processor architecture and are not easily transferable to other systems.
3. Time-consuming: Writing and maintaining assembly code is often more time-intensive than using
high-level languages.
4. Steeper learning curve: It requires a deeper understanding of computer architecture and hardware
operations.
2. Labels:
Labels are symbolic names used to mark specific memory addresses or program locations. They help organize
the code and making it more readable. For example:
START:
MOV AX, 1
ADD AX, 2
JMP START
3. Operands:
Operands are the data or memory locations that instructions operate on. They can be immediate values,
registers, or memory addresses. For example:
FUNDAMENTALS OF ASSEMBLY LANGUAGE | 31
4. Directives:
Directives are special commands for the assembler that do not translate directly to machine code but affect the
assembly process. Examples include:
5. Comments:
Comments are explanatory text ignored by the assembler. They are used to improve the readability of code and
provide explanations. For example:
MOV AX, 5 ; Load the value 5 into register
AX ADD AX, 3 ; Add 3 to the value in AX
For further explanation: A video lecture following this reading material provides additional insights and
clarifications
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
BOOLEAN ALGEBRA IN ASSEMBLY PROGRAMMING | 33
• True (1)
• False (0)
In the context of computer systems and assembly programming, Boolean algebra provides the foundation for:
Understanding Boolean algebra is crucial for assembly language programmers as it directly relates to how
computers process and manipulate data at the lowest level.
1. AND (∧)
◦ Symbol: ∧ or •
◦ Truth table:
34 | BOOLEAN ALGEBRA IN ASSEMBLY PROGRAMMING
2. OR (∨)
◦ Symbol: ∨ or +
◦ Truth table:
3. NOT (¬)
◦ Symbol: ¬ or ‘
◦ Truth table:
These basic operations can be combined to create more complex logical expressions and functions.
BOOLEAN ALGEBRA IN ASSEMBLY PROGRAMMING | 35
1. Bit Manipulation
2. Conditional Branching
3. Logical Comparisons
4. Optimizing Code
◦ Using Boolean operations can often lead to more efficient code than using arithmetic operations or
conditional statements.
◦ Boolean algebra is useful for implementing finite state machines, which are common in embedded
systems.
BOOLEAN ALGEBRA IN ASSEMBLY PROGRAMMING | 37
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
38 | MPLAB IDE AND ASSEMBLY PROGRAMMING
2. Debugger:
3. Project Manager:
4. Simulator:
4. Debugging techniques:
GOTO
Start ; Repeat
By following these practices and utilizing the powerful features of MPLAB X IDE, you can efficiently develop,
test, and optimize your assembly language programs for microcontrollers.
42 | MPLAB IDE AND ASSEMBLY PROGRAMMING
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
LAB #1 : REVIEW INSTRUCTION SET AND ORDER PARTS | 43
1. Download PIC16F18875 Data Sheets ([Link] to an external site.) and start reading it.
Order MICROCHIP TECHNOLOGY DM164136 PIC Micro MCU Curiosity High Pin Count (HPC)
Development Board PIC MCU 8-Bit
[Link] to an external site.
2. Download and install MPLAB IDE (Latest version) (Report – screenshot that the software is installed. If
you have the development board, add a screenshot that it works)
3. Read about the MICROCHIP TECHNOLOGY DM164136 PIC Micro MCU Curiosity High Pin
Count (HPC) Development Board PIC MCU 8-Bit and make notes.
44 | LAB #2 STUDENT ROBOT BLOCK DIAGRAM/FLOWCHART EXERCISE
In-class Exercise:
• Students will create a block diagram of a program for students, starting from sitting in the chair to
opening the classroom door.
• Once the block diagram is complete, other students will behave as student robots, and they will follow
the instructions you made.
• Check if student Robot is able to understand your instructions.
• All the teams in the class should now have a chance to see the Me Robot execute their program.
Remember that the Me Robot cannot do anything other than the instructions and knows nothing more
than what you have commanded it—he/She/they may crash into walls, etc.
In this design project, the students are to copy the program attached and enter it into the MPLAB
editor.
1. Build the program to get aHEX file.
2. Download [Link] file to the development board.
3. Demonstrate that the program runs by looking at the output pin.
4. Produce a technical report as if you were in the industry using template.
5. A conclusion of your results and discussion of anything you found especially interesting
or not expected from your work on this project.
CODE to test
LAB #3 : TEST A PROGRAM ON MPLAB | 47
48 | LAB #3 : TEST A PROGRAM ON MPLAB
Below video will guide you on how to create a project and run it on the MPLAB:
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
50 | ASSIGNMENT #1
ASSIGNMENT #1
Assignment #1
1. Write an instruction sequence to swap the contents of data registers at Ox300 and Ox200.
2. Write an instruction sequence to load the value of Ox39 into data memory locations Oxl OO-Oxl03.
3. Write an instruction sequence to subtract 10 from data memory locations Ox30-0x34.
4. Write an instruction to store the contents of the WREG register in the data register located at Ox25 of
bank 4.
5. Write an instruction sequence to copy the contents of data memory at Oxl00-0xl03 to Ox200-0x203
using the postincrement addressing mode.
6. Write an instruction sequence to copy the contents of data memory at Oxl00-0xl03 to Ox203-0x200,
that is, in reverse order, by combining the use of postincrement and postdecrement modes.
7. Write an instruction sequence to add 5 to data registers at $300–$303.
8. Write an instruction sequence to add the contents of the data registers at $10 and $20 and
store the sum at $30.
9. Write an instruction sequence to subtract the contents of the data register at Ox20 from that of the data
register at Ox30 and store the difference in the data register at OxlO.
Reference:
Chartrand, L., & Huang, H. W. (2005). (PIC microconteroller: an introduction to software & hardware
interfacing.)
ASSEMBLY LANGUAGE PROGRAMMING - I | 51
PART III
ASSEMBLY LANGUAGE
PROGRAMMING - I
In this module, students will delve into the fundamentals of assembly language programming, focusing on
the 8085 microprocessor. The module is structured to provide both theoretical knowledge and practical
experience through a series of lectures and lab assignments. By the end of this module, students will have a solid
understanding of the 8085 instruction set and the ability to implement basic assembly programs.
• Data Transfer Instructions: Instructions that move data between registers, memory, and I/O ports.
• Arithmetic Instructions: Instructions that perform arithmetic operations like addition, subtraction,
increment, and decrement.
• Logical Instructions: Instructions that perform bitwise logical operations such as AND, OR, XOR,
and complement.
• Branch Instructions: Instructions that alter the flow of execution, including jumps, calls, returns, and
restarts.
• Stack, I/O, and Machine Control Instructions: Instructions that manage the stack, perform I/O
operations, and control the microprocessor’s operation.
• Advanced Data Manipulation: Instructions for more complex data handling and manipulation.
• Conditional and Unconditional Branching: Detailed use of branching instructions for creating
loops and conditional execution.
• Interrupt Handling: Instructions and techniques for managing interrupts and implementing
52 | ASSEMBLY LANGUAGE PROGRAMMING - I
Lab #4: Code for DELAY – Use the Delay Code with
Blinking LED Program
In this lab assignment, students will write an assembly program to implement a delay routine and use it to
blink an LED. The lab will cover:
• Writing Delay Routines: Techniques for creating accurate delay loops using the 8085 instruction set.
• LED Control: Using I/O ports to control an LED, turning it on and off at regular intervals.
• Combining Delay and LED Control: Integrating the delay routine with LED control to create a
blinking effect.
Objectives:
• Controlling Multiple LEDs: Using multiple I/O ports to control more than one LED.
• Synchronized Blinking: Creating a program that alternates the blinking of two LEDs.
• Optimizing Delay Routines: Refining delay routines to ensure synchronized operation.
Objectives:
Introduction
The 8085 microprocessor, developed by Intel, has a rich set of instructions that allow it to perform a wide
range of operations. These instructions can be broadly classified into several categories, each serving a specific
purpose in the operation of the microprocessor. Understanding these instructions is crucial for programming
the 8085 effectively.
Categories of Instructions
The 8085 instruction set can be divided into the following categories:
MOV Rd, Rs Copy the contents of the source register (Rs) to the destination register (Rd).
Copy the contents of the memory location pointed to by the HL pair to the destination
MOV Rd, M
register (Rd).
Copy the contents of the source register (Rs) to the memory location pointed to by the
MOV M, Rs
HL pair.
MVI Rd, Data Move immediate 8-bit data to the destination register (Rd).
MVI M, Data Move immediate 8-bit data to the memory location pointed to by the HL pair.
LDA 16-bit address Load the contents of the specified memory location into the accumulator.
STA 16-bit address Store the contents of the accumulator into the specified memory location.
LHLD 16-bit address Load H and L registers directly from the specified memory locations.
SHLD 16-bit address Store H and L registers directly into the specified memory locations.
Load the accumulator indirectly from the memory location pointed to by the specified
LDAX B/D
register pair (B or D).
Store the contents of the accumulator into the memory location pointed to by the
STAX B/D
specified register pair (B or D).
XCHG None Exchange the contents of the H and L registers with the contents of the D and E registers.
2. Arithmetic Instructions
Arithmetic instructions perform arithmetic operations such as addition, subtraction, increment, and
decrement on the data in registers or memory.
Common Arithmetic Instructions:
8085 INSTRUCTION SET: PART 1 | 55
ADD R Add the contents of the specified register (R) to the accumulator.
ADD M Add the contents of the memory location pointed to by the HL pair to the accumulator.
ADC R Add the contents of the specified register (R) to the accumulator along with the carry flag.
Add the contents of the memory location pointed to by the HL pair to the accumulator along
ADC M
with the carry flag.
ACI Data Add immediate 8-bit data to the accumulator along with the carry flag.
SUB R Subtract the contents of the specified register (R) from the accumulator.
SUB M Subtract the contents of the memory location pointed to by the HL pair from the accumulator.
SBB R Subtract the contents of the specified register (R) and the borrow flag from the accumulator.
Subtract the contents of the memory location pointed to by the HL pair and the borrow flag
SBB M
from the accumulator.
SBI Data Subtract immediate 8-bit data and the borrow flag from the accumulator.
INR R Increment the contents of the specified register (R) by 1.
INR M Increment the contents of the memory location pointed to by the HL pair by 1.
DCR R Decrement the contents of the specified register (R) by 1.
DCR M Decrement the contents of the memory location pointed to by the HL pair by 1.
INX Reg. pair Increment the contents of the specified register pair by 1.
DCX Reg. pair Decrement the contents of the specified register pair by 1.
DAD Reg. pair Add the contents of the specified register pair to the contents of the HL pair.
DAA None Decimal adjust the accumulator.
3. Logical Instructions
Logical instructions perform bitwise logical operations such as AND, OR, XOR, and complement on the data
in registers or [Link] Logical Instructions:
56 | 8085 INSTRUCTION SET: PART 1
ANA R Logical AND the contents of the specified register (R) with the accumulator.
Logical AND the contents of the memory location pointed to by the HL pair with the
ANA M
accumulator.
ANI Data Logical AND immediate 8-bit data with the accumulator.
XRA R Logical XOR the contents of the specified register (R) with the accumulator.
Logical XOR the contents of the memory location pointed to by the HL pair with the
XRA M
accumulator.
XRI Data Logical XOR immediate 8-bit data with the accumulator.
ORA R Logical OR the contents of the specified register (R) with the accumulator.
Logical OR the contents of the memory location pointed to by the HL pair with the
ORA M
accumulator.
ORI Data Logical OR immediate 8-bit data with the accumulator.
CMP R Compare the contents of the specified register (R) with the accumulator.
CMP M Compare the contents of the memory location pointed to by the HL pair with the accumulator.
RRC None Rotate the contents of the accumulator right through the carry flag.
1. MOV Instruction:
2. MVI Instruction:
8085 INSTRUCTION SET: PART 1 | 57
◦ LDA 2500H: Loads the contents of memory location 2500H into the accumulator.
◦ STA 2500H: Stores the contents of the accumulator into memory location 2500H.
4. LXI Instruction:
◦ LXI H, 2500H: Loads the immediate value 2500H into the H-L pair.
◦ LDAX B: Loads the contents of the memory location pointed by the B-C pair into the
accumulator.
◦ STAX D: Stores the contents of the accumulator into the memory location pointed by the D-E
pair.
1. ADD Instruction:
2. ADI Instruction:
3. SUB Instruction:
4. SUI Instruction:
◦ SUI 0x10: Subtracts the immediate value 0x10 from the accumulator.
58 | 8085 INSTRUCTION SET: PART 1
7. DAD Instruction:
◦ DAD B: Adds the contents of the B-C pair to the H-L pair.
Summary
In this part of the reading material, we have covered the first three categories of the 8085 instruction set:
Data Transfer Instructions, Arithmetic Instructions, and Logical Instructions. These instructions form the
core of the operations that the 8085 microprocessor can perform, allowing it to manipulate data, perform
calculations, and execute logical [Link] the next part, we will explore the remaining categories: Branch
Instructions and Stack, I/O, and Machine Control Instructions. Understanding these instructions will provide
a comprehensive view of the capabilities of the 8085 microprocessor.
To enhance understanding, below are the lecture videos that may help in completing the lab
assignment.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
8085 INSTRUCTION SET: PART 2 | 59
Branch Instructions
Branch instructions in the 8085 microprocessor allow the program to change its execution sequence. These
instructions are crucial for implementing decision-making and loop structures in assembly language programs.
Types of Branch Instructions:
Opcode Description
3. Call Instructions:
4. Return Instructions:
5. Compare Instructions:
6. Rotate Instructions:
7. Restart Instructions:
◦ RST n: Calls one of eight subroutines located in the first 64 bytes of memory.
I/O Instructions:
1. ANA Instruction:
◦ ANA B: Performs a bitwise AND operation between the contents of register B and the
accumulator.
2. XRA Instruction:
◦ XRA C: Performs a bitwise XOR operation between the contents of register C and the
accumulator.
62 | 8085 INSTRUCTION SET: PART 2
3. CMP Instruction:
1. JMP Instruction:
2. JC Instruction:
3. CALL Instruction:
4. RET Instruction:
Summary
Understanding these instructions is important for effective assembly language programming on the 8085
microprocessor. Branch instructions allow for complex program flow control, while stack and machine control
instructions provide essential functionality for managing subroutines, interrupts, and overall program
[Link] that efficient use of these instructions requires careful consideration of program flow
and system resources. Practice and experience will help in choosing the most appropriate instructions for
specific programming tasks.
To enhance your understanding and to complete the lab assignment, please see the video lectures
below:
8085 INSTRUCTION SET: PART 2 | 63
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
64 | LAB #4 : CODE FOR DELAY
This report requires you to write down the assembly code for delay (use the delay code with the
blinking LED program). Use the following instructions:
1. Blinking LED code available from the lecture below for your review
2. Make the block diagram for the delay code which explains the algorithm you used
3. Based on the algorithm create an assembly code to provide a delay
4. Once the Delay code is created then add it to the existing blinking LED code from the lecture
5. Write a report stating the whole process, the difficulty, and tips you found in that process.
LAB #5 : BLINK TWO LEDS AT A TIME | 65
In this Lab, you will be creating your own code for blinking two LEDs at a time, follow the
instructions for this lab below:
1. Write a code that can turn the two LEDs (RA4 & RA6) ON at a time while LEDs (RA5 & RA7) are
OFF and vice versa in the second cycle
2. Make a block diagram or write a step-by-step algorithm for this program
3. Write a report stating the whole process, the difficulty, and tips you found in that process.
66 | LAB #5 : BLINK TWO LEDS AT A TIME
ASSEMBLY LANGUAGE PROGRAMMING - II | 67
PART IV
ASSEMBLY LANGUAGE
PROGRAMMING - II
In this module, students will further explore assembly language programming, focusing on the PIC16F18875
microcontroller. This module builds on foundational knowledge and introduces more advanced programming
techniques and practical applications. By the end of this module, students will have a thorough understanding
of the PIC16F18875 instruction set and the ability to implement complex assembly programs.
• Data Transfer Instructions: Instructions that move data between registers, memory, and I/O ports.
• Arithmetic Instructions: Instructions that perform arithmetic operations like addition, subtraction,
increment, and decrement.
• Logical Instructions: Instructions that perform bitwise logical operations such as AND, OR, XOR,
and complement.
• Control Instructions: Instructions that manage program flow, including jumps, calls, returns, and
resets.
• Special Instructions: Instructions for specific microcontroller operations, such as sleep, watchdog
timer reset, and no operation.
• Advanced Data Manipulation: Instructions for more complex data handling and manipulation.
• Conditional and Unconditional Branching: Detailed use of branching instructions for creating
loops and conditional execution.
68 | ASSEMBLY LANGUAGE PROGRAMMING - II
• Interrupt Handling: Instructions and techniques for managing interrupts and implementing
interrupt service routines.
• Timing and Delay Instructions: Instructions used for creating precise timing delays, which are
essential for various applications.
• Rotate and Shift Instructions: Used for bit manipulation, essential in applications such as
cryptography and data compression.
• Bit-Oriented Instructions: Precise control over individual bits in registers, crucial for tasks like setting
flags, toggling LEDs, or reading sensor states.
• Literal and Control Instructions: Immediate data manipulation and controlling the flow of the
program.
• Practical Applications: Implementing delays, reading and writing to I/O ports, using interrupts, and
implementing finite state machines.
• Lab #6: Rotating LED to RIGHT with Consistency: Writing an assembly program to rotate an
LED to the right consistently.
• Lab #7: Rotate LED on Each Button Press: Writing an assembly program to rotate an LED each
time a button is pressed.
• Configuring I/O Ports: Setting up the microcontroller ports for LED control.
• Using Rotate Instructions: Implementing rotate instructions to shift the LED pattern to the right.
• Creating Delay Routines: Adding delay loops to control the speed of the LED rotation.
Objectives:
• Configuring I/O Ports for Input: Setting up the microcontroller ports to read button presses.
• Debouncing Button Inputs: Implementing debouncing techniques to avoid false triggering.
• Using Rotate Instructions: Implementing rotate instructions to shift the LED pattern on each button
press.
Objectives:
2. Instruction Formats
The PIC16F18875 uses several instruction formats:
1. Byte-oriented operations
2. Bit-oriented operations
3. Literal operations
4. Control operations
Each format is designed to efficiently handle different types of operations, from data manipulation to program
flow control.
5. Special Instructions
5. Addressing Modes
The PIC16F18875 supports several addressing modes:
Below are the lecture videos to support the reading and lab assignments.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
PART 1: INTRODUCTION TO PIC16F18875 INSTRUCTION SET | 73
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
74 | PART 2: DETAILED PIC16F18875 INSTRUCTION SET AND PROGRAMMING TECHNIQUES
Bank Selection
The PIC16F18875 has multiple register banks. Use the BANKSEL directive for efficient bank switching:
BANKSEL TRISA ; Select bank containing TRISA
MOVLW 0xFF
MOVWF TRISA ; Set PORTA as all inputs
Interrupt Handling
Implement interrupt service routines (ISRs) using the RETFIE instruction:
ORG 0x0004 ; Interrupt vector location
GOTO ISR ; Jump to ISR
; ... (main program)
ISR:
; Interrupt handling code
76 | PART 2: DETAILED PIC16F18875 INSTRUCTION SET AND PROGRAMMING TECHNIQUES
Loop Optimization
Use decrement and skip instructions for efficient loops:
MOVLW 10 ; Load loop counter
MOVWF COUNTER
LOOP:
; Loop body
DECFSZ COUNTER, F
GOTO LOOP
; Continue after loop
Summary
While the instruction set is compact, it provides all the necessary tools for complex embedded system
development. Regular practice and reference to the official Microchip documentation will help in becoming
proficient in PIC assembly programming. Remember to always consult the latest PIC16F18875 datasheet and
programming manual for the most up-to-date and detailed information on instructions and their usage.
Below are the lecture videos to support the reading and lab assignments.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
PART 2: DETAILED PIC16F18875 INSTRUCTION SET AND PROGRAMMING TECHNIQUES | 77
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
Refrences:
[1] [Link]
[2] [Link]
[3] [Link]
PIC16%28L%29F18855_75%20Data%20Sheet_DS40001802E.pdf
[4] [Link]
[5] [Link]
78 | PART 3: ADVANCED INSTRUCTIONS AND PRACTICAL APPLICATIONS FOR PIC16F18875 ASSEMBLY
PROGRAMMING
1. Advanced Instructions
The PIC16F18875 microcontroller includes several advanced instructions that enhance its functionality and
allow for more complex operations. These instructions are essential for efficient and powerful assembly
programming.
2. Practical Applications
Understanding how to apply these instructions in real-world scenarios is crucial for effective programming.
Here are some practical applications of the PIC16F18875 instruction set.
BIT_CLEAR:
MOVLW 0x00 ; Load W with 0
CONTINUE:
; Continue with rest of the program
ERROR_STATE:
; Error handling code
GOTO FSM_LOOP
GOTO MAIN
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
Refrences:
[1] [Link]
[2] [Link]
[3] [Link]
PIC16%28L%29F18855_75%20Data%20Sheet_DS40001802E.pdf
[4] [Link]
[5] [Link]
[6] [Link]
PART 3: ADVANCED INSTRUCTIONS AND PRACTICAL APPLICATIONS FOR PIC16F18875 ASSEMBLY
PROGRAMMING | 83
[7] [Link]
[8] [Link]
[9] [Link]
84 | PART 4: INSTRUCTION SET FOR 16F18875 SPECIFIC TO LAB ASSIGNMENTS AND VIDEO LECTURES
This section provides an overview of the crucial data transfer, arithmetic, logical,
and bit-oriented instructions for the 16F18875 microcontroller, which are
fundamental to the Lab Assignments and Lecture Videos. Some of these
instruction sets might overlap with previous readings. Understanding these
instructions is key for effective assembly language programming and practical
application in various embedded systems projects.
◦ Syntax: MOVLW k
◦ Function: Loads the literal value k into the W register.
◦ Example: MOVLW 0x55 ; Loads the value 0x55 into the W register.
◦ Syntax: MOVWF f
◦ Function: Copies the contents of the W register to the specified file register f.
◦ Example: MOVWF 0x20 ; Copies the contents of the W register to file register 0x20.
◦ Syntax: MOVF f, d
◦ Function: Moves the contents of the file register f to the W register if d is 0.
◦ Example: MOVF 0x20, W ; Moves the contents of file register 0x20 to the W register.
Arithmetic Instructions
◦ Syntax: ADDWF f, d
◦ Function: Adds the contents of the W register to the file register f, and stores the result in f if d is
1.
◦ Example: ADDWF 0x20, F ; Adds W register to file register 0x20, storing the result in 0x20.
◦ Syntax: SUBWF f, d
◦ Function: Subtracts the contents of the W register from the file register f, and stores the result in W
if d is 0.
◦ Example: SUBWF 0x20, W ; Subtracts W register from file register 0x20, storing the result in W.
◦ Syntax: INCF f, d
◦ Function: Increments the contents of the file register f by one and stores the result in f if d is 1.
◦ Example: INCF 0x20, F ; Increments the contents of file register 0x20 by one, storing the
result in 0x20.
◦ Syntax: DECF f, d
◦ Function: Decrements the contents of the file register f by one and stores the result in W if d is 0.
◦ Example: DECF 0x20, W ; Decrements the contents of file register 0x20 by one, storing the
result in W.
Logical Instructions
◦ Syntax: ANDWF f, d
◦ Function: Performs a bitwise AND operation between the W register and the file register f, storing
the result in f if d is 1.
◦ Example: ANDWF 0x20, F ; Performs AND operation between W register and file register
0x20, storing result in 0x20.
◦ Syntax: IORWF f, d
◦ Function: Performs a bitwise OR operation between the W register and the file register f, storing
the result in f if d is 1.
◦ Example: IORWF 0x20, F ; Performs OR operation between W register and file register 0x20,
storing result in 0x20.
◦ Syntax: XORWF f, d
◦ Function: Performs a bitwise XOR operation between the W register and the file register f, storing
the result in f if d is 1.
◦ Example: XORWF 0x20, F ; Performs XOR operation between W register and file register
0x20, storing result in 0x20.
Bit-Oriented Instructions
◦ Syntax: BCF f, b
◦ Function: Clears the specified bit b in the file register f.
◦ Example: BCF 0x20, 2 ; Clears bit 2 of file register 0x20.
◦ Syntax: BSF f, b
◦ Function: Sets the specified bit b in the file register f.
◦ Example: BSF 0x20, 3 ; Sets bit 3 of file register 0x20.
◦ Syntax: BTFSC f, b
◦ Function: Tests bit b in the file register f and skips the next instruction if the bit is clear.
◦ Example: BTFSC 0x20, 4 ; Tests bit 4 of file register 0x20, skips next instruction if bit is clear.
◦ Syntax: BTFSS f, b
PART 4: INSTRUCTION SET FOR 16F18875 SPECIFIC TO LAB ASSIGNMENTS AND VIDEO LECTURES | 87
◦ Function: Tests bit b in the file register f and skips the next instruction if the bit is set.
◦ Example: BTFSS 0x20, 5 ; Tests bit 5 of file register 0x20, skips next instruction if bit is set.
Control Instructions
◦ Syntax: NOP
◦ Function: Executes no operation and moves to the next instruction.
◦ Example: NOP ; Simply does nothing for one instruction cycle.
◦ Syntax: CLRWDT
◦ Function: Resets the watchdog timer to prevent a system reset.
◦ Example: CLRWDT ; Resets the watchdog timer.
3. SLEEP:
◦ Syntax: SLEEP
◦ Function: Puts the microcontroller into sleep mode to save power.
◦ Example: SLEEP ; Puts the microcontroller into sleep mode.
4. RESET:
◦ Syntax: RESET
◦ Function: Resets the microcontroller.
◦ Example: RESET ; Resets the microcontroller.
Branching Instructions
1. GOTO:
◦ Syntax: GOTO k
◦ Function: Unconditionally branches to the specified address k.
◦ Example: GOTO 0x100 ; Jumps to address 0x100.
88 | PART 4: INSTRUCTION SET FOR 16F18875 SPECIFIC TO LAB ASSIGNMENTS AND VIDEO LECTURES
2. CALL:
◦ Syntax: CALL k
◦ Function: Calls a subroutine at the specified address k.
◦ Example: CALL 0x200 ; Calls the subroutine at address 0x200.
3. RETURN:
◦ Syntax: RETURN
◦ Function: Returns from a subroutine to the calling function.
◦ Example: RETURN ; Returns from a subroutine.
◦ Syntax: RETFIE
◦ Function: Returns from an interrupt service routine.
◦ Example: RETFIE ; Returns from an interrupt service routine.
Example Programs
• LED Blinking:
START:
BSF TRISB, 0 ; Set RB0 as input
BCF TRISB, 1 ; Set RB1 as output
LOOP:
BTFSS PORTB, 0 ; Check if button is pressed
GOTO SKIP
PART 4: INSTRUCTION SET FOR 16F18875 SPECIFIC TO LAB ASSIGNMENTS AND VIDEO LECTURES | 89
START:
BSF TRISB, 0 ; Set RB0 as input
BCF TRISB, 1 ; Set RB1 as output
CHECK_BUTTON:
BTFSS PORTB, 0 ; Check if button is pressed
GOTO BUTTON_PRESSED
GOTO CHECK_BUTTON
BUTTON_PRESSED:
BSF PORTB, 1 ; Turn on LED
GOTO CHECK_BUTTON
END
• Simple Subroutine:
MAIN:
CALL SUBROUTINE
GOTO MAIN
SUBROUTINE:
BSF PORTB, 1 ; Turn on LED
RETURN
END
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
90 | LAB #7: ROTATE LED ON EACH BUTTON PRESS
In this Lab, you will be creating your own code for Rotating LED on each button press, follow the
instructions for this lab below:
1. Write a code that can rotate the LED whenever the button is pressed.
2. Rotate the button press from left (RA7) to right (RA4)
3. Make a block diagram or write a step by step algorithm for this program
4. Write a report stating the whole process, difficulty, tips you found in that process.
LAB #6: ROTATING LED TO RIGHT WITH CONSISTENC | 91
In this Lab, you will be creating your own code for RIGHT rotating LED consistency, follow the
instructions for this lab below:
1. Write a code that can turn the LED on the development board towards the right (from RA7 to RA4)
with consistency.
2. Make a block diagram or write a step by step algorithm for this program
3. Write a report stating the whole process, difficulty, tips you found in that process.
4. Attach the report, asm file of your code for me to test, and a demo video of the running code (optional)
92 | LAB #6: ROTATING LED TO RIGHT WITH CONSISTENC
ASSEMBLY PROGRAMMING -III | 93
PART V
ASSEMBLY PROGRAMMING -III
In this module, students will explore advanced assembly programming concepts, focusing on the
PIC16(L)F18855/75 microcontroller and its ADC2 module. This module is designed to provide an in-depth
understanding of the ADC2 functionalities and configurations, along with practical lab assignments that
reinforce theoretical knowledge through hands-on projects.
• Sample and Hold Circuit: Captures and holds the analog input voltage.
• Successive Approximation Converter: Performs the analog-to-digital conversion.
• Result Registers (ADRESH:ADRESL): Store the conversion results.
• Advanced Features: 8-bit acquisition timer, capacitive voltage divider (CVD) support, automatic
repeat and sequencing, computation features such as averaging and low-pass filter functions, and
selectable interrupts.
• Configuring I/O Ports: Setting up the microcontroller ports for external circuit control.
• Using External Inputs and Outputs: Implementing programs that read from and write to external
circuits.
• Creating Delay Routines: Adding delay loops to control the timing of interactions with external
circuits.
Objectives:
• Sensor Inputs: Configuring the microcontroller to read inputs from door/window sensors and motion
detectors.
• User Interface: Implementing a keypad for arming/disarming the system and an LCD display for
system status.
• Outputs: Controlling LEDs and a piezo buzzer or siren for alarm indications.
• Timing Considerations: Implementing entry/exit delays and alarm activation delays.
• State Machine: Managing the system’s behavior in different states (disarmed, armed, alarm triggered).
Objectives:
ASSEMBLY PROGRAMMING -III | 95
• Analog-to-Digital Conversion: Configuring the ADC2 module to read the temperature from the
MCP9701 sensor.
• Temperature Calculation: Converting the ADC reading to a temperature value.
• LED Indicators: Using LEDs to indicate the temperature status (high, low, on target).
Objectives:
• Understand how to configure and use the ADC2 module for analog-to-digital conversion.
• Learn to calculate temperature values from ADC readings.
• Gain practical experience in writing assembly programs that interact with sensors and indicators.
These topics will be discussed in detail later in the module, providing students with both theoretical knowledge
and practical skills in advanced assembly programming for the PIC16(L)F18855/75 microcontroller.
96 | ASSEMBLY PROGRAMMING -III
PART 1: INTRODUCTION TO PIC16(L)F18855/75 ADC2 MODULEC | 97
PART 1: INTRODUCTION TO
PIC16(L)F18855/75 ADC2 MODULEC
Key Components:
• Sample and Hold Circuit: Captures and holds the analog input voltage stable during conversion.
• Successive Approximation Converter: Performs the analog-to-digital conversion and generates a
10-bit binary result.
• Result Registers (ADRESH:ADRESL): Store the conversion results for further processing.
2. Advanced Features
The ADC2 module includes several advanced features to enhance its functionality:
4. Interrupt Capabilities
The ADC2 module can generate interrupts upon:
• Completion of a conversion.
• Threshold comparison results.
These interrupts can wake the device from Sleep mode, enabling power-efficient operation in battery-powered
applications.
5. Configuration Considerations
When configuring and using the ADC2 module, several factors must be considered:
Summary
The ADC2 module in the PIC16(L)F18855/75 microcontroller provides advanced features for precise and
efficient analog-to-digital conversion. Understanding its key components, configuration options, and
advanced features is important for effectively utilizing its capabilities in analog signal processing and embedded
system [Link] the next part, we will delve into the detailed configuration and operation procedures of the
ADC2 module, including practical examples and best practices for achieving accurate and reliable conversions.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
PART 2: DETAILED CONFIGURATION AND OPERATION OF THE PIC16(L)F18855/75 ADC2 MODULE | 101
Example:
BANKSEL TRISA
BSF TRISA, 0 ; Set RA0 as input
BANKSEL ANSELA
BSF ANSELA, 0 ; Set RA0 as analog input
Example:
MOVLW 0x00 ; Select AN0 (RA0) as input channel
MOVWF ADPCH
Example:
MOVLW 0x03 ; Set positive reference to FVR 4.096V
MOVWF ADREF
Example:
MOVLW 0x03 ; Set ADC clock source to FOSC/8
MOVWF ADCLK
Example:
BSF ADCON0, ADON ; Enable ADC module
BSF ADCON0, ADGO ; Start conversion
Example:
BTFSC ADCON0, ADGO ; Wait for conversion to complete
GOTO $-1 ; Loop until conversion is done
MOVF ADRESH, W ; Read upper 2 bits of result
MOVWF RESULT_HIGH
MOVF ADRESL, W ; Read lower 8 bits of result
MOVWF RESULT_LOW
104 | PART 2: DETAILED CONFIGURATION AND OPERATION OF THE PIC16(L)F18855/75 ADC2 MODULE
4. Practical Examples
Summary
In this part, we have explored the detailed configuration and operation of the ADC2 module in the
PIC16(L)F18855/75 microcontroller. By understanding how to configure ports, select channels, choose
voltage references, set conversion clock sources, and handle interrupts, you can effectively utilize the ADC2
module for accurate and efficient analog-to-digital [Link] practice and reference to the official
Microchip documentation will help in becoming proficient in using the ADC2 module. Always consult the
latest datasheet and programming manual for the most up-to-date and detailed information on the ADC2
module and its usage.
PART 2: DETAILED CONFIGURATION AND OPERATION OF THE PIC16(L)F18855/75 ADC2 MODULE | 107
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
108 | READINGS SPECIFIC TO LAB ASSIGNMENTS
2. User Interface:
3. Outputs:
4. Timing Considerations:
5. State Machine:
◦ Disarmed state
◦ Armed state
◦ Alarm triggered state
Implementation Tips
1. Use interrupts for sensor inputs to ensure quick response times.
2. Implement debouncing for keypad inputs to avoid false triggering.
3. Use timer interrupts for managing delays and timing functions.
4. Store the security code in EEPROM for persistence across power cycles.
5. Use a state machine approach to manage system behavior in different modes.
2. Analog-to-Digital Conversion:
3. Temperature Calculation:
4. LED Indicators:
Implementation Tips
1. Configure the ADC for the appropriate voltage reference and acquisition time.
2. Use averaging of multiple ADC readings to reduce noise.
3. Implement hysteresis to prevent rapid switching between temperature states.
4. Use floating-point calculations for accurate temperature conversion.
Deepen your understanding: Watch the accompanying lecture video to delve deeper into the concepts
covered in the reading.
One or more interactive elements has been excluded from this version of the text. You can view
them online here: [Link]
LAB #8 : MAKE THREE PROGRAM USING EXTERNAL CIRCUIT | 113
In this Lab, you will be creating your own code for the 3 blinking LEDs program Download 3
blinking LEDs program, follow the instructions for this lab as mentioned below:
1. Perform all three programs using the separate circuit for LED. DO NOT use the built-in LED from the
development board.
2. Write a report stating the whole process, the difficulty, and tips you found in that process.
3. Include the schematic of your circuit in the report.
4. Attach the report, asm file of your code for me to test, and a demo video of the running code (optional)
114 | LAB #9: HOME SECURITY SYSTEM (ALARM SYSTEM)
Objective: Design and implement a microcontroller-based development board for a home security system
using the PIC16F18875 microcontroller. The system should meet the specified performance requirements and
be thoroughly documented.
Specifications
1. System Scope:
2. Code Input:
◦ The system will be enabled and disabled by inputting a 3-digit code sequentially.
LAB #9: HOME SECURITY SYSTEM (ALARM SYSTEM) | 115
3. Arming Delay:
◦ A 30-second delay upon arming the system at a door opening to allow the occupant to exit without
triggering the alarm.
4. Disarming Delay:
◦ A 30-second delay upon entering the premises at a door opening to allow the occupant to enter
and disarm the system without triggering the alarm.
5. Alarm Outputs:
6. Opening Indication:
◦ The system will indicate which opening was entered when enabled and retain this information
until reset.
◦ Inputs: Sensor outputs (5), code input, silent feature, and reset signal.
◦ Outputs: Two system outputs for the siren and monitoring station, indicated by LEDs.
8. Board Design:
◦ Ensure the development board has enough pins for all connections.
Requirements
1. Assembly Language Program:
◦ Build the program and produce the .asm file for review.
◦ Download the .HEX file.
◦ Debug the program thoroughly and include portions of the debug process in your report.
3. Demonstration:
4. Technical Report:
Detailed Steps
1. Circuit Design:
◦ Design the circuit to monitor 5 openings with sensors connected to the microcontroller.
◦ Include input mechanisms for the 3-digit code, silent feature, and reset signal.
◦ Design output connections for the siren and monitoring station, indicated by LEDs.
2. Coding:
◦ Initialize the microcontroller’s I/O ports and configure the ADC for sensor inputs.
◦ Write subroutines for reading the sensors, inputting the code, and managing delays.
◦ Implement logic for arming/disarming the system, triggering alarms, and indicating which opening
was entered.
◦ Test the circuit and code to ensure all specifications are met.
◦ Debug any issues and document the debugging process.
4. Documentation:
Submission
• Schematic Diagram: Upload a PDF or image file of the schematic diagram.
• Circuit Board Pictures: Upload image files of the circuit board.
• Code: Include the commented assembly code in a text file or directly within the submission platform.
• Video: Upload the video file demonstrating the working security system.
• ASM and HEX Files: Upload the .asm and .HEX files containing the code.
Grading Criteria
1. Report Quality:
2. System Functionality:
3. Programming Standards:
Objective: Using the development board and a PIC16F18875 microcontroller, build and program a
Temperature Indicator that measures temperature using the MCP9701 sensor and indicates the status with
LEDs based on specific temperature thresholds.
Performance Specifications
1. Temperature Measurement:
2. Temperature Comparison:
3. LED Indicators:
Requirements
1. Schematic Diagram:
◦ Provide a detailed schematic diagram of the circuit, including the connections between the
PIC16F18875 microcontroller, MCP9701 sensor, and the LEDs.
◦ Ensure all components are labeled clearly.
3. Code:
4. Video Demonstration:
5. ASM File:
◦ Upload the assembly (.asm) file containing the code for the Temperature Indicator.
Detailed Steps
1. Circuit Design:
◦ Design the circuit using the MCP9701 sensor connected to the ADC input of the PIC16F18875.
◦ Connect the LEDs to the appropriate output pins of the microcontroller.
◦ Ensure proper power supply and grounding for all components.
2. Coding:
◦ Test the circuit and code to ensure accurate temperature measurement and LED indication.
◦ Debug any issues that arise during testing.
4. Documentation:
Submission
• Schematic Diagram: Upload a PDF or image file of the schematic diagram.
• Circuit Board Pictures: Upload image files of the circuit board.
• Code: Include the commented assembly code in a text file or directly within the submission platform.
• Video: Upload the video file demonstrating the working Temperature Indicator.
• ASM File: Upload the .asm file containing the code.
This appendix provides brief information to support the main content of the module in this [Link] includes
summaries and key points regarding the 8085 instruction set and the PIC16(L)F18855/75 ADC2 module,
along with practical code examples and configuration details.
2. Arithmetic Instructions:
3. Logical Instructions:
4. Branch Instructions:
1. Port Configuration:
2. Channel Selection:
◦ Use the ADPCH register to select the desired analog input channel.
◦ Configure the ADREF register to select the positive and negative voltage references.
◦ Select the ADC conversion clock source via the ADCLK register and the ADCS bit of the
ADCON0 register.
5. Interrupt Control:
◦ Enable ADC interrupts by setting the ADIE bit in the PIE1 register and the PEIE and GIE bits in
the INTCON register.
6. Result Formatting:
APPENDIX | 123
◦ Choose between left-justified and right-justified formats for the 10-bit conversion result using the
ADFRM0 bit of the ADCON0 register.
◦ Enable the ADC module by setting the ADON bit of the ADCON0 register.
◦ Start a conversion by setting the ADGO bit.
◦ Upon completion, the ADGO bit is cleared, and the conversion result is stored in the
ADRESH:ADRESL registers.
124 | APPENDIX