<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//index.php?action=history&amp;feed=atom&amp;title=C_Example%3A_Comparators</id>
	<title>C Example: Comparators - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//index.php?action=history&amp;feed=atom&amp;title=C_Example%3A_Comparators"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=C_Example:_Comparators&amp;action=history"/>
	<updated>2026-05-14T22:09:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=C_Example:_Comparators&amp;diff=4967&amp;oldid=prev</id>
		<title>LIMS at 20:50, 25 June 2007</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=C_Example:_Comparators&amp;diff=4967&amp;oldid=prev"/>
		<updated>2007-06-25T20:50:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
==Code==&lt;br /&gt;
Program to implement an analog comparator.&lt;br /&gt;
&lt;br /&gt;
First include header file with definitions for specific PIC.&lt;br /&gt;
Set fuses.  HS is type of external clock, low voltage protection&lt;br /&gt;
(LVP) is off, and the watchdog timer (WDT) is off.&lt;br /&gt;
External clock frequency of 20 MHz is specified.&lt;br /&gt;
&lt;br /&gt;
   #include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
   #fuses HS,NOWDT,NOPROTECT,NOLVP&lt;br /&gt;
   #use delay(clock=20000000)&lt;br /&gt;
&lt;br /&gt;
Begin main body of program.&lt;br /&gt;
&lt;br /&gt;
   void main(void) {&lt;br /&gt;
&lt;br /&gt;
Setup the comparators C1 and C2.  A0 is C1- and A3 is C1+. If C1+ &amp;gt; C1-&lt;br /&gt;
C1 will output high (C1OUT = 1 = 5V).  If C1- &amp;gt; C1+ C1 will output low.&lt;br /&gt;
A second comparator (C2) has been set up, but is not being utilized.&lt;br /&gt;
See the header file 18F4520.h for all possible constants used in the&lt;br /&gt;
setup_comparator() function.&lt;br /&gt;
&lt;br /&gt;
      setup_comparator(A0_A3_A1_A2);&lt;br /&gt;
&lt;br /&gt;
Setup an infinite loop using a while statement.&lt;br /&gt;
&lt;br /&gt;
      while(TRUE) {&lt;br /&gt;
&lt;br /&gt;
Check the output of the comparator and light an LED accordingly.&lt;br /&gt;
&lt;br /&gt;
         if(C1OUT){&lt;br /&gt;
            output_low(PIN_D0);}&lt;br /&gt;
         else{&lt;br /&gt;
            output_high(PIN_D0);}&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
==Associated Circuitry==&lt;/div&gt;</summary>
		<author><name>LIMS</name></author>
	</entry>
</feed>