SlideShare a Scribd company logo
CONFIGURING
ON-CHIP ADC
ON PIC 16F877
By
GAURAV .M. RAIKAR
Roll No: EL-18-
PIC MICROCONTROLLER
PIC (Peripheral Interface Controller ) is family of microcontrollers made by
“Microchip Technology”.
PIC microcontrollers are very fast and executing a program is easier compared to
other controllers. It follows “Harvard architecture” for internal data transfer. Its
architecture comprises of CPU, RAM, ROM, timers, counters and protocols like
SPI, UART, CAN which are used for interfacing with other peripherals. .
PIC are small microcontroller that can be programmed to carry out a vast range of
tasks. The programming and the simulation process of this microcontroller can be
done using MP-LAB software.
Even though there are many types of PIC microcontrollers , the most widely used
and basic microcontroller is PIC16F877.
PIC 16F877 :FEATURES
8 bit microcontroller
8k x 14 words of flash program memory.
368 x 8 bytes of data memory(RAM).
256 x 8 bytes of EEPROM data memory.
20MHz operating speed (200 ns instruction
cycle).
Wide operating voltage range(2.0-5.6)volts.
High Sink/Source current, about 25mA.
Package options(40 or 44 pins).
High performance RISC CPU.
35 simple word Instructions.
Support for 14 interrupts.
Supports different types of addressing modes.
Power up timer(PWRT).
3 timers (Multiple modes 8 bit,16 bit support).
10 bit multi-channel Analog to digital convertor (10 bit
resolution)..
Universal synchronous asynchronous receiver transmitter
(USART).
Supports for I2C.
Supports SPI.
Brown out reset(BOR).
Watch dog timer.
PIC microcontroller types
Instruction set for PIC 16F877(35 instructions)
PIC 16F877 of Architecture
Program Memory:
• This is a 8K*14 memory space.
• It contains the programs that are written
by the user.
• The program memory data is accessed
by the 13 bit program counter register
that holds the address of the program
memory.
• The address 0000H is used as reset
memory space and 0004H is used as
interrupt memory space.
The PIC 16F877 consists of 3 memories:
Program memory , Data memory and Data EEPROM.
• Data Memory: The data memory
consists of the 368 bytes of RAM
and 256 bytes of EEPROM.
• The Data Memory consists of
multiple banks.
• Each bank consists of general
purpose registers and special
function registers.
• The special function registers
consists of control registers to
control different operations of the
chip resources like Timers, Analog
to Digital Converters, Serial ports,
I/O ports, etc.
• Data EEPROM (Electrically Erasable Programmable Read-Only
Memory) - Data EEPROM they are non-volatile memories, which store the
information even after the power is turn off. These memories called Flash Or
EEPROM.
• The general purpose registers -consists of registers that are used to store
temporary data and processing results of the data. These general purpose registers
are each 8-bit registers.
• Working Register -It consists of a memory space that stores the operands for
each instruction. It also stores the results of each execution.
• File Selection Register- It acts as a pointer to any other general-purpose
register. It consists of a register file address, and it is used in indirect addressing.
• Program-counter register- It is a 13-bit register. The 5 upper bits are used as
PCLATH (Program Counter Latch) to independently function as any other
register, and the lower 8-bits are used as the program counter bits. The program
counter acts as a pointer to the instructions stored in the program memory.
• Status Register: The bits of the status register denote the status of the ALU (arithmetic logic unit) after every
execution of the instruction. It is also used to select any one of the 4 banks of the RAM.
IRP - Register Bank Select bit, used for indirect addressing method.
When the IRP Equal to 0, the program will work with banks 0, 1.
When the IRP Equal to 1, the program will work with banks 2, 3.
RP1:RP0: - Register Bank Select bits, used for direct addressing method
selection of the RP0 and RP1 bits helps in selecting one of the 4 banks.
C: Carry/borrow bit
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
DC: Digit carry/borrow bit (for borrow, the polarity is reversed)
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
PD: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
TO: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
• Power on Reset- The task of POR is ensuring that the processor starts at
known address when power is first on, the reset function will set the PC to
starting address.
• Power up timer- A special timer that delay the start of program execution
after the PIC has been reset on power.
• Brown out Reset(BOR)- when the power supply drops below certain
voltage(4v in case of PIC),it causes PIC to reset.
• Watch Dog Timer(WDT)- A simple timer circuit that performs specific
operation after a certain period of time if something goes wrong
• In Circuit Debugger(ICD)- with the ICD we can watch our program run in
the chip/module and find any bugs or programming mistakes as they happen
Register Description
ADCON0 - ADC Control Register 0 Control the operation of A/D module
ADCON1 -ADC Control Register 1 Used to configure the GPIO pins for ADC.
Determines the configuration of the PORT A
and PORT E
ADRESH -ADC Result High Register Holds the higher byte of ADC result
ADRESL -ADC Result low Register Holds the lower byte of ADC result
ADC Registers
The A/D module has four 8 bit registers:
ADCON0
ADCON0
bit7 6 5 4 3 2 1 bit0
ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON
• ADCS1 and ADCS2 are used to select A/D Conversion Clock . It should be selected in accordance with device clock.
• CHS2, CHS1 and CHS0 are used to select one of the Analog input channel out of eight channels.
• CHS2-CHS0: Analog Channel Select bits
000 = Channel 0 (AN0/RA0)
001 = Channel 1 (AN1/RA1)
010 = Channel 2 (AN2/RA2)
011 = Channel 3 (AN3/RA3)
100 = Channel 4 (AN4/RA5)
101 = Channel 5 (AN5/RE0)
110 = Channel 6 (AN6/RE1)
111 = Channel 7 (AN7/RE2)
• GO/DONE is the A/D Conversion Status bit. Setting this bit initializes A/D Conversion and will be automatically
cleared when the conversion is complete.
• ADON is used to switch on/off the ADC Module. When it is 1, the ADC Module turns ON and when it is 0, the ADC
Module will be OFF.
ADCON1
ADCON1
7 6 5 4 3 2 1 0
ADFM — — — PCFG3 PCFG2 PCFG1 PCFG0
• ADFM - ADC Result Format select bit. Two 8 bit
register (ADRESH and ADRESL) are provided to store the
10-bit result of A/D Conversion. When ADFM is 1, the
result will be right justified, i.e. Most Significant Bits of
ADRESH will be read as 0. When ADFM is 0, the result
will be left justified, i.e. Least Significant Bits of ADRESL
will be read as zero.
• PCFG3 – PCFG0 are the A/D “Port Configuration
Control bits”. Each pin among AN0 – AN7 is configured
as analog , digital or reference voltage inputs according to
the status of these configuration bits as given below.
1. Configure the A/D module:
• Configure analog pins/voltage reference and digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADON bit of ADCON0)
2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE ,PEIE ,GIE bit
3. Wait the required acquisition time.
4. Start conversion:
• Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared(with interrupts enabled); OR
• Waiting for the A/D interrupt
6. Read A/D result register pair (ADRESH:ADRESL), clear bit ADIF if required.
7. For the next conversion, go to step 1 or step 2, as required.
Steps for A/D conversion
A/D conversion timing Diagram
Flowchart
Start
Configure ADC module
Set ADC clock
Select Channel
Start Conversion
Display Result
Is
conversion
complete
No
YE
SRead ADC Result
#include<16f877.h>
#use delay(clock=20000000)
#use rs232(baud=19200,xmit=pin_c6,rcv=pin_c7)
int adc_data;
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(1)
{
adc_data = read_adc();
printf("nr ADC %d ",adc_data);
}
}
On-Chip ADC program
THANK
YOU

More Related Content

What's hot

ARM Processor
ARM ProcessorARM Processor
ARM Processor
Aniket Thakur
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
Gaurav Verma
 
Unit V:Motorola 563xx
Unit V:Motorola 563xxUnit V:Motorola 563xx
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Introduction to MPLAB IDE
Introduction to MPLAB IDEIntroduction to MPLAB IDE
Introduction to MPLAB IDE
Karim El-Rayes
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
Jamia Hamdard
 
Unit4.addressing modes 54 xx
Unit4.addressing modes 54 xxUnit4.addressing modes 54 xx
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
RAMPRAKASHT1
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
Sudhanshu Janwadkar
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
Pantech ProLabs India Pvt Ltd
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
Gaurav Verma
 
ARM stacks, subroutines, Cortex M3, LPC 214X
ARM  stacks, subroutines, Cortex M3, LPC 214XARM  stacks, subroutines, Cortex M3, LPC 214X
ARM stacks, subroutines, Cortex M3, LPC 214X
Karthik Vivek
 
The 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systemsThe 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systems
manishpatel_79
 
Memory interfacing
Memory interfacingMemory interfacing
Memory interfacing
mahalakshmimalini
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
Nikhil Sharma
 
Memory Interface
Memory InterfaceMemory Interface
Memory Interface
Sweetlinrose
 
Microprocessor & Micro-controller
Microprocessor & Micro-controllerMicroprocessor & Micro-controller
Microprocessor & Micro-controller
Om Bheda
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
Abdullah Saghir Ahmad
 
16bit RISC Processor
16bit RISC Processor16bit RISC Processor
16bit RISC Processor
Shashi Suman
 

What's hot (20)

ARM Processor
ARM ProcessorARM Processor
ARM Processor
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Unit V:Motorola 563xx
Unit V:Motorola 563xxUnit V:Motorola 563xx
Unit V:Motorola 563xx
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Introduction to MPLAB IDE
Introduction to MPLAB IDEIntroduction to MPLAB IDE
Introduction to MPLAB IDE
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Unit4.addressing modes 54 xx
Unit4.addressing modes 54 xxUnit4.addressing modes 54 xx
Unit4.addressing modes 54 xx
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
ARM stacks, subroutines, Cortex M3, LPC 214X
ARM  stacks, subroutines, Cortex M3, LPC 214XARM  stacks, subroutines, Cortex M3, LPC 214X
ARM stacks, subroutines, Cortex M3, LPC 214X
 
The 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systemsThe 8051 microcontroler based embedded systems
The 8051 microcontroler based embedded systems
 
Memory interfacing
Memory interfacingMemory interfacing
Memory interfacing
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
 
Memory Interface
Memory InterfaceMemory Interface
Memory Interface
 
Microprocessor & Micro-controller
Microprocessor & Micro-controllerMicroprocessor & Micro-controller
Microprocessor & Micro-controller
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
8255
82558255
8255
 
16bit RISC Processor
16bit RISC Processor16bit RISC Processor
16bit RISC Processor
 

Similar to PIC 16F877 micro controller by Gaurav raikar

Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
Anbuselvi Mathivanan
 
Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.ppt
AakashRawat35
 
Avr report
Avr reportAvr report
Avr report
NITISH KUMAR
 
Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]gauravholani
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copymkazree
 
digital clock atmega16
digital clock atmega16digital clock atmega16
digital clock atmega16
Arcanjo Salazaku
 
Overview of Microcontroller and ATMega32 microcontroller
Overview of Microcontroller and ATMega32 microcontrollerOverview of Microcontroller and ATMega32 microcontroller
Overview of Microcontroller and ATMega32 microcontroller
Rup Chowdhury
 
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080Vivek Venugopal
 
8085 microprocessor architecture
8085 microprocessor architecture8085 microprocessor architecture
8085 microprocessor architecture
Arashdeepkaur16
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
OsaMa Hasan
 
Presentation
PresentationPresentation
Presentation
Abhijit Das
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
KanchanThory
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
Siva Kumar
 
MPMC
MPMC MPMC
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheetAtmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
sang2792
 
Atmega16
Atmega16Atmega16
Atmega16
Thrived Kumar
 
Design and Fabrication of 4-bit processor
Design and Fabrication of  4-bit processorDesign and Fabrication of  4-bit processor
Design and Fabrication of 4-bit processor
Priyatham Bollimpalli
 
janakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiraman I msc 4 unit
janakiraman I msc 4 unit
janakiramang6
 

Similar to PIC 16F877 micro controller by Gaurav raikar (20)

Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 
Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.ppt
 
Avr report
Avr reportAvr report
Avr report
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
 
digital clock atmega16
digital clock atmega16digital clock atmega16
digital clock atmega16
 
Overview of Microcontroller and ATMega32 microcontroller
Overview of Microcontroller and ATMega32 microcontrollerOverview of Microcontroller and ATMega32 microcontroller
Overview of Microcontroller and ATMega32 microcontroller
 
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
 
8085 microprocessor architecture
8085 microprocessor architecture8085 microprocessor architecture
8085 microprocessor architecture
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
 
Presentation
PresentationPresentation
Presentation
 
unit-2.pptx
unit-2.pptxunit-2.pptx
unit-2.pptx
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
 
MPMC
MPMC MPMC
MPMC
 
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheetAtmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
Atmel 2486-8-bit-avr-microcontroller-atmega8 l-datasheet
 
Atmega16
Atmega16Atmega16
Atmega16
 
Design and Fabrication of 4-bit processor
Design and Fabrication of  4-bit processorDesign and Fabrication of  4-bit processor
Design and Fabrication of 4-bit processor
 
janakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiraman I msc 4 unit
janakiraman I msc 4 unit
 
12 mt06ped001
12 mt06ped001 12 mt06ped001
12 mt06ped001
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 

Recently uploaded (20)

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 

PIC 16F877 micro controller by Gaurav raikar

  • 1. CONFIGURING ON-CHIP ADC ON PIC 16F877 By GAURAV .M. RAIKAR Roll No: EL-18-
  • 2. PIC MICROCONTROLLER PIC (Peripheral Interface Controller ) is family of microcontrollers made by “Microchip Technology”. PIC microcontrollers are very fast and executing a program is easier compared to other controllers. It follows “Harvard architecture” for internal data transfer. Its architecture comprises of CPU, RAM, ROM, timers, counters and protocols like SPI, UART, CAN which are used for interfacing with other peripherals. . PIC are small microcontroller that can be programmed to carry out a vast range of tasks. The programming and the simulation process of this microcontroller can be done using MP-LAB software. Even though there are many types of PIC microcontrollers , the most widely used and basic microcontroller is PIC16F877.
  • 3. PIC 16F877 :FEATURES 8 bit microcontroller 8k x 14 words of flash program memory. 368 x 8 bytes of data memory(RAM). 256 x 8 bytes of EEPROM data memory. 20MHz operating speed (200 ns instruction cycle). Wide operating voltage range(2.0-5.6)volts. High Sink/Source current, about 25mA. Package options(40 or 44 pins). High performance RISC CPU. 35 simple word Instructions. Support for 14 interrupts. Supports different types of addressing modes. Power up timer(PWRT). 3 timers (Multiple modes 8 bit,16 bit support). 10 bit multi-channel Analog to digital convertor (10 bit resolution).. Universal synchronous asynchronous receiver transmitter (USART). Supports for I2C. Supports SPI. Brown out reset(BOR). Watch dog timer.
  • 5. Instruction set for PIC 16F877(35 instructions)
  • 6. PIC 16F877 of Architecture
  • 7. Program Memory: • This is a 8K*14 memory space. • It contains the programs that are written by the user. • The program memory data is accessed by the 13 bit program counter register that holds the address of the program memory. • The address 0000H is used as reset memory space and 0004H is used as interrupt memory space. The PIC 16F877 consists of 3 memories: Program memory , Data memory and Data EEPROM.
  • 8. • Data Memory: The data memory consists of the 368 bytes of RAM and 256 bytes of EEPROM. • The Data Memory consists of multiple banks. • Each bank consists of general purpose registers and special function registers. • The special function registers consists of control registers to control different operations of the chip resources like Timers, Analog to Digital Converters, Serial ports, I/O ports, etc.
  • 9. • Data EEPROM (Electrically Erasable Programmable Read-Only Memory) - Data EEPROM they are non-volatile memories, which store the information even after the power is turn off. These memories called Flash Or EEPROM. • The general purpose registers -consists of registers that are used to store temporary data and processing results of the data. These general purpose registers are each 8-bit registers. • Working Register -It consists of a memory space that stores the operands for each instruction. It also stores the results of each execution. • File Selection Register- It acts as a pointer to any other general-purpose register. It consists of a register file address, and it is used in indirect addressing. • Program-counter register- It is a 13-bit register. The 5 upper bits are used as PCLATH (Program Counter Latch) to independently function as any other register, and the lower 8-bits are used as the program counter bits. The program counter acts as a pointer to the instructions stored in the program memory.
  • 10. • Status Register: The bits of the status register denote the status of the ALU (arithmetic logic unit) after every execution of the instruction. It is also used to select any one of the 4 banks of the RAM. IRP - Register Bank Select bit, used for indirect addressing method. When the IRP Equal to 0, the program will work with banks 0, 1. When the IRP Equal to 1, the program will work with banks 2, 3. RP1:RP0: - Register Bank Select bits, used for direct addressing method selection of the RP0 and RP1 bits helps in selecting one of the 4 banks. C: Carry/borrow bit 1 = A carry-out from the Most Significant bit of the result occurred 0 = No carry-out from the Most Significant bit of the result occurred DC: Digit carry/borrow bit (for borrow, the polarity is reversed) 1 = A carry-out from the 4th low order bit of the result occurred 0 = No carry-out from the 4th low order bit of the result Z: Zero bit 1 = The result of an arithmetic or logic operation is zero 0 = The result of an arithmetic or logic operation is not zero PD: Power-down bit 1 = After power-up or by the CLRWDT instruction 0 = By execution of the SLEEP instruction TO: Time-out bit 1 = After power-up, CLRWDT instruction or SLEEP instruction 0 = A WDT time-out occurred
  • 11. • Power on Reset- The task of POR is ensuring that the processor starts at known address when power is first on, the reset function will set the PC to starting address. • Power up timer- A special timer that delay the start of program execution after the PIC has been reset on power. • Brown out Reset(BOR)- when the power supply drops below certain voltage(4v in case of PIC),it causes PIC to reset. • Watch Dog Timer(WDT)- A simple timer circuit that performs specific operation after a certain period of time if something goes wrong • In Circuit Debugger(ICD)- with the ICD we can watch our program run in the chip/module and find any bugs or programming mistakes as they happen
  • 12.
  • 13. Register Description ADCON0 - ADC Control Register 0 Control the operation of A/D module ADCON1 -ADC Control Register 1 Used to configure the GPIO pins for ADC. Determines the configuration of the PORT A and PORT E ADRESH -ADC Result High Register Holds the higher byte of ADC result ADRESL -ADC Result low Register Holds the lower byte of ADC result ADC Registers The A/D module has four 8 bit registers:
  • 14. ADCON0 ADCON0 bit7 6 5 4 3 2 1 bit0 ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON • ADCS1 and ADCS2 are used to select A/D Conversion Clock . It should be selected in accordance with device clock. • CHS2, CHS1 and CHS0 are used to select one of the Analog input channel out of eight channels. • CHS2-CHS0: Analog Channel Select bits 000 = Channel 0 (AN0/RA0) 001 = Channel 1 (AN1/RA1) 010 = Channel 2 (AN2/RA2) 011 = Channel 3 (AN3/RA3) 100 = Channel 4 (AN4/RA5) 101 = Channel 5 (AN5/RE0) 110 = Channel 6 (AN6/RE1) 111 = Channel 7 (AN7/RE2) • GO/DONE is the A/D Conversion Status bit. Setting this bit initializes A/D Conversion and will be automatically cleared when the conversion is complete. • ADON is used to switch on/off the ADC Module. When it is 1, the ADC Module turns ON and when it is 0, the ADC Module will be OFF.
  • 15. ADCON1 ADCON1 7 6 5 4 3 2 1 0 ADFM — — — PCFG3 PCFG2 PCFG1 PCFG0 • ADFM - ADC Result Format select bit. Two 8 bit register (ADRESH and ADRESL) are provided to store the 10-bit result of A/D Conversion. When ADFM is 1, the result will be right justified, i.e. Most Significant Bits of ADRESH will be read as 0. When ADFM is 0, the result will be left justified, i.e. Least Significant Bits of ADRESL will be read as zero. • PCFG3 – PCFG0 are the A/D “Port Configuration Control bits”. Each pin among AN0 – AN7 is configured as analog , digital or reference voltage inputs according to the status of these configuration bits as given below.
  • 16. 1. Configure the A/D module: • Configure analog pins/voltage reference and digital I/O (ADCON1) • Select A/D input channel (ADCON0) • Select A/D conversion clock (ADCON0) • Turn on A/D module (ADON bit of ADCON0) 2. Configure A/D interrupt (if desired): • Clear ADIF bit • Set ADIE ,PEIE ,GIE bit 3. Wait the required acquisition time. 4. Start conversion: • Set GO/DONE bit (ADCON0) 5. Wait for A/D conversion to complete, by either: • Polling for the GO/DONE bit to be cleared(with interrupts enabled); OR • Waiting for the A/D interrupt 6. Read A/D result register pair (ADRESH:ADRESL), clear bit ADIF if required. 7. For the next conversion, go to step 1 or step 2, as required. Steps for A/D conversion
  • 18. Flowchart Start Configure ADC module Set ADC clock Select Channel Start Conversion Display Result Is conversion complete No YE SRead ADC Result
  • 19. #include<16f877.h> #use delay(clock=20000000) #use rs232(baud=19200,xmit=pin_c6,rcv=pin_c7) int adc_data; void main() { setup_adc_ports(ALL_ANALOG); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); while(1) { adc_data = read_adc(); printf("nr ADC %d ",adc_data); } } On-Chip ADC program