SlideShare a Scribd company logo
Microcontroller- 16EC2304
VI - Semester
MC-Syllabus
Module-1
▪ Introduction to Microcontroller - Microprocessor and Microcontroller Characterization, Components of a
Microcontroller, Microcontroller Architecture.
• Main Characteristics of PIC Microcontrollers - Arithmetic and Logic Unit (ALU), Working Register in PIC
Microcontrollers, Machine Cycles and Execution of Instructions, Pipelining for Instruction Execution, Oscillators,
Configuration Bits, Reset Options, Low-Power Consumption Mode, Watchdog Timer, Program Counter,RISC,
Compare Harvard architecture with von Neumann architecture.
Module-2
▪ Memory in Microcontrollers – Memory Organization, RAM, Data Memory, EEPROM, Flash Memory.
• Instruction Set and Assembler Language Programming - Arithmetic Instructions, Logic and Compare
instructions, Rotate Instruction and Data Serialization, Branch Instructions and Looping, Call Instructions and Stack
•
MC-Syllabus
Module-3
▪ Programming in C - Data Types and Time Delays, bit-addressable I/O, Logic Operations, Data Serialization, ROM &
RAM Allocation
Module-4
• Timers and Interrupts - Instruction Pipeline, Timers, The CCP Module, Interrupt, Examples of Timer and Interrupt
Applications.
• Parallel and Serial Communication – Parallel IO, Serial IO, advantages of serial communication over parallel,
Streaming Parallel Port, USART, SPI, I2C
Module-5
▪ Sensors and Actuators - Interfacing LED, LCD, Keypad, ADC, DAC, Buzzer, Sensor, Relays, Stepper & DC Motor
TEXT BOOKS:
[1]Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers -
Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009.
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And
Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
•
REFERENCE BOOKS:
• 1. Myke Predko, “Programming and Customizing the PIC Microcontroller”, Mc Graw Hill Education, 3rd
Edition, 2008.
• 2. John B. Peatman, “Design with PIC Microcontrollers”, Prentice Hall, 1997.
• 3. Verle Milan, “PIC Microcontrollers – Programming in C”, Mikroelektronika, 1 st Edition, 2009
• For the Blended Learning
1. https://www.classcentral.com/course/swayam-microprocessors-and-microcontrollers-9894
2. https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
3. https://circuitdigest.com/microcontroller-projects/writing-your-first-pic-microcontroller-program
Module-3-PROGRAMMING IN C
Data Types and Time Delays [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Why program a PIC18 in C programming language?
▪ Writing Programs in C are easier than in Assembly language programming(ALP).
▪ Easier to modify and update the program than Assembly language.
▪ C code is portable to other microcontrollers with no or little modifications compared to ALP.
▪ Codes available in function libraries can be used.
▪ But the hex file generated for C program is larger than the hex file generated for assembly language programming.
[2]
PROGRAMMING IN C
Data Types and Time Delays [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data types [2]
1. Unsigned character:
▪ It is an 8 bit data type and can take values from 0-255(00-FFH)
▪ C compilers use signed char as default hence unsigned should be mentioned.
▪ Since int data types generate a large size hex files unsigned data types should be used instead.
▪ Eg. Used for counter values less than 256.
[2]
PROGRAMMING IN C
Data Types and Time Delays [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data types [2]
2. signed character:
▪ It is an 8 bit data type uses D7bit used for the sign (-or+).
▪ 7 bits for magnitude giving values from -128 to+127.
▪ eg. Used for representing temperature (as temp can be + or -)
[2]
PROGRAMMING IN C
Data Types and Time Delays [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data types [2]
3. unsigned int:
▪ It is an 16 bit data type and takes a value in the range 0 to 65,535 (0000H-FFFFH).
▪ eg. 16 bit unsigned int used to represent variables like memory address or counter values more than 256.
▪ Since unsigned int is 16 bit and most registers and RAM location in PIC18 are 8 bit long, use of unsigned int generates a
large hex file.
[2]
PROGRAMMING IN C
Data Types and Time Delays [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data types [2]
3. Signed int:
▪ It is an 16 bit data type and uses D15 (of D0-D15) bit to represent the sign .
▪ Has only 15 bits for magnitude. So can represent in the range -32,768- +32,767.
▪ eg.
PROGRAMMING IN C
Time Delays [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Two ways to generate time delays
1. A simple for loop: In c programing in creating a time delay using FOR loop, the accuracy of the delay program
is affected by Compiler being used and Crystal oscillator connected to OSC1 - OSC2
2. Using timers of PIC18F4550
[2]
[2]
PROGRAMMING IN C
Byte addressable I/O [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
➢ PIC18F 4550 has PORTA, PORTB, PORTC, PORTD, PORTE
➢ Each PORTx is associated with 3 registers.
➢ PORT, TRIS, LAT eg. PortB has PORTB, TRISB, LATB
➢ TRIS (data direction register)is an SFR used to make a PORT input or output port. At reset all the TRIS registers are FF i.e
input port.
➢ PortA has 7 pins, PorTB,C,D has 8 pins and PORTE has 4pins
➢ PORT register reads levels on the device pins and when writes it writes to the output latch.
➢ LAT or data latch register used to read-modify-write on the values driven by the I/O Pins.
[2] [2]
PROGRAMMING IN C
Byte addressable I/O [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
➢ PIC18F 4550 has PORTA, PORTB, PORTC, PORTD, PORTE
➢ Each PORTx is associated with 3 registers.
➢ PORT, TRIS, LAT eg. PortB has PORTB, TRISB, LATB
➢ TRIS (data direction register)is an SFR used to make a PORT input or output port. At reset all the TRIS registers are
FF i.e input port.
➢ PortA has 7 pins, PorTB,C,D has 8 pins and PORTE has 4pins
➢ PORT register reads levels on the device pins and when writes it writes to the output latch.
➢ LAT or data latch register used to read-modify-write on the values driven by the I/O Pins.
[2] [2]
PROGRAMMING IN C
Byte addressable I/O [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
➢ PIC18F 4550 has PORTA, PORTB, PORTC, PORTD, PORTE
➢ Each PORTx is associated with 3 registers.
➢ PORT, TRIS, LAT eg. PortB has PORTB, TRISB, LATB
➢ TRIS (data direction register)is an SFR used to make a PORT input or output port. At reset all the TRIS registers are
FF i.e input port.
➢ PortA has 7 pins, PorTB,C,D has 8 pins and PORTE has 4pins
➢ PORT register reads levels on the device pins and when writes it writes to the output latch.
➢ LAT or data latch register used to read-modify-write on the values driven by the I/O Pins.
[2]
PROGRAMMING IN C
Bit addressable I/O [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
[3]
[3]
PROGRAMMING IN C
Bit addressable I/O [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Portxbits.Rxy
➢ Each bit (port pins) of the PORT can be accessed
independently
➢ Portxbits.Rxy
[2]
[2]
PROGRAMMING IN C
Bit addressable I/O [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
[2]
PROGRAMMING IN C
Logic operators [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
➢ Ability to perform bitwise operation
Bit-wise shift operation
[2]
[2]
PROGRAMMING IN C
Logic operators [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
➢ Ability to perform bitwise operation
[2] [2]
PROGRAMMING IN C
Data Conversion in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ASCII to Unpacked BCD
Packed BCD to ASCII
ASCII to packed BCD
[2]
[2]
PROGRAMMING IN C
Data Conversion in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Checksum data in ROM:
➢ To check the integrity of the ROM data checksum calculation is
done
➢ Checksum checks for corruption in ROM data.
➢ Corruption can happen due to current surge on turning on and off.
➢ Checksum bytes is tagged to the end of the series of data.
Steps to calculate checksum data
➢ Add the bytes together drop the carries
➢ Take 2’s complement of result which is the checksum
byte.
➢ Add the series of data with the checksum byte. If the
addition is ‘0’ after dropping the carry the data is not
corrupted otherwise it is corrupted.
Example how checksum byte works is as follows
[2]
[2]
PROGRAMMING IN C
Data Conversion in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Checksum data in ROM:
Program how checksum byte works is as follows
[2]
[2]
PROGRAMMING IN C
Data Conversion in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Binary (hex) to Decimal and ASIIC conversion in C
[2]
PROGRAMMING IN C
Data Serialisation in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data serialization is way of sending byte of data one bit at a time from a single pin.
TWO WAYs are
➢ Use of serial port. – Little control on the sequence of data being transferred.
➢ Data transfer one bit at a time and will have control on the sequence of data
and space between them. Can be done using I2C and CAN but few devices do
not support these standards. Hence data serialization using C is used.
[2]
PROGRAMMING IN C
Data Serialisation in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data serialization is way of sending byte of data one bit at a time from a single pin.
[2]
PROGRAMMING IN C
Data Serialisation in C programming [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data serialization is way of sending byte of data one bit at a time from a single pin.
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ROM allocation
➢ PIC 18 has maximum RAM capacity of 4K i.e from 000-FFFH
➢ PIC 18 has maximum ROM capacity of 2M i.e from 000000-1FFFFFH
➢ PIC18F4550 has maximum RAM capacity of 2K
➢ PIC18F4550 has maximum ROM capacity of 32K
➢ In assembly TBLRD instruction to access the program ROM for the purpose
of data
➢ C18 compiler also uses ROM space for storing data
[2]
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ROM allocation:
➢ Allocating Program space to fixed data
➢ The keyword used is rom
[2]
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ROM allocation: Near and Far storage qualifier
➢ Indicates what region the data and code should be placed
➢ Near qualifier will allocate data in the first 64KB of ROM location
➢ Far qualifier will allocate data variable within the entire 2MB of ROM
Example of near storage qualifier
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ROM allocation: Near and Far storage qualifier
➢ Indicates what region the data and code should be placed
➢ Near qualifier will allocate data in the first 64KB of ROM location (for general PIC18)
➢ Far qualifier will allocate data variable within the entire 2MB of ROM(for general PIC18)
Example of Far storage qualifier [2]
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ROM allocation: Using pragma directive to allocate fixed location
➢ Like ORG directive in assembly C18 compilers use pragma directive to allocate fixed location
[A] Putting code in specific ROM location
[2]
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
ROM allocation: Using pragma directive to allocate fixed location to data and code
➢ Like ORG directive in assembly C18 compilers use pragma directive to allocate fixed location
[B] Putting data in specific ROM location
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data RAM allocation in C18: PIC18 has 2K of RAM
[2] [2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data RAM allocation in C18: PIC18 has 2K of RAM
Near Far Storage qualifier
Example of near qualifier
Example of far qualifier
[2]
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
Data RAM allocation in C18: PIC18 has 2K of RAM
Putting data in a specific RAM Address using pragma directive
➢ Two options for pragma directive are
1. idata – initialised data
2. udata – uninitialized data
[2]
[2]
PROGRAMMING IN C
ROM & RAM Allocation [2,3]
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
➢ Overlay storage data: Two different variables can be allocated same address location
provided the two variable's are not being used at the same time.
Example of allocation of same location to two
independent variables.
Example of allocation of different location to
two dependent variables.
[2]
[2]
References and disclaimer
The contents (pictures, text and programs) of the above slides have
been adapted from the following references (mainly reference 2). It is
only meant as a students’ reference for the course 16EC2403 –
microcontroller and not intended to be published.
[1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and
Applications with PIC”, CRC Press, 1st Edition, 2009
[2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”,
using assembly and C for PIC18, Pearson Education International, 2008
[3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf
[4] https://www.youtube.com/watch?v=Xl2nWDcy0To
[5] https://www.youtube.com/watch?v=DmwOSdwzZ3E
[6] D.V Hall, Microprocessors and Interfacing”,TATA MCGRAW HILL, revised 2nd edition

More Related Content

PDF
Embedded Systems Syllabus
PDF
Microprocessors, Microcomputers and Assembly Language, Microprocessor Archit...
PPTX
BEC405A_MICROCONTROLLERS_2023-24_M1.pptx
PPT
MICROPROCESSORS AND MICROCONTROLLERS8086 .ppt
PDF
Screenshot 2022-10-30 at 10.48.22 AM.pdf
PDF
Eee iv-microcontrollers [10 es42]-notes
PDF
Microprocessor and interfacing
PPTX
Introduction to Embedded Systems and Microcontrollers
Embedded Systems Syllabus
Microprocessors, Microcomputers and Assembly Language, Microprocessor Archit...
BEC405A_MICROCONTROLLERS_2023-24_M1.pptx
MICROPROCESSORS AND MICROCONTROLLERS8086 .ppt
Screenshot 2022-10-30 at 10.48.22 AM.pdf
Eee iv-microcontrollers [10 es42]-notes
Microprocessor and interfacing
Introduction to Embedded Systems and Microcontrollers

Similar to MC_module_3_2022.pdf (20)

PPTX
Introduction to Embedded Systems I: Chapter 2 (1st portion)
PDF
ECE_Embeded_Systems_Lecture_Notes of .pdf
DOC
Ankit sarin
DOCX
EEE INPLANT TRAINING IN CHENNAI-ELECTRICAL INPLANT TRAINING
DOCX
E&I INPLANT TRAINING-INSTRUMENTAION INPL;ANT TRAINING CHENNAI
DOCX
ECE INPLANT TRAINING IN EMBEDDED SYSTEMS CHENNAI
DOCX
INPLANT TRAINING IN CHENNAI-ROBOTICS/EMBEDDED SYSTEMS/PCB ASSEMBLING
DOCX
CSE INPLANT TRAINING FOR CSE/IT STUDENTS-CHENNAI MAASTECH
DOCX
INPLANT TRAINING IN ROBOTICS/EMBEDDED SYSTEMS/PCB DESIGNING/ORCAD
PPTX
ESD unit 1.pptx
PPTX
Microprocessor
PDF
8085 microprocessor notes
PDF
8085 microprocessor notes
PDF
Ee6008 mcbsd notes
PDF
EE6008 MBSD
PDF
EE6008 MCBSD - Introduction to PIC Micro controller
PDF
A STUDY OF AN ENTRENCHED SYSTEM USING INTERNET OF THINGS
PDF
IMPLEMENTATION OF USER INTERFACE FOR MICROPROCESSOR TRAINER
PPTX
Vinod ppt on es31 08 15
PPTX
Class 5 an 8 bit embedded platform
Introduction to Embedded Systems I: Chapter 2 (1st portion)
ECE_Embeded_Systems_Lecture_Notes of .pdf
Ankit sarin
EEE INPLANT TRAINING IN CHENNAI-ELECTRICAL INPLANT TRAINING
E&I INPLANT TRAINING-INSTRUMENTAION INPL;ANT TRAINING CHENNAI
ECE INPLANT TRAINING IN EMBEDDED SYSTEMS CHENNAI
INPLANT TRAINING IN CHENNAI-ROBOTICS/EMBEDDED SYSTEMS/PCB ASSEMBLING
CSE INPLANT TRAINING FOR CSE/IT STUDENTS-CHENNAI MAASTECH
INPLANT TRAINING IN ROBOTICS/EMBEDDED SYSTEMS/PCB DESIGNING/ORCAD
ESD unit 1.pptx
Microprocessor
8085 microprocessor notes
8085 microprocessor notes
Ee6008 mcbsd notes
EE6008 MBSD
EE6008 MCBSD - Introduction to PIC Micro controller
A STUDY OF AN ENTRENCHED SYSTEM USING INTERNET OF THINGS
IMPLEMENTATION OF USER INTERFACE FOR MICROPROCESSOR TRAINER
Vinod ppt on es31 08 15
Class 5 an 8 bit embedded platform
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
master seminar digital applications in india
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
01-Introduction-to-Information-Management.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
master seminar digital applications in india
Anesthesia in Laparoscopic Surgery in India
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Final Presentation General Medicine 03-08-2024.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
01-Introduction-to-Information-Management.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
RMMM.pdf make it easy to upload and study
What if we spent less time fighting change, and more time building what’s rig...
Paper A Mock Exam 9_ Attempt review.pdf.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Ad

MC_module_3_2022.pdf

  • 2. MC-Syllabus Module-1 ▪ Introduction to Microcontroller - Microprocessor and Microcontroller Characterization, Components of a Microcontroller, Microcontroller Architecture. • Main Characteristics of PIC Microcontrollers - Arithmetic and Logic Unit (ALU), Working Register in PIC Microcontrollers, Machine Cycles and Execution of Instructions, Pipelining for Instruction Execution, Oscillators, Configuration Bits, Reset Options, Low-Power Consumption Mode, Watchdog Timer, Program Counter,RISC, Compare Harvard architecture with von Neumann architecture. Module-2 ▪ Memory in Microcontrollers – Memory Organization, RAM, Data Memory, EEPROM, Flash Memory. • Instruction Set and Assembler Language Programming - Arithmetic Instructions, Logic and Compare instructions, Rotate Instruction and Data Serialization, Branch Instructions and Looping, Call Instructions and Stack •
  • 3. MC-Syllabus Module-3 ▪ Programming in C - Data Types and Time Delays, bit-addressable I/O, Logic Operations, Data Serialization, ROM & RAM Allocation Module-4 • Timers and Interrupts - Instruction Pipeline, Timers, The CCP Module, Interrupt, Examples of Timer and Interrupt Applications. • Parallel and Serial Communication – Parallel IO, Serial IO, advantages of serial communication over parallel, Streaming Parallel Port, USART, SPI, I2C Module-5 ▪ Sensors and Actuators - Interfacing LED, LCD, Keypad, ADC, DAC, Buzzer, Sensor, Relays, Stepper & DC Motor
  • 4. TEXT BOOKS: [1]Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009. [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf •
  • 5. REFERENCE BOOKS: • 1. Myke Predko, “Programming and Customizing the PIC Microcontroller”, Mc Graw Hill Education, 3rd Edition, 2008. • 2. John B. Peatman, “Design with PIC Microcontrollers”, Prentice Hall, 1997. • 3. Verle Milan, “PIC Microcontrollers – Programming in C”, Mikroelektronika, 1 st Edition, 2009 • For the Blended Learning 1. https://www.classcentral.com/course/swayam-microprocessors-and-microcontrollers-9894 2. https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf 3. https://circuitdigest.com/microcontroller-projects/writing-your-first-pic-microcontroller-program
  • 6. Module-3-PROGRAMMING IN C Data Types and Time Delays [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Why program a PIC18 in C programming language? ▪ Writing Programs in C are easier than in Assembly language programming(ALP). ▪ Easier to modify and update the program than Assembly language. ▪ C code is portable to other microcontrollers with no or little modifications compared to ALP. ▪ Codes available in function libraries can be used. ▪ But the hex file generated for C program is larger than the hex file generated for assembly language programming. [2]
  • 7. PROGRAMMING IN C Data Types and Time Delays [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data types [2] 1. Unsigned character: ▪ It is an 8 bit data type and can take values from 0-255(00-FFH) ▪ C compilers use signed char as default hence unsigned should be mentioned. ▪ Since int data types generate a large size hex files unsigned data types should be used instead. ▪ Eg. Used for counter values less than 256. [2]
  • 8. PROGRAMMING IN C Data Types and Time Delays [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data types [2] 2. signed character: ▪ It is an 8 bit data type uses D7bit used for the sign (-or+). ▪ 7 bits for magnitude giving values from -128 to+127. ▪ eg. Used for representing temperature (as temp can be + or -) [2]
  • 9. PROGRAMMING IN C Data Types and Time Delays [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data types [2] 3. unsigned int: ▪ It is an 16 bit data type and takes a value in the range 0 to 65,535 (0000H-FFFFH). ▪ eg. 16 bit unsigned int used to represent variables like memory address or counter values more than 256. ▪ Since unsigned int is 16 bit and most registers and RAM location in PIC18 are 8 bit long, use of unsigned int generates a large hex file. [2]
  • 10. PROGRAMMING IN C Data Types and Time Delays [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data types [2] 3. Signed int: ▪ It is an 16 bit data type and uses D15 (of D0-D15) bit to represent the sign . ▪ Has only 15 bits for magnitude. So can represent in the range -32,768- +32,767. ▪ eg.
  • 11. PROGRAMMING IN C Time Delays [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Two ways to generate time delays 1. A simple for loop: In c programing in creating a time delay using FOR loop, the accuracy of the delay program is affected by Compiler being used and Crystal oscillator connected to OSC1 - OSC2 2. Using timers of PIC18F4550 [2] [2]
  • 12. PROGRAMMING IN C Byte addressable I/O [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ➢ PIC18F 4550 has PORTA, PORTB, PORTC, PORTD, PORTE ➢ Each PORTx is associated with 3 registers. ➢ PORT, TRIS, LAT eg. PortB has PORTB, TRISB, LATB ➢ TRIS (data direction register)is an SFR used to make a PORT input or output port. At reset all the TRIS registers are FF i.e input port. ➢ PortA has 7 pins, PorTB,C,D has 8 pins and PORTE has 4pins ➢ PORT register reads levels on the device pins and when writes it writes to the output latch. ➢ LAT or data latch register used to read-modify-write on the values driven by the I/O Pins. [2] [2]
  • 13. PROGRAMMING IN C Byte addressable I/O [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ➢ PIC18F 4550 has PORTA, PORTB, PORTC, PORTD, PORTE ➢ Each PORTx is associated with 3 registers. ➢ PORT, TRIS, LAT eg. PortB has PORTB, TRISB, LATB ➢ TRIS (data direction register)is an SFR used to make a PORT input or output port. At reset all the TRIS registers are FF i.e input port. ➢ PortA has 7 pins, PorTB,C,D has 8 pins and PORTE has 4pins ➢ PORT register reads levels on the device pins and when writes it writes to the output latch. ➢ LAT or data latch register used to read-modify-write on the values driven by the I/O Pins. [2] [2]
  • 14. PROGRAMMING IN C Byte addressable I/O [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ➢ PIC18F 4550 has PORTA, PORTB, PORTC, PORTD, PORTE ➢ Each PORTx is associated with 3 registers. ➢ PORT, TRIS, LAT eg. PortB has PORTB, TRISB, LATB ➢ TRIS (data direction register)is an SFR used to make a PORT input or output port. At reset all the TRIS registers are FF i.e input port. ➢ PortA has 7 pins, PorTB,C,D has 8 pins and PORTE has 4pins ➢ PORT register reads levels on the device pins and when writes it writes to the output latch. ➢ LAT or data latch register used to read-modify-write on the values driven by the I/O Pins. [2]
  • 15. PROGRAMMING IN C Bit addressable I/O [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf [3] [3]
  • 16. PROGRAMMING IN C Bit addressable I/O [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Portxbits.Rxy ➢ Each bit (port pins) of the PORT can be accessed independently ➢ Portxbits.Rxy [2] [2]
  • 17. PROGRAMMING IN C Bit addressable I/O [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf [2]
  • 18. PROGRAMMING IN C Logic operators [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ➢ Ability to perform bitwise operation Bit-wise shift operation [2] [2]
  • 19. PROGRAMMING IN C Logic operators [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ➢ Ability to perform bitwise operation [2] [2]
  • 20. PROGRAMMING IN C Data Conversion in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ASCII to Unpacked BCD Packed BCD to ASCII ASCII to packed BCD [2] [2]
  • 21. PROGRAMMING IN C Data Conversion in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Checksum data in ROM: ➢ To check the integrity of the ROM data checksum calculation is done ➢ Checksum checks for corruption in ROM data. ➢ Corruption can happen due to current surge on turning on and off. ➢ Checksum bytes is tagged to the end of the series of data. Steps to calculate checksum data ➢ Add the bytes together drop the carries ➢ Take 2’s complement of result which is the checksum byte. ➢ Add the series of data with the checksum byte. If the addition is ‘0’ after dropping the carry the data is not corrupted otherwise it is corrupted. Example how checksum byte works is as follows [2] [2]
  • 22. PROGRAMMING IN C Data Conversion in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Checksum data in ROM: Program how checksum byte works is as follows [2] [2]
  • 23. PROGRAMMING IN C Data Conversion in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Binary (hex) to Decimal and ASIIC conversion in C [2]
  • 24. PROGRAMMING IN C Data Serialisation in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data serialization is way of sending byte of data one bit at a time from a single pin. TWO WAYs are ➢ Use of serial port. – Little control on the sequence of data being transferred. ➢ Data transfer one bit at a time and will have control on the sequence of data and space between them. Can be done using I2C and CAN but few devices do not support these standards. Hence data serialization using C is used. [2]
  • 25. PROGRAMMING IN C Data Serialisation in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data serialization is way of sending byte of data one bit at a time from a single pin. [2]
  • 26. PROGRAMMING IN C Data Serialisation in C programming [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data serialization is way of sending byte of data one bit at a time from a single pin. [2]
  • 27. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ROM allocation ➢ PIC 18 has maximum RAM capacity of 4K i.e from 000-FFFH ➢ PIC 18 has maximum ROM capacity of 2M i.e from 000000-1FFFFFH ➢ PIC18F4550 has maximum RAM capacity of 2K ➢ PIC18F4550 has maximum ROM capacity of 32K ➢ In assembly TBLRD instruction to access the program ROM for the purpose of data ➢ C18 compiler also uses ROM space for storing data [2] [2]
  • 28. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ROM allocation: ➢ Allocating Program space to fixed data ➢ The keyword used is rom [2] [2]
  • 29. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ROM allocation: Near and Far storage qualifier ➢ Indicates what region the data and code should be placed ➢ Near qualifier will allocate data in the first 64KB of ROM location ➢ Far qualifier will allocate data variable within the entire 2MB of ROM Example of near storage qualifier [2]
  • 30. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ROM allocation: Near and Far storage qualifier ➢ Indicates what region the data and code should be placed ➢ Near qualifier will allocate data in the first 64KB of ROM location (for general PIC18) ➢ Far qualifier will allocate data variable within the entire 2MB of ROM(for general PIC18) Example of Far storage qualifier [2] [2]
  • 31. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ROM allocation: Using pragma directive to allocate fixed location ➢ Like ORG directive in assembly C18 compilers use pragma directive to allocate fixed location [A] Putting code in specific ROM location [2] [2]
  • 32. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ROM allocation: Using pragma directive to allocate fixed location to data and code ➢ Like ORG directive in assembly C18 compilers use pragma directive to allocate fixed location [B] Putting data in specific ROM location [2]
  • 33. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data RAM allocation in C18: PIC18 has 2K of RAM [2] [2]
  • 34. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data RAM allocation in C18: PIC18 has 2K of RAM Near Far Storage qualifier Example of near qualifier Example of far qualifier [2] [2]
  • 35. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf Data RAM allocation in C18: PIC18 has 2K of RAM Putting data in a specific RAM Address using pragma directive ➢ Two options for pragma directive are 1. idata – initialised data 2. udata – uninitialized data [2] [2]
  • 36. PROGRAMMING IN C ROM & RAM Allocation [2,3] [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf ➢ Overlay storage data: Two different variables can be allocated same address location provided the two variable's are not being used at the same time. Example of allocation of same location to two independent variables. Example of allocation of different location to two dependent variables. [2] [2]
  • 37. References and disclaimer The contents (pictures, text and programs) of the above slides have been adapted from the following references (mainly reference 2). It is only meant as a students’ reference for the course 16EC2403 – microcontroller and not intended to be published. [1] Fernando E. Valdes-Perez, Ramon Pallas-Areny, “Microcontrollers - Fundamentals and Applications with PIC”, CRC Press, 1st Edition, 2009 [2] Mazidi M. A., McKinlay R. D., Causey D., “PIC Microcontroller And Embedded Systems.”, using assembly and C for PIC18, Pearson Education International, 2008 [3] https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf [4] https://www.youtube.com/watch?v=Xl2nWDcy0To [5] https://www.youtube.com/watch?v=DmwOSdwzZ3E [6] D.V Hall, Microprocessors and Interfacing”,TATA MCGRAW HILL, revised 2nd edition