Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

COMPARATOR MODULE

Microcontrollers

1
COMPARATOR MODULE

• The comparator module contains two analog compara-


• tors.
• The inputs to the comparators are multiplexed with I/O
port pins RA0 through RA3, while the outputs are
multiplexed to pins RA4 and RA5.
Microcontrollers

• The on-chip voltage reference can also be an input to


the comparators.
COMPARATOR I/O OPERATING
MODES
Microcontrollers

3
COMPARATOR I/O OPERATING
MODES
Microcontrollers

4
SINGLE COMPARATOR
Microcontrollers

5
COMPARATOR VOLTAGE
REFERENCE MODULE
COMPARATOR VOLTAGE REFERENCE BLOCK DIAGRAM
Microcontrollers

6
COMPARATOR VOLTAGE
REFERENCE MODULE
Microcontrollers

7
COMPARATOR VOLTAGE
REFERENCE MODULE
#include <16F877a.h>
#fuses XT,WDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1)
main() {
delay_ms(1000); putc(254); putc(1); delay_ms(10); printf("Voltage test"); delay_ms(1000);
setup_comparator(A0_VR_A1_VR); setup_vref(VREF_HIGH|15);
Microcontrollers

while(TRUE) {
putc(254); putc(1); delay_ms(10);
if(C1OUT){
printf("Below 3.6 V."); delay_ms(1000);
}
else{
printf("Above 3.6 V."); delay_ms(1000);
}
}
} 8
PIC16 C Assembler
Routines
● Reasons for using assembly
language
● Insertion of assembler sequence
● Overview of assembly language
Microcontrollers

9
Reasons for using
assembly language
• The default programming language of any
microprocessor or microcontroller is its own assembly
language.
• Assembly language is the first-level abstraction from
machine code, where each instruction is represented by
Microcontrollers

a corresponding text mnemonic.


• When compiled, a C program is converted into
assembler, then to machine code.

10
C Code Fragment for
Pulse Output Loop
#include "16F877a.h" // MCU header file
void main() // Main block start
{
while(1)
Microcontrollers

{ output_high(PIN_D0);
output_low(PIN_D0);
}
}
11
Disassembled Code for
Pulse Output Loop
Microcontrollers

12
Assembler Block
• The start of the assembler block is
identified by the #asm directive and
terminated with #endasm .
Microcontrollers

• All the code between these points must


conform to the PIC assembler syntax

13
Assembler Block
#include "16F877A.h"
#use delay(clock=4000000)
#int_ext
void isrext()
{ output_low(PIN_D0); delay_ms(100); while(input(PIN_B0));
}
void main()
{
Microcontrollers

enable_interrupts(int_ext); enable_interrupts(global); ext_int_edge(L_TO_H);

#asm

Start:
BSF 8,0
BCF 8,0
GOTO Start
#endasm

} 14
Assembler Block
Microcontrollers

15
C Code
#include "16F877A.h"
#use delay(clock=4000000)

#int_ext
void isrext()
{ output_low(PIN_D0); delay_ms(100); while(input(PIN_B0));
}
Microcontrollers

void main() {
enable_interrupts(int_ext); enable_interrupts(global); ext_int_edge(L_TO_H);

while(1)
{ output_high(PIN_D0);
output_low(PIN_D0);
}
}
16
Microcontrollers

C Code

17

You might also like