Professional Documents
Culture Documents
8-Comparator-Assembler Block
8-Comparator-Assembler Block
Microcontrollers
1
COMPARATOR MODULE
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
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
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
#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