<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6503816347236610996</id><updated>2026-03-23T16:36:37.074-07:00</updated><category term="Proteus"/><category term="ARES"/><category term="Button"/><category term="Delay"/><category term="Device Symbol"/><category term="Heterogeneous"/><category term="ISIS"/><category term="Input"/><category term="LED"/><category term="LOGO"/><category term="Merge"/><category term="Multi-element"/><category term="PCB"/><category term="PIC18"/><category term="Panelization"/><category term="SIMULATION"/><category term="Timer"/><title type='text'>Embedded Electronics Blog</title><subtitle type='html'>Learn | DIY | Understand</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6503816347236610996.post-8099680714562790304</id><published>2013-09-04T14:16:00.000-07:00</published><updated>2013-09-04T14:18:17.995-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Delay"/><category scheme="http://www.blogger.com/atom/ns#" term="Timer"/><title type='text'>Using PIC18 Timer Module for delay – C Code with Proteus Simulation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6iew_wocksCLV5sxAw8u99lWpqYmtHoTP4ziqDsbTcOiB0EE7RyW7UJvbQ8KyN4ZoFwHi5X5MIv1hVON-QfqWVDpP7nWK-8JOCAeo-U65TVKuZVZ8rNL9Qz91SlCsty_hjKIYl65pnQYA/s1600-h/title_image15.png&quot;&gt;&lt;img alt=&quot;title_image&quot; border=&quot;0&quot; height=&quot;403&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFRlGCgvrp-gp63ZjENlEkaoQvNCzgWGGPqNmYGULE2CiyzU4Dv6GwhRtbQGrmHpmJ2ZSB7cpz_cE7Ngm_jepsWSIZTF5evusKwHv5sZ2E8VTXc1ziYTs5UyEr7MKzwbJ9rSVC5bIebuHz//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;title_image&quot; width=&quot;564&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
In our LED Blinking tutorial we used the PIC18 library function for delay which doesn’t use timer for delay. The built-in function we used for delay just insert’s NOP instruction to obtain the required delay. Today we will use the PIC18’s Timer Module to obtain the delay for&amp;nbsp; LED Blinking Example. &lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Introduction to PIC18 Timers&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
The number of timers a PIC18 has depends on its family. They ranges from 2 to 5 in PIC18. PIC18 Timers can be used as timers to generate delays or as counters. In the counter mode it is used to count events which occur outside of the Microcontroller. PIC18 Timers are referred by the names Timer0, Timer1, Timer3, and so on. In our Example Program we will be using Timer0 in timer mode to obtain the required delay. Timer can be 8-bit, 16-bit or even 32-bit on some newest PICs. In the PIC18F8722 Timer0 can be used in 8-bit or 16-bit mode selectable via software. In the 8-bit mode the timer increments an 8-bit register on each clock cycle and ranges from 0 – 255 while in 16-bit mode the range is 0 – 65535. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Timer Clock Source&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
A Timer or any other Microcontroller peripheral requires clock source for its operation referred to as the Peripheral Clock. The clock can be internal or external. In the internal clock mode Timer0 operates as timer and uses the internal(FCPU) clock with or without pre-scalar. Pre-Scalar is an integer value which divides the CPU clock to give Timer Clock i.e &lt;strong&gt;&lt;em&gt;Timer Clock = FCPU/pre-scalar&lt;/em&gt;.&lt;/strong&gt;&amp;nbsp; When the Pre-scalar is set to one or bypassed then the timer runs on the same clock as the CPU is running. In the external clock mode Timer0 operates as counter and counts on every rising or falling edge of the clock connected to the Timer&#39;s clock pin. In this example we will be using Timer0 with the internal clock(timer mode) configuration and pre-scalar bypassed or 1. T0CON – Timer0 Control Register is used to control all these settings, details can be found in the Timer0 Module section of the &lt;a href=&quot;http://ww1.microchip.com/downloads/en/devicedoc/39646c.pdf&quot; target=&quot;_blank&quot;&gt;datasheet&lt;/a&gt;. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Difference Between FOSC and FCPU&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Oscillator Frequency (FOSC) is the frequency of the crystal we have connected to the PIC. in our case we are using 20MHz crystal so &lt;strong&gt;FOSC = 20MHz. &lt;/strong&gt;The PIC internally divides FOSC by 4 to get FCPU. Based on this we have clock cycle and instruction cycle. the clock cycle is simply 1/FOSC while instruction cycle is 1/FCPU. An instruction cycle is the time required for the PIC to execute a single assembly language instruction( excluding jump and loop instructions which requires more than on instruction cycles). &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Delay Calculation&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
After initializing Timer0 in 8-bit mode with internal clock by setting the relevant bits in &lt;strong&gt;T0CON&lt;/strong&gt; Register we turn on the Timer. As the Timer is turned on it increments the &lt;strong&gt;TMR0&lt;/strong&gt; register every clock cycle starting from 0. What happens when it reaches 255? glad you asked. PIC18 has the ability to generate interrupt on overflow – meaning that a&amp;nbsp; bit called Timer0 Interrupt Flag(TMR0IF) which is set when TMR0 makes&amp;nbsp; transition from 255 to 0. We can check TMR0IF either by polling or using Interrupt Service Routine(ISR). In this example we will used polling method and will cover Interrupts in another post.&amp;nbsp; &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Assuming the PIC is operating with FOSC = 20MHz or FCPU = 5MHz, a single overflow of Timer0 will give us 256 * 1/5MHz = 51.2usec delay. So if we need delay more than 51.2usec we maintain a counter and increment it each time Timer0 overflows. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;strong&gt;For a delay of 1sec&lt;/strong&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
1sec = 10^6usec the timer overflows after 51.2usec So number of TImer0 overflows required to get a 1sec delay can be calculated as 10^6/51.2 = 19531.25 rounded to 19531 will give approximately 1sec delay.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
So after starting Timer0 we poll for TMR0IF if set a variable called &lt;em&gt;counter&lt;/em&gt; is incremented. The &lt;em&gt;counter&lt;/em&gt; value is compared to 19531 if equal it means approximately 1sec is elapsed and an LED toggles to indicate this. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
C Code&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Below is the C code for this example with comments, copy it and generate the hex file for Proteus simulation. &lt;/div&gt;
&lt;div id=&quot;codeSnippetWrapper&quot; style=&quot;background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;&quot;&gt;
&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/* &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   ################################################################################ &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   **** PIC18 Timer Example&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   **** IDE      : MPLAB Ver 8.91&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   **** Compiler : Microchip C18 Ver 3.43&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   ################################################################################&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;*/&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Includes&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;#include &amp;lt;p18cxxx.h&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;#include &amp;lt;delays.h&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Configurations&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config WDT = OFF                &lt;span style=&quot;color: green;&quot;&gt;// Watchdog Timer Disabled&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config OSC = HS                &lt;span style=&quot;color: green;&quot;&gt;// OSC Mode - High Speed Crystal/Resonator&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config XINST = OFF            &lt;span style=&quot;color: green;&quot;&gt;// Extended Instructions Disabled&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// LEDs&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#define&lt;/span&gt; LED1    LATCbits.LATC0&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// main&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; main(&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;{   &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    unsigned &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; counter = 0;    &lt;span style=&quot;color: green;&quot;&gt;// variable that holds timer overflow count&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// Initialize Timer0&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// T0CON bits&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//   7    |   6    |   5  |   4   |  3  |   2   |   1   |   0 &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// TMR0ON | T08BIT | T0CS |  T0SE | PSA | T0PS2 | T0PS1 | T0PS0&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// See datasheet for details&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// 8-bit timer mode &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// internal clock, pre-scaler = 1&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// TMR0ON = 0 at this point we don&#39;t start the timer&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    T0CON = 0b01001000;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    TRISCbits.TRISC0 = 0;     &lt;span style=&quot;color: green;&quot;&gt;// Set as output for LED&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// infinite loop    &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;(1)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        T0CONbits.TMR0ON = 1;           &lt;span style=&quot;color: green;&quot;&gt;// Start Timer&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;(!INTCONbits.TMR0IF)      &lt;span style=&quot;color: green;&quot;&gt;// wait until Timer0 overflows - polling&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            INTCONbits.TMR0IF = 0;    &lt;span style=&quot;color: green;&quot;&gt;// clear interrupt flag&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;(counter != 19531)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            counter++;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            counter = 0;              &lt;span style=&quot;color: green;&quot;&gt;// reset counter&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            LED1 = ~LED1;            &lt;span style=&quot;color: green;&quot;&gt;// toggle LED&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            T0CONbits.TMR0ON = 0;   &lt;span style=&quot;color: green;&quot;&gt;// Stop Timer0      &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;em&gt;unsigned int counter = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // variable that holds timer overflow count&lt;/em&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
this line of code declares the counter as &lt;em&gt;unsigned int&lt;/em&gt; which ranges from 0 – 65535. So if you want delay other than 19531(calculated for 1sec) and greater than 65535 then you may declare the counter as &lt;em&gt;unsigned long int&lt;/em&gt; instead.&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Simulation&lt;/h2&gt;
Here is the gif animation of the Proteus simulation&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuHShiF05G0zUXxGDzzCCktlqnqxeNsMmFVXp4jhyV_ZRRBMdRH-7BpztZzao6rt-WIA9uAAPlvo8sClZMfAEqRWs_p6G8t2ZCCp6kph8JJwVfFdOr_-fPdIaiN11t5jWCeC7u3wjaka9g/s1600-h/Timer_Ex_animation3.gif&quot;&gt;&lt;img alt=&quot;Timer_Ex_animation&quot; height=&quot;399&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirt1PyTk6-v4JGGASHhspVQQqknYbXz-9SBjudzpxzB7nH2NrZpG-97-nnBzjwZ1oVyH8lZg-2AzrCl7mTrfvfCzbR4PkSont6gWarpmVVeucjtn84CxPbpXQD8QKanVQ_enLO3nOx5JSr//?imgmax=800&quot; style=&quot;display: inline;&quot; title=&quot;Timer_Ex_animation&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Conclusion&lt;/h2&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
In this post we used PIC18F8722’s Timer0 in 8-bit timer mode to obtain a delay of approximately 1sec. Besides this the timer can also be used to find the execution time of a function – for example. In which case we have to use Timer Interrupt to take care of the timer overflow. In the beginning of the function Timer is started and after the function finishes it is stopped. To calculate the time we use our counter variable value as well as TMR0 value as&lt;/div&gt;
&lt;blockquote&gt;
&lt;div align=&quot;justify&quot;&gt;
time taken = (counter * &lt;span style=&quot;background-color: #9bbb59;&quot;&gt;0.0000512&lt;/span&gt;) + (TMR0 * 1/5MHz) sec or more generally&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
time taken = ((counter * 256) + TMR0) *&amp;nbsp; 1/FCPU in seconds.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;u&gt;Please comment you questions and suggestions and subscribe for updates&lt;/u&gt;.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/8099680714562790304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddede-lab.blogspot.com/2013/09/using-pic18-timer-module-for-delay-c.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/8099680714562790304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/8099680714562790304'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/2013/09/using-pic18-timer-module-for-delay-c.html' title='Using PIC18 Timer Module for delay – C Code with Proteus Simulation'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFRlGCgvrp-gp63ZjENlEkaoQvNCzgWGGPqNmYGULE2CiyzU4Dv6GwhRtbQGrmHpmJ2ZSB7cpz_cE7Ngm_jepsWSIZTF5evusKwHv5sZ2E8VTXc1ziYTs5UyEr7MKzwbJ9rSVC5bIebuHz/s72-c/?imgmax=800" height="72" width="72"/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6503816347236610996.post-4348909120139558127</id><published>2013-09-02T15:05:00.000-07:00</published><updated>2013-09-02T15:13:38.149-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Button"/><category scheme="http://www.blogger.com/atom/ns#" term="Input"/><title type='text'>Acquiring Button Inputs in PIC18 using C with Proteus Simulation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div align=&quot;justify&quot; dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimaMq56GXdS78ESr8F98rosfTENerWfj_nRw71KIEAXiyvV6mCCkYabIku6ENKQ0kDRZLVZ04ownJ12aL4Fq4BRuPrhR7xiSsOAY6RI-YmkOMlu68oGZyjeMzJFdDgkQLU10hV_uTJ-3OV/s1600-h/ButtonAnimation%25255B9%25255D.gif&quot;&gt;&lt;img align=&quot;left&quot; alt=&quot;ButtonAnimation&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSE0rx7k67GdmXs8kR4M1PzbStdIZ2PFKQ_uSkR6NCyzp6km_XuAf-mKUqSqPgv83GmXrMZuE3OtptOC5hrGReAYzBxWyjVw1DDPHHsQI164AZDsIXuxvmxN7JjtEZlueySwZHRYavEDSk//?imgmax=800&quot; style=&quot;display: inline; float: left;&quot; title=&quot;ButtonAnimation&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&amp;nbsp;In this Tutorial we will demonstrate how &amp;nbsp;to acquire User Push Button Input &amp;nbsp;connected to one of the PIC18 digital &amp;nbsp;IO. As the user pushes the Button an &amp;nbsp;LED connected to a different IO will &amp;nbsp;glow as long as the button is kept &amp;nbsp; &amp;nbsp; &amp;nbsp;pressed.&lt;/div&gt;
&lt;h2 dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&amp;nbsp;&lt;/h2&gt;
&lt;h2 dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&amp;nbsp;&lt;/h2&gt;
&lt;h2 dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&amp;nbsp;&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
A Little About Port Registers&lt;/h2&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: justify;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There are three Registers associated with each Port of PIC18, LATx, PORTx, and TRISx. where ‘x’ represents A,B,C depending upon the number of Ports in a specific device. The TRISx register is used for setting a Port pin either input or output by writing a binary 1 or 0 respectively. The PORTx register is used to read the state of a Port pin,&amp;nbsp; and writing to it will write to the Port latch. The LATx register is the output latch register and it keeps the latched output value for PORTx. &lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: justify;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
For reading an input port pin we use PORTx register as it gives the current status of the port pin. For writing or reading the state of an output pin either LATx or PORTx is used. Both LATx and PORTx are read/write registers.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div align=&quot;justify&quot; dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;h2 dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
C Code for the Project&lt;/h2&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: justify;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Below as an example code of the project in C which needs to be compiled using Microchip C18 Compiler and the MPLAB IDE environment. The code is almost the same as the previous &lt;a href=&quot;http://embeddede-lab.blogspot.com/2013/08/led-blinking-in-pic18-using-c-with.html&quot; target=&quot;_blank&quot;&gt;tutorial&lt;/a&gt; with a little difference.&amp;nbsp; In the previous &lt;a href=&quot;http://embeddede-lab.blogspot.com/2013/08/led-blinking-in-pic18-using-c-with.html&quot; target=&quot;_blank&quot;&gt;tutorial&lt;/a&gt; we used two pins as digital outputs, here one pin is used as digital input-to which the user button is connected, and the other is used as digital output and an LED is connected to it. &lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: justify;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The input pin is polled in the main loop for button state, if the button is pressed the LED connected to another pin turns on as long as the the button is kept pressed. This is demonstrated with the Proteus simulation.&lt;/div&gt;
&lt;/div&gt;
&lt;div align=&quot;justify&quot; dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Copy the code below and compile it to generate .hex file.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div id=&quot;codeSnippetWrapper&quot; style=&quot;background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;&quot;&gt;
&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/* &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   ################################################################################ &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   **** PIC18 Button Input Example&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   **** IDE      : MPLAB Ver 8.91&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   **** Compiler : Microchip C18 Ver 3.43&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;   ################################################################################&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;*/&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Includes&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;#include &amp;lt;p18cxxx.h&amp;gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;#include &amp;lt;delays.h&amp;gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Configurations&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config WDT = OFF            &lt;span style=&quot;color: green;&quot;&gt;// Watchdog Timer Disabled&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config OSC = HS                &lt;span style=&quot;color: green;&quot;&gt;// OSC Mode - High Speed Crystal/Resonator&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config XINST = OFF            &lt;span style=&quot;color: green;&quot;&gt;// Extended Instructions Disabled&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// LED&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#define&lt;/span&gt; LED1    LATDbits.LATD0&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 619.671875px;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Button&lt;/span&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;#define&lt;/span&gt; BUTTON1 PORTCbits.RC0&lt;/pre&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// main&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; main(&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;{   &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// As the LED1 pin is also an analog input pin we have to declare it as&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// digital by writing the port configuration control bits(PCFG&amp;lt;3:0&amp;gt;) in &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// ADCON1 Register - Refer to the datasheet for more details&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;       ADCON1 = 0x00001111;    &lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// Set PORTD bit 0 as digital output, LED1 is connected on this pin&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    TRISDbits.TRISD0 = 0;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    TRISCbits.TRISC0 = 1;     &lt;span style=&quot;color: green;&quot;&gt;// Set the Button Pin as input&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;// infinite loop    &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;(1)&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;(BUTTON1 == 0)    &lt;span style=&quot;color: green;&quot;&gt;// Poll for Button Press    &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            LED1 = 1;    &lt;span style=&quot;color: green;&quot;&gt;// Turn ON LED&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;            LED1 = 0;    &lt;span style=&quot;color: green;&quot;&gt;// Turn OFF LED&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;    }&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Proteus Simulation&lt;/h2&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The Proteus circuit is also not so much different from the previous &lt;a href=&quot;http://embeddede-lab.blogspot.com/2013/08/led-blinking-in-pic18-using-c-with.html&quot; target=&quot;_blank&quot;&gt;tutorial&lt;/a&gt;. the only change is one LED is replaced with a button.&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4GfbUUbebdAUPz2DqVQfLSJ59WcfGQBJM0RjtPNAsB7A-IVxNZFTutyxurnV-IfgFoWIKWZsuq1b54SG_DGWXeHZiRAkB5084Z2qksKCUQHQhcCBbjaefNk2gvS5nj_Lh8l8MehOw8rYD/s1600-h/circuit23.jpg&quot;&gt;&lt;img alt=&quot;circuit&quot; border=&quot;0&quot; height=&quot;345&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFW83ERdKNptQleldygjmo7AhnG0Q29PPsDeYqVZgivTbR_mMVDhnq89wxxDIAODQwyEIdiULLNcISvLUiTSCdRjTNvoyhyY488uMvDJXPO0N_7DrXDsIVCZoua3VNexwhdn3hgEnbT_rx//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;circuit&quot; width=&quot;564&quot; /&gt;&lt;/a&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
After adding the hex file to the Proteus project click the play button to run the simulation, while the simulation is running push the button and the LED will glow release it and it will turn off. &lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is a simple tutorial demonstrating the use of a push button with PIC18 for beginners hope you learn something from it.&lt;/div&gt;
&lt;blockquote dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Please comment for feedback.&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/4348909120139558127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddede-lab.blogspot.com/2013/09/acquiring-button-inputs-in-pic18-using.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/4348909120139558127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/4348909120139558127'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/2013/09/acquiring-button-inputs-in-pic18-using.html' title='Acquiring Button Inputs in PIC18 using C with Proteus Simulation'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSE0rx7k67GdmXs8kR4M1PzbStdIZ2PFKQ_uSkR6NCyzp6km_XuAf-mKUqSqPgv83GmXrMZuE3OtptOC5hrGReAYzBxWyjVw1DDPHHsQI164AZDsIXuxvmxN7JjtEZlueySwZHRYavEDSk/s72-c/?imgmax=800" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6503816347236610996.post-5223326410511990522</id><published>2013-08-31T12:52:00.001-07:00</published><updated>2013-08-31T12:52:49.309-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LED"/><category scheme="http://www.blogger.com/atom/ns#" term="PIC18"/><category scheme="http://www.blogger.com/atom/ns#" term="SIMULATION"/><title type='text'>LED Blinking in PIC18 using C with Proteus Simulation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJib1-Ojii1K_BCUAUz1zVSnY7ewAZnY9tPkgaDaUmz_tMNYgmrcTfiVqE2MsewRsdAm0JSOdJGajl5K9yBhIGzsBMxCroVR0QD-CjJ9l4PZlSkLkAu-lYK_EpuDDWwLiAagTbwIpmvTT6/s1600-h/PIC18_LEDanimation5.gif&quot;&gt;&lt;img align=&quot;left&quot; alt=&quot;PIC18_LEDanimation&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIropxt43hdoeO2ZisiKWcNSLs_5zsGqj7MHWq2mnE_d3g9wKIPEhtqLE3sP-SMAqHeEyFu6qodL9O5h5eh9eeEx_Ir4xPd3zsDTt4K7PIi5AlAHwuB6SQjI3kjd6jbHIdXbdqMHy3YYCX//?imgmax=800&quot; style=&quot;display: inline; float: left;&quot; title=&quot;PIC18_LEDanimation&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
If you have just started learning PIC18 you will have to study a lot of materials about PIC18, like Instruction Set Architecture, Memory Organization etcetera if you want to know the details. However if you want quick start to program a PIC18 Microcontroller in C you should probably write a simple program in C which will flash an LED connected to one of the IO pin of the Microcontroller like we write the famous “Hello Word” program while learning C.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
This Tutorial demonstrates how to code a simple LED Blinking program in C for the Microchip PIC18 platform and then simulate it using Proteus VSM.&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Pre-requisites&lt;/h2&gt;
It’s assumed that you are familiar with &lt;a href=&quot;http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&quot; target=&quot;_blank&quot;&gt;MPLAB IDE Ver. 8&lt;/a&gt; and &lt;a href=&quot;http://www.labcenter.com/download/prodemo_download.cfm&quot; target=&quot;_blank&quot;&gt;Proteus Design Suite&lt;/a&gt;. &lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Introduction to PIC18&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
PIC stands for Peripheral Interface Controller. PIC18 is a series of 8-bit Microcontrollers made by Microchip. There are different families of PIC18 each having different features. The number of IOs, Data RAM, Flash Memory and Peripherals changes from device to device in a family. A family’s vast feature set provides flexibility to select a specific device for a certain applications depending upon the resources needed.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
For the purposes of this tutorial I have selected PIC18F8722 family. This family has devices with 64 and 80 pins, and also with different resources. we will be using PIC18F8722 from this family for this series of tutorials. For more details refer to the &lt;a href=&quot;http://ww1.microchip.com/downloads/en/devicedoc/39646c.pdf&quot; target=&quot;_blank&quot;&gt;datasheet&lt;/a&gt;.&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Getting Started&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
When you install MPLAB IDE Ver. 8 it will install the C18 Compiler as well which will convert our source code written in C to Machine code. In case you haven’t used MPLAB before refer to the MPLAB Getting Started manual to get a basic idea on how to create and compile a new project.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Microchip has extensive documentations available for their products, which includes Application Notes, Reference Design manuals and many other which can be found on the &lt;a href=&quot;http://www.microchip.com/&quot; target=&quot;_blank&quot;&gt;Microchip Website&lt;/a&gt;.&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
C Code for our LED Blinking Project&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
After you have created your new MPLAB Project create a new .c file copy the following Code into it and add the file into the project. To compile the Project Click &lt;strong&gt;Build All&lt;/strong&gt; from the Toolbar or find &lt;strong&gt;Build All&lt;/strong&gt; in the &lt;strong&gt;Project &lt;/strong&gt;drop down menu.&lt;/div&gt;
&lt;div id=&quot;codeSnippetWrapper&quot; style=&quot;background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;&quot;&gt;
&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum1&quot; style=&quot;color: #606060;&quot;&gt;   1:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;/* &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum2&quot; style=&quot;color: #606060;&quot;&gt;   2:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;   ###############################################################################&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum3&quot; style=&quot;color: #606060;&quot;&gt;   3:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;   **** PIC18 LED Blinky&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum4&quot; style=&quot;color: #606060;&quot;&gt;   4:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;   **** IDE      : MPLAB Ver 8.91&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum5&quot; style=&quot;color: #606060;&quot;&gt;   5:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;   **** Compiler : Microchip C18 Ver 3.43&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum6&quot; style=&quot;color: #606060;&quot;&gt;   6:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;   ###############################################################################&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum7&quot; style=&quot;color: #606060;&quot;&gt;   7:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;*/&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum8&quot; style=&quot;color: #606060;&quot;&gt;   8:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum9&quot; style=&quot;color: #606060;&quot;&gt;   9:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;// Includes&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum10&quot; style=&quot;color: #606060;&quot;&gt;  10:&lt;/span&gt; #include &amp;lt;p18cxxx.h&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum11&quot; style=&quot;color: #606060;&quot;&gt;  11:&lt;/span&gt; #include &amp;lt;delays.h&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum12&quot; style=&quot;color: #606060;&quot;&gt;  12:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum13&quot; style=&quot;color: #606060;&quot;&gt;  13:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;// Configurations&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum14&quot; style=&quot;color: #606060;&quot;&gt;  14:&lt;/span&gt; &lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config WDT = OFF                &lt;span style=&quot;color: green;&quot;&gt;// Watchdog Timer Disabled&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum15&quot; style=&quot;color: #606060;&quot;&gt;  15:&lt;/span&gt; &lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config OSC = HS                &lt;span style=&quot;color: green;&quot;&gt;// OSC Mode - High Speed Crystal/Resonator&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum16&quot; style=&quot;color: #606060;&quot;&gt;  16:&lt;/span&gt; &lt;span style=&quot;color: #cc6633;&quot;&gt;#pragma&lt;/span&gt; config XINST = OFF            &lt;span style=&quot;color: green;&quot;&gt;// Extended Instructions Disabled&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum17&quot; style=&quot;color: #606060;&quot;&gt;  17:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum18&quot; style=&quot;color: #606060;&quot;&gt;  18:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;// LEDs&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum19&quot; style=&quot;color: #606060;&quot;&gt;  19:&lt;/span&gt; &lt;span style=&quot;color: #cc6633;&quot;&gt;#define&lt;/span&gt; LED1 LATDbits.LATD0&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum20&quot; style=&quot;color: #606060;&quot;&gt;  20:&lt;/span&gt; &lt;span style=&quot;color: #cc6633;&quot;&gt;#define&lt;/span&gt; LED2 LATCbits.LATC0&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum21&quot; style=&quot;color: #606060;&quot;&gt;  21:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum22&quot; style=&quot;color: #606060;&quot;&gt;  22:&lt;/span&gt; &lt;span style=&quot;color: green;&quot;&gt;// main&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum23&quot; style=&quot;color: #606060;&quot;&gt;  23:&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; main(&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum24&quot; style=&quot;color: #606060;&quot;&gt;  24:&lt;/span&gt; {   &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum25&quot; style=&quot;color: #606060;&quot;&gt;  25:&lt;/span&gt;     &lt;span style=&quot;color: green;&quot;&gt;// As the LED pin is also an analog input pin we have to declare it as&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum26&quot; style=&quot;color: #606060;&quot;&gt;  26:&lt;/span&gt;     &lt;span style=&quot;color: green;&quot;&gt;// digital by writing the port configuration control bits(PCFG&amp;lt;3:0&amp;gt;) in &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum27&quot; style=&quot;color: #606060;&quot;&gt;  27:&lt;/span&gt;     &lt;span style=&quot;color: green;&quot;&gt;// ADCON1 Register - Refer to the datasheet for more details&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum28&quot; style=&quot;color: #606060;&quot;&gt;  28:&lt;/span&gt;     ADCON1 = 0x00001111;   &lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;  29:&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;  30:&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum31&quot; style=&quot;color: #606060;&quot;&gt;  31:&lt;/span&gt;     &lt;span style=&quot;color: green;&quot;&gt;// Set PORTD bit 0 as digital output, the LED is connected on this pin&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum32&quot; style=&quot;color: #606060;&quot;&gt;  32:&lt;/span&gt;     TRISDbits.TRISD0 = 0;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum33&quot; style=&quot;color: #606060;&quot;&gt;  33:&lt;/span&gt;     TRISCbits.TRISC0 = 0;   &lt;span style=&quot;color: green;&quot;&gt;// The second LED we want to flash is connected on&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;                                  // PORTC pin 0&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum34&quot; style=&quot;color: #606060;&quot;&gt;  34:&lt;/span&gt;                             &lt;span style=&quot;color: green;&quot;&gt;// As this pin is not analog so we just need to&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;                                  // set its direction&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum35&quot; style=&quot;color: #606060;&quot;&gt;  35:&lt;/span&gt;     &lt;span style=&quot;color: green;&quot;&gt;// infinite loop    &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum36&quot; style=&quot;color: #606060;&quot;&gt;  36:&lt;/span&gt;     &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;(1)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum37&quot; style=&quot;color: #606060;&quot;&gt;  37:&lt;/span&gt;     {&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;  38:         &lt;span style=&quot;font-size: 8pt; line-height: 12pt;&quot;&gt;Delay10KTCYx(10);         &lt;/span&gt;&lt;span style=&quot;color: green; font-size: 8pt; line-height: 12pt;&quot;&gt;//wait&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum38&quot; style=&quot;color: #606060;&quot;&gt;  39:&lt;/span&gt;         LED1 = 0;    &lt;span style=&quot;color: green;&quot;&gt;// turn LED1 OFF&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum39&quot; style=&quot;color: #606060;&quot;&gt;  40:&lt;/span&gt;         LED2 = 0;    &lt;span style=&quot;color: green;&quot;&gt;// turn LED2 OFF&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum40&quot; style=&quot;color: #606060;&quot;&gt;  41:&lt;/span&gt;         Delay10KTCYx(10);        &lt;span style=&quot;color: green;&quot;&gt;//wait &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum41&quot; style=&quot;color: #606060;&quot;&gt;  42:&lt;/span&gt;         LED1 = 1;    &lt;span style=&quot;color: green;&quot;&gt;// turn LED1 ON&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum42&quot; style=&quot;color: #606060;&quot;&gt;  43:&lt;/span&gt;         LED2 = 1;    &lt;span style=&quot;color: green;&quot;&gt;// turn LED2 ON&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum44&quot; style=&quot;color: #606060;&quot;&gt;  44:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span id=&quot;lnum45&quot; style=&quot;color: #606060;&quot;&gt;  45:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitBDZBZwbp-rT7Fyous_McZ7SX8GLK55_mQRwUrKWB40twb_z5qdmad06NfciD9vuhwga2gmsp-2OX0HoHouHbibB0FfCWTP4IwJPxXGliiY3UpYUJQKMvGd6OJqigPitpBuVUEDzUczd9/s1600-h/build6.jpg&quot;&gt;&lt;img alt=&quot;build&quot; border=&quot;0&quot; height=&quot;77&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVzKoTkeci2g4SrMHTUv4rUYWSavB0XlQiiySUjEDEvkpDGFBdkMehGTg5CZ0YUqYw_aN2Ltoo3JHnqxriMr3Aoh7dE8EHDS1HYgR1bcCMKYdy__6urG0TeqsWxxjBn2IYoZSbysxqRMxQ//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;build&quot; width=&quot;576&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Explaining the Code&lt;/h2&gt;
&lt;br /&gt;
Although the code is heavily commented, but I will explain some points to my best. The fist two lines &lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;codeSnippetWrapper&quot; style=&quot;background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;&quot;&gt;
&lt;br /&gt;
&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;// Includes&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;#include &amp;lt;p18cxxx.h&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: white; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;&quot;&gt;#include &amp;lt;delays.h&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
includes the device specific header file and the delays.h is for the C18 built-in delay routines which will be used while flashing the LED. I used the built-in delay routine for the delay, but we can also use one of the PIC18 timers for the delay. We will be covering timers in another tutorial.&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
The other three lines are for the configuration settings of the device, their may be other configurations depending on the application. For our purposes these are enough. You can find the device specific configuration settings in the file “hlpPIC18ConfigSet.htm” in&amp;nbsp; the install directory of MPLAB. On Windows 7 64-bit it will be something like &lt;span style=&quot;background-color: #4bacc6;&quot;&gt;C:\Program Files (x86)\Microchip\MPLAB C18 Suite\v3.43\doc&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
In order to ease our life I have defined the LED pins as LED1 and LED2 in the next two lines.&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
Then we enter into the main loop. In the main loop we set the direction of the LED pins as digital outputs. I have used one analog and one digital pin to demonstrate the use of an analog pin as digital IO.&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
The other important line of code is the &lt;strong&gt;&lt;em&gt;Delay10KTCYx(10) &lt;/em&gt;&lt;/strong&gt;this function is used for the delay between LED on and LED off cycles. This generates delay in multiple of 10,000 instruction cycles. One Instruction cycle is equal to 1/FOSC/4 and Clock cycle is equal to 1/FOSC, Where FOSC is our Clock Frequency. Help files for these library function can also be found in the above mentioned &lt;strong&gt;doc&lt;/strong&gt; folder.&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
Now that we have compiled our code and our HEX file is ready to be burned the PIC18. We will simulate the code in Proteus.&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Simulation&lt;/h2&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
I have created a simple circuit in Proteus which contains PIC18F8722 with minimum connections. As shown below&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihxTW2O7pQCb5Las25lFBmPqu9PJlb0ouhp8St38s-SRn9Z9jAiiUO47o31XUavipe-qG9NGvy-N_GFZZ7h_64LN15hsarLa9gtRhe0q7Ju8v80rt2W9dgvx8SAFgT9ENdSLvVBNb-uk_o/s1600-h/circuit%25255B8%25255D.jpg&quot;&gt;&lt;img alt=&quot;circuit&quot; border=&quot;0&quot; height=&quot;407&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiovQ1ij7E7DRHtWxXx-IwJOopkGhHA4_sDf1437ozpqueKQ5HgJ6OPHa1O7dFutsYmg6F9Li8x6zaZlgS55rkAXcBXZ6q5hxS_p-rbyfWUD-H9I_Pf0g4SkbxEiEpGxYRC7xCtPOjYUUiK//?imgmax=800&quot; style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;circuit&quot; width=&quot;576&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
For the purpose of simulations Proteus doesn’t need the power and the Clock circuits I have included this if we want to build a real PCB for this project.&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
After adding the HEX file to PIC18 Click the Play Button to run the Simulation.&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfexKaRKePSjMewTMiO3td2x4Y27rrsCrJ7yDrg_rePezPyYTEyo2ruo8jSG7gcQowkZbDRtAidHk_BFxAsJGreTjXkN9cYPIqAbeFllXpTnE_4xHOeIWijXnqrRJ1e-cSK3-mwjvVT9YI/s1600-h/circuit_simulation%25255B28%25255D.gif&quot;&gt;&lt;img alt=&quot;GIF animation depicting LED Simulation in Proteus&quot; height=&quot;399&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkPqx_hA0cMOB2nsJysHunTf6CLDeUhg4J6cY5ERpL_27VPZ-kPj3pW9tDbf0aH_xafojJFqRbs1c5FnRI3aifO7zNIURCkdfJ8fctFaG17Qblj3vUnTSLXcTbmi-pm3GhGxDS3ZU88ZFm//?imgmax=800&quot; style=&quot;display: inline;&quot; title=&quot;circuit_simulation&quot; width=&quot;578&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
This Concludes our LED blinking Tutorial. We will be covering other features of PIC18 in the upcoming tutorials.&lt;br /&gt;
&lt;blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Please use the comment box below to leave your feedback.&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/5223326410511990522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddede-lab.blogspot.com/2013/08/led-blinking-in-pic18-using-c-with.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/5223326410511990522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/5223326410511990522'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/2013/08/led-blinking-in-pic18-using-c-with.html' title='LED Blinking in PIC18 using C with Proteus Simulation'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIropxt43hdoeO2ZisiKWcNSLs_5zsGqj7MHWq2mnE_d3g9wKIPEhtqLE3sP-SMAqHeEyFu6qodL9O5h5eh9eeEx_Ir4xPd3zsDTt4K7PIi5AlAHwuB6SQjI3kjd6jbHIdXbdqMHy3YYCX/s72-c/?imgmax=800" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6503816347236610996.post-7432121170155929715</id><published>2013-08-20T10:15:00.003-07:00</published><updated>2013-08-31T12:53:39.924-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LOGO"/><title type='text'>Tutorial - Placing your company logo on PCB in Proteus ARES</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaR_Rxgnx1nkjUdNoVaxMyBwyj1B5VcPI04HJ-WRr_sBv4asbgONNzPJtorMq7o5ACpIoMzgkuuQVY4UiP2Y-iVp2xu7smjUKvnBvJbmsQE7_W3i6QC3RP4Dy6p-j3HA8nCZIrkfMmCr8K/s1600-h/pic32-title4.jpg&quot;&gt;&lt;img alt=&quot;pic32-title&quot; border=&quot;0&quot; height=&quot;235&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6T7IPto6pBjMqSG8-3SbSFO_fDnyP95BugJ3D9iyyLB1wo_RDmhPf6pyNePyvOBxW3r3WXsWMJfKy-yiMD4Q3DYaNZoTibtDyRYWCyWfBPrM1Pt7gqMapRxDxLLW1jymzqNJeGyumg2RE//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;pic32-title&quot; width=&quot;489&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Today we will talk about how to place logo or other graphics on PCB in Proteus ARES. After we design a PCB its important to place logo of your company on the PCB so that people know who made it. In ARES we can do some artwork using the built-in graphics tools like drawing a circle, line, arc, rectangles etc. but its not possible to make your company logo using these tools. So you have to place your company logo using import features in ARES. Let’s place a logo on a PCB to illustrate the process.&lt;br /&gt;
First of all you need to convert your company’s logo to monochromatic bmp format in order to import it to ARES. you can do the conversion either with Paint (a small photo editing program that comes with Windows) or any other online or offline tool you can find. I have converted the logo to monochromatic bmp using Paint in Windows using the following procedure…&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Open the logo image with Paint  &lt;/li&gt;
&lt;li&gt;From the Save As choose the Save as type “Monochromatic Bitmap” from the drop down menu and Click Save. &lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglzT89Vd8VcPAxBGjEvWvfg3yMfhB5MzhGaZ3k5Fw3DKweHB2IiXX-WgrIHO40MPbhpnewzIhRx0ouwcPGcY4hd-QkpI_Jh-EkFytv4Jc-4JMV2NXrnyGTLTHU64yvt-vDKXQRriYkpWRP/s1600-h/pic32-14.jpg&quot;&gt;&lt;img alt=&quot;pic32-1&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ4K-Adg7XbjhuiA_d1r4vAMiYdRRgpDljcPplpeJC-ros8S2io7O3PknVpXHfiRa-X-j0EKHt4JjKy70Q4qvJLW0NlB1RJ5yOlcl1o22z2c_jemQaR_3FUSlC42JokWBO7-PHPTjvrzEa//?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;pic32-1&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Now that you have the .bmp Image of your logo. Open the PCB in Proteus ARES do the following steps to place the image on&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;From the File menu select Import Bitmap  &lt;/li&gt;
&lt;li&gt;Navigate to the .bmp image you have saved and import it  &lt;/li&gt;
&lt;li&gt;The image will be attached with the mouse place it wherever you want and resize if required. &lt;/li&gt;
&lt;/ul&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj05WF2CenvE78tHmi5P8z_W5caK6COsfaA6YHzcGXjMluq3UhcvxL8nhbCD_82V6ERY2aoDS3PNHbCNc-OSOM2tbihTths_u6v78Ey8OY_5ItUxCiWu9bU_G4J6iBRr0dNTYwSQxkXiuQE/s1600-h/pic32-28.jpg&quot;&gt;&lt;img alt=&quot;pic32-2&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxX8npaFzsv8F9MlvKw6Mc5BgCPCx_ivNUowbaSKp8a18g_pwTsdZuJYltIjzsRF_ABOBU7Rl_Upwi-g2gxvS5w4vPdhQWLi4zIH0cF5YfZYUMds509jIJMibsZFFAQ4cqx7vVqs2Nmf5t//?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;pic32-2&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
That’s it you can import any image you want to place on the PCB but first you have to convert it to Monochromatic Bitmap format. &lt;br /&gt;
After placing and re-sizing the image the Board looks like as below&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha9h9-RlYcKTVvKD2pq4B5Rvjqb6PYqGnNzbE-kgJ2nwQqml85vgbkVd7gzvM9nc1fxFJrOZNIuJJvN606MTjwMXO578Iel4zS2UHVZVwOPa2bI6SP3DwC_p56cSyOW9v2diqUJMDqjFuB/s1600-h/pic32-36.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;pic32-3&quot; border=&quot;0&quot; height=&quot;307&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGYOoPudW_UZ9XXlU0DSpFtiX5_PUV8btdEYWQk3sgnWkvAFCdeT-fE3Sf8Xz4Kye1JQceJZRdR1mlDAOdfTe_btf9Es3JPp0tn7_GHTMNpwQ2gbd3MR-B7Ghk5kYz5Fzt91kDPakDO9iT//?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;pic32-3&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Please comment you questions and suggestions and follow for updates. Thanks&lt;/blockquote&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/7432121170155929715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddede-lab.blogspot.com/2013/08/tutorial-placing-your-company-logo-on_20.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/7432121170155929715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/7432121170155929715'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/2013/08/tutorial-placing-your-company-logo-on_20.html' title='Tutorial - Placing your company logo on PCB in Proteus ARES'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6T7IPto6pBjMqSG8-3SbSFO_fDnyP95BugJ3D9iyyLB1wo_RDmhPf6pyNePyvOBxW3r3WXsWMJfKy-yiMD4Q3DYaNZoTibtDyRYWCyWfBPrM1Pt7gqMapRxDxLLW1jymzqNJeGyumg2RE/s72-c/?imgmax=800" height="72" width="72"/><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6503816347236610996.post-181074785985435915</id><published>2013-08-15T07:27:00.000-07:00</published><updated>2013-08-16T02:38:57.757-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Device Symbol"/><category scheme="http://www.blogger.com/atom/ns#" term="Heterogeneous"/><category scheme="http://www.blogger.com/atom/ns#" term="ISIS"/><category scheme="http://www.blogger.com/atom/ns#" term="Multi-element"/><category scheme="http://www.blogger.com/atom/ns#" term="Proteus"/><title type='text'>Tutorial - Creating Multi-element Heterogeneous device Symbol in Proteus ISIS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAPBXGF9WLMAD9EX9D6G-EULMhkKQjEpLUlqxe5x28A_IfRpI-IicA91iWRaezbj3ra66tZ-5z9u0eV6AkEN-4zRlOqIO3fmjOB980rn9XuVjYSDBMLV8bhWd46xEX_pnc8fEL5jjhVkUn/s1600-h/title1.png&quot;&gt;&lt;img align=&quot;left&quot; alt=&quot;title&quot; border=&quot;0&quot; height=&quot;247&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSV1dQj4z1Js_tcYMhR-bQh9h6jYJktIrKan_ykKtyJ0y8N3JcuF9YgfN-QpXr9nS0-RkNma08vbtC8aYA4quWCb5fxBedwaADFqaNVP3CHSzfi_HjfqSa5l2aLW072jJkga2U5-DFpH_4//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; float: left; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;title&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
In today’s tutorial we will learn “How to make&amp;nbsp; multi-element heterogeneous device symbol in Proteus ISIS”. The image on the left shows a device symbol consists of 7 elements where each elements have different number of pins. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
We will make this 7 elements device symbol for NXP Semiconductors ARM Based Microcontroller LPC2478 using Proteus ISIS 8 demo version.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;/h2&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Why make Multi-elements heterogeneous device symbol instead of One single element symbol?&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
The answer to this question in my opinion is, its easy to deal with multiple elements of a device when it have hundreds of pins. So we split the device symbol into multiple elements which eases capturing our schematic.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Lets start our work to make one such symbol.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
We will be making device symbol for LPC2478. LPC2478 is a 208 pin device available in LQFP as well as BGA package. We will make device symbol and then assign LQFP Package, You can also assign BGA Package to the symbol the process is the same. Datasheet of LPC2478 can be downloaded from &lt;a href=&quot;http://www.nxp.com/documents/data_sheet/LPC2478.pdf&quot;&gt;here&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Proteus 8 Demo Version can be downloaded &lt;a href=&quot;http://www.labcenter.com/download/&quot;&gt;from Lab Center Electronics Website&lt;/a&gt; if you don’t have it.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 1 – Opening Proteus ISIS&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Open &lt;a href=&quot;http://www.labcenter.com/download/&quot;&gt;Proteus 8&lt;/a&gt; and click on the ISIS icon in the toolbar to open ISIS.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 2 – Make The first element in the multi-element device Symbol&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Make device symbol for the Power part of the device. Assign names to pins and &lt;b&gt;don’t&lt;/b&gt; assign number at this stage, we will assign numbers in the &lt;b&gt;Package Assigning&lt;/b&gt; step. Select the symbol and invoke the Make Device tool using the toolbar button. In the warning window click OK, The Make Device window appears. In case you don’t know how to make device symbol in Proteus ISIS, read the tutorial &lt;a href=&quot;http://www.embeddede-lab.blogspot.com/&quot;&gt;Making Device Symbol in Proteus&lt;/a&gt; first.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRctsPWsbRF6qluqerI-x9nhWRxAr8utRp90BJc2Xkmrj5dIkpKNqCGNiznnH8pAmoBOL9GQTkuuDve6bTSEHCObTOIABNBLXV9Xjy_FQLqQfJsLF81OK3pPea1_TXi2wU2I-jp-AxojC-/s1600-h/step-23.png&quot;&gt;&lt;img alt=&quot;step 2&quot; border=&quot;0&quot; height=&quot;216&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHNrtRuj5USHOHVlfiVmWeA-KOA-d01N4gA5a2AZOUbM94IiAI1BvHOXCosrCuEX-ybsgEXRd4Rh1lvmgaNb0CsnssEUyq2P4ZvqT_jEQap5GWqdlX4l3GrhnGVsslFN1IsNTmzYxniBcb//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;step 2&quot; width=&quot;340&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 3&amp;nbsp; - Naming elements of the multi-element symbol package&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;b&gt;&lt;/b&gt;In the Name Device field write LPC2478:A (&amp;lt;Name of Device&amp;gt; : &amp;lt;A,B,C….Z&amp;gt;), write U in the Reference Prefix field click Next&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2fXlmJJL3T0rUWwEyqqGEYWxOd-KCoIvyXKwk2y9nq9DrgttuI9lNvwMaiPrXBpBHfrieQRmGrmgy-Wl1z9LY_WGAHNkuXtT2F-c-tE8T24hd1PNby5HEC7VYkQM9o7fcwY5jCKUAw7Py/s1600-h/step-33.png&quot;&gt;&lt;img alt=&quot;step 3&quot; border=&quot;0&quot; height=&quot;213&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnEVzHxQf20Cc64_G_dKEz-wBGllDSFHZlRm09bGlK7L8RyctS44bFFyyR2civwCskdBb8wqjHpT6onGailDRWkA8MztrZEwbCsuUEcHQ_jMTzpNBz-DehxQRWMHt2E5lfcKb2Q30vC-z1//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;step 3&quot; width=&quot;340&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
The Next Dialog says package cannot be assigned (we will do that later) click Next. Add datasheet if you want, select Category, subcategory, Manufacturer etc. for the Device, Select a Library and Hit OK to finish the dialog. We have created and saved the first element of Heterogeneous multi-element device symbol.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitMUOUGYwdR9PlVQvEBvZUXuLVdG48vvaDg_2ji0Z2ts1K9jJYResCP6VCQBDF7JVN7ayM-KJvSsplmZh2XoLa8hpuE5jUpECPMWzNr6JyZxoGV180O_2BwU5YFY3ZcSdDhz1KZlXRC_Ox/s1600-h/step-43.png&quot;&gt;&lt;img alt=&quot;step 4&quot; border=&quot;0&quot; height=&quot;214&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC0OdjOVGohDTxMKZ08tCcWr6FZGWPIBkU4y8XOnYk0nw1LBJbADYhdkcez7-vWGWPpPIxV5ooSLuS4WtE5Rcjt67F51WDXOzdXGbrXlzUiG77xKnPN4D-qR3YQxgkjMLWE0vQ_FS1KcVO//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;step 4&quot; width=&quot;340&quot; /&gt;&lt;/a&gt;  &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 4 - &lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Repeat &lt;b&gt;Step 2&lt;/b&gt; and &lt;b&gt;Step 3&lt;/b&gt; for all other parts, assign names as LPC2478:B, LPC2478:C and so on. Now you have complete device in different elements. We will assign a package to it in the next step to complete the tutorial.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;h2&gt;
&lt;/h2&gt;
&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 5 – Assigning Package to the multi-element device symbol&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Add one instance of each element to the work area in ISIS. Select all and invoke the Packaging tool from the toolbar as shown in the image below&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtwrVSB_YPI7uwqbssEPUKv_e9zucE8diEPPPqiwbrKypQc0IfN1YWFgWwDCEXqYWeg_AlIpJ8J57IL6Gpr_kANtyMN252JqejmM5YlHf1rCWr7ZNx-pl3PYFtZzRYVR2LN7dY7pWJ-7Uh/s1600-h/53.png&quot;&gt;&lt;img alt=&quot;5&quot; border=&quot;0&quot; height=&quot;245&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQMsdrjzFcFba4RISou_FLh1ZBlHm3eZjIgrLXxh5KKOBfUkrGkK9-vdLyQWYjXpPk1I8-S3D2GMGfyOHe5CcqKqH71DAx5ibnI5IEgh3LBLYviBRitLm4Rj9IHwL5dumAuyI4N15QDhxx//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;5&quot; width=&quot;340&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
In the dialog that appears click add to add the PCB Package(footprint) of the device. To know how to create a device package in ARES read the tutorial &lt;a href=&quot;http://www.embeddede-lab.blogspot.com/&quot;&gt;Making Device Package in Proteus ARES&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
The Package assignment is not finished now. remember we didn&#39;t assigned numbers to pins while making symbols for them, here we have to assign numbers to the pins. The pin number assignment is time consuming process in making multi-element heterogeneous device symbol as you have to refer to the datasheet. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
In the next window we have a column for each element and we will write the pin numbers in each column for the pins shown in the left most column, After assigning writing pin numbers in each column click Assign Package to finish.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb0O_J_EVRJqUIhjDKQrOT99AesaOJqA_PsjIElA1h5nVwP737y0l8yB9yjfzFd7cmLrqx6UXK-ezneR-NUT0jgpXvYAb113e0ZAvjoYTRawe9X_7Dm5xiziYGUEk7au5D-1UfBIA_zlXK/s1600-h/63.png&quot;&gt;&lt;img alt=&quot;6&quot; border=&quot;0&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaQ7y3EfZSgR-jYHuTQ4WD4xvbRbKsK9Fr8nrzYYHmRjEgT1G79D1aplFJEAtMnlXZRj1O3LUVHpGrtNz_s0KNCWeJ6o07sHB7G2T-LP807FximnvSkWtvpMALUrnHJEbXRJ8OaeBHqm5W//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;6&quot; width=&quot;340&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
This completes the tutorial. In this tutorial we have learned how to make multi-element device symbol in Proteus ISIS. Please feel free to comment for questions and suggestions. &lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/181074785985435915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddede-lab.blogspot.com/2013/08/tutorial-creating-multi-element.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/181074785985435915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/181074785985435915'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/2013/08/tutorial-creating-multi-element.html' title='Tutorial - Creating Multi-element Heterogeneous device Symbol in Proteus ISIS'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSV1dQj4z1Js_tcYMhR-bQh9h6jYJktIrKan_ykKtyJ0y8N3JcuF9YgfN-QpXr9nS0-RkNma08vbtC8aYA4quWCb5fxBedwaADFqaNVP3CHSzfi_HjfqSa5l2aLW072jJkga2U5-DFpH_4/s72-c/?imgmax=800" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6503816347236610996.post-876789051980212667</id><published>2013-07-27T17:26:00.003-07:00</published><updated>2013-09-04T11:59:45.103-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ARES"/><category scheme="http://www.blogger.com/atom/ns#" term="Merge"/><category scheme="http://www.blogger.com/atom/ns#" term="Panelization"/><category scheme="http://www.blogger.com/atom/ns#" term="PCB"/><category scheme="http://www.blogger.com/atom/ns#" term="Proteus"/><title type='text'>Tutorial–Panelizing/Merging Different PCBs in Proteus ARES</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDoiFsbZVprSj09TPU9AXuuXyoStQUw2YV6kFSmyUAQP1_aq7qgT8X5XTnsDnLQokEkUApomGC7TPIpY_3F9tJpu-pgHDu8W4yZm0Zyb7jZHLaW_hWPdwFg16mqOv4RnOm2e3WfET7Lyt-/s1600-h/title%25255B5%25255D.png&quot;&gt;&lt;img align=&quot;left&quot; alt=&quot;title&quot; border=&quot;0&quot; height=&quot;244&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhELgBoM_aEmxB2uApw_0AZIcC26f4fB_OP4Tmm0_BgfcJahhRe2UMypGvSar7IBsr_dQFigepu47R_z6C-G7uVjckQuDNMLdnFj3zo69paqPbUrLBTZiSo3R6o41UEhl6vFDaHDDwp1-0L//?imgmax=800&quot; style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; float: left; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;title&quot; width=&quot;340&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
Merging different Prototype boards on a single Panel and generating Gerber Files for it, So that we can submit a single job to the PCB Manufacturer.&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;span style=&quot;background-color: orange;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Note:&lt;/span&gt;&lt;/strong&gt;&amp;nbsp; This Tutorial applies only to double sided PCBs.&lt;/span&gt;&lt;/div&gt;
&lt;h1&gt;
&amp;nbsp;&lt;/h1&gt;
&lt;h1&gt;
&lt;/h1&gt;
&lt;h1&gt;
&lt;/h1&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Contents&lt;/h2&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=6503816347236610996#intro&quot;&gt;Introduction&lt;/a&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=6503816347236610996#step1&quot;&gt;Step 1 – Setting to Work&lt;/a&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=6503816347236610996#step24&quot;&gt;Step 2 - 4 – Viewing Gerber Files in Penalization mode&lt;/a&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=6503816347236610996#step5&quot;&gt;Step 5 – Arranging Boards on the Panel&lt;/a&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=6503816347236610996#step6&quot;&gt;Step 6 – Generate Gerber Files for the Panel&lt;/a&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=6503816347236610996#conc&quot;&gt;Conclusion&lt;/a&gt;&lt;/h3&gt;
&lt;div id=&quot;intro&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Introduction&lt;/h2&gt;
&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Penalizing PCBs is the process of merging the Gerber files generated by a PCB package for different circuit boards in order to submit a single job to the PCB manufacturer. In this Tutorial we will merge Gerber files generated by Proteus ARES for three different boars. Proteus ARES generates Gerber files in RS-274X extended Gerber format. You can read about RS-274X and other Gerber formats &lt;a href=&quot;http://en.wikipedia.org/wiki/Gerber_format&quot;&gt;at Wikipedia&lt;/a&gt; or somewhere else on the internet.  &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
I assume you are familiar with schematic and PCB designing in the Proteus Design package. You can download the current free version of Proteus &lt;a href=&quot;http://www.labcenter.com/index.cfm&quot;&gt;here&lt;/a&gt;. For this tutorial I used Version 7.7.  &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
For this tutorial I am using three the Sample Project. I have previously generated the Gerber files for them in different folders for the sake of clarity  &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Project1-Gerber  &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Project2-Gerber  &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Project3-Gerber  &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Now we do the following steps to Panelize the Boards into a single Panel.&lt;/div&gt;
&lt;div id=&quot;step1&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Step 1 - Setting to Work&lt;/h3&gt;
&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Open the Proteus ARES Program. Set the Work area to the size of the Panel. Here are some tips for selecting the size of the panel&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Know the dimensions of your boards  &lt;/li&gt;
&lt;li&gt;How many copies of each board you want?  &lt;/li&gt;
&lt;li&gt;What size Panel the PCB manufacturer can make(some PCB Manufacturers have restrictions on the Panel size some have not confirm it first).  &lt;/li&gt;
&lt;li&gt;Select the Panel size so that you can optimally place your boards without wasting much space on the Panel. &lt;/li&gt;
&lt;/ol&gt;
&lt;div align=&quot;justify&quot;&gt;
Now you are ready to set the work area go to the windows menu and select the option “Set Work Area” enter the dimensions of the Panel and Hit Ok.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjLn3jSisCj15sE1bV2aI0pgWZ85yGc7L17vjSC0QhS6CozsjVrNWsM6yl0CZ8yVcYb-tMDT98ITToxFsufWBMJ4riJQMgf40jhcTV23qa4WGTJp6i7Ie0OiXEGuF8o8rLYhWMJvpUm5DV/s1600-h/1%25255B8%25255D.jpg&quot;&gt;&lt;img alt=&quot;screenshot of doing Step1&quot; border=&quot;0&quot; height=&quot;230&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVaXKdZ6BxcmLRFBKenYvWMYpshx_I-oqHRuNco4B_IW-ghIOi72mjXwFO5WTOoMbaYuKGjz4GHKSpMy8xVgqK-qANIDt9KF93mLukNoddKAznrFv4KuB63xacoNNKZv0ZG6H45du5aOvY//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;1&quot; width=&quot;425&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;step24&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Step 2 – 4 – Viewing Gerber Files in Penalization mode&lt;/h3&gt;
&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 2 -&lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
Now it’s time to open all the Gerber File we have previously created in ARES. Click the &lt;b&gt;Gerber Viewer&lt;/b&gt; icon in the toolbar or Find it in the Output drop-down menu, the Gerber View window appears, navigate to the project folder and open the GERBVIEW for the first project as shown in the figure.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoiRkjGq7Ml0DEDsC8hTIsHSOSH8UfRT9Wd02WCxB7-8lWJI5T3HhoRXbzV5dFr9f98Ppc9TLoFKZ8qfeB3EOvLbJCZfUzk50ZNpAYcVn4EuyYnKoBBI0w7Cm557OU8pkvTnPdIzajAf9N/s1600-h/2%25255B54%25255D.jpg&quot;&gt;&lt;img alt=&quot;screenshot of doing Step2&quot; border=&quot;0&quot; height=&quot;229&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibNqaDZSs95TZCJvFmnK8MkjN7A8Zvf2PVie9XTbUTkPuMi2elnURCcKfnGiJhW8BAI03QojN3DdX9DJ_uH9BSMPLhU1DO9lXSCuVdql6TXHbyrosFaHrcNzrNGE0N47P4UFKyXDD-OULM//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;2&quot; width=&quot;430&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 3 - &lt;/h2&gt;
&lt;div align=&quot;justify&quot;&gt;
After clicking Open, In the next popup window don’t forget to check the option “Penalization mode” as shown. Click OK&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi46_l0vG0y2vEasVNd7Ao6YJBKlrQOtnmukXxiaRVvdn8ZhTpz-Eyo1FQQZXCfAnANbzGAVWzfkvccchAmzpz-6RsJ8U-rBjEfHs69r6GsMIJeySWjRRTYwysU_Xc9plnydYQbU0wjnuQ0/s1600-h/3%25255B4%25255D.jpg&quot;&gt;&lt;img alt=&quot;screenshot of doing Step3&quot; border=&quot;0&quot; height=&quot;230&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghyieImnms4Ho4A0H1Z_Y9DbV8vdz9AlI4Ash5zGRN7FDDoD7i6TAEbkIc24bL69yGfsew6TN-AF3gM5llwq2lpiGwgrwday4_5lFmN45iH5vGykr1m7Qa_pz7VRXgAi1TUP6iXIbgPe5M//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;3&quot; width=&quot;431&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
We have just viewed Gerber Files for the First Project in ARES in Penalization mode.  &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAR78YaJtKuNr7Kqp2jZW2O8G0M28R2v4_9t4lHuVax7R6Dl3_M3iNA4IDfRt5CBr25kOMpDavGgq22gYJMLvtPhestrgUCA0gx6JZBb0l3HsRo_-9dDqY9FMtrTFxoU7zF3crLpDYSKBj/s1600-h/4%25255B3%25255D.jpg&quot;&gt;&lt;img alt=&quot;screenshot showing first board when imported to ARES&quot; border=&quot;0&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsx7F6FoLofojaetRguc5VOqEi_RRHwELedfJdfadbBWUgMvwIes4BNQdaPRiXHexsQjscTc6M30yKvOrNGEVBUSc3DRv78XgzJFEOL5hwazQIZ71Tzovula4_5s8jVIAVzJkyabSJvLBU//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;4&quot; width=&quot;425&quot; /&gt;&lt;/a&gt;  &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 4 - &lt;/h2&gt;
Follow &lt;b&gt;step 2&lt;/b&gt; to &lt;b&gt;Step 3&lt;/b&gt; for the other two boards.  &lt;br /&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;b&gt;Note:&lt;/b&gt; “Don’t move any of your board until you do the process for each board you want to be on the Panel”. If you move a board and then try to load another you will get the option to save your work, it doesn’t matter whether you save or not you will get the other board in new work area, which we don’t want here. So be careful  &lt;/div&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div id=&quot;step5&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 5 – Arranging Boards on the Panel&lt;/h2&gt;
&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Now that you have loaded all of your boards to the work area, it’s time to arrange them on the Panel. &lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
If you want to make a copy of a board you simply select it right click and select “Block Copy” place it as many times you want and then click escape key to end.&lt;/div&gt;
I arranged the Boards as shown in the below image  &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVUS7v3lFQHJ26yuUv3eL7kD1yJghe8__uiIH1phTB0-68L5_F7Ahv63jaarpD8IkaPSjMz3_8PKuMyI_b9QWvem06dg6PFUBPLtRbylltqI-Dw7Of8avoBu9okfQ26ZkXgZAl6vcdWJSI/s1600-h/5%25255B3%25255D.jpg&quot;&gt;&lt;img alt=&quot;screenshot when all PCBs are merged&quot; border=&quot;0&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPrCUc_jMnoR0IA3viIZ-5leVusLQxGEuDFdtmuuqkjhCRHwA377TEGuagZVqzSCQ8FiWQ55xzUt77ivHaIyncPV8chyNa8OWET4hQNE4QthVwoszQmgRJrx9gAZQ1rhDHT1ro5-yvp_Fv//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;5&quot; width=&quot;425&quot; /&gt;&lt;/a&gt;  &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div id=&quot;step6&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Step 6 – Generate Gerber Files for the Panel&lt;/h2&gt;
&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
Now we have to generate Gerber files for the Panel which has our three Board on it, these are Gerber Files you will submit to the PCB Manufacturer. The Steps to generate and save the Gerber Files for the Panel are as below (in the image)  &lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;justify&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjA_HgHdZMoGLgQpcQsXFCCI69_e5h-JFaYuPc57WhdNseXJHX1bqmjIFhyphenhyphenpNpzsSd6PiK6J4ZuLAnKr4Cu9-QBXPmAUSIuOetvUhuyuJOeNDq-DYQKrbldJvuWqaGzbRadV7C3MPDHKkBD/s1600-h/6%25255B3%25255D.jpg&quot;&gt;&lt;img alt=&quot;screenshot of doing Step6&quot; border=&quot;0&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJpTB5iAVoD4NOTEkWKKSWaqxKtk5Dj4I1Bd3uPdUFzvXklonoyxaBio-5oAy5ZjoZEkCU887gmHE_8idoNJQqr4mCIqXXMOhBRqPE0sMqo8rvUtvcIH7NmcPl-kN2kxdVgeO5pokfjSr3//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;6&quot; width=&quot;425&quot; /&gt;&lt;/a&gt;  &lt;/div&gt;
&lt;br /&gt;
&lt;div id=&quot;conc&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Conclusion&lt;/h2&gt;
&lt;/div&gt;
&lt;b&gt;Trick:&lt;/b&gt;  &lt;br /&gt;
If you are having difficulty moving the boards, try to hide some layers.  &lt;br /&gt;
This concludes the Tutorial.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://embeddede-lab.blogspot.com/feeds/876789051980212667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embeddede-lab.blogspot.com/2013/07/tutorialpanelizingmerging-different.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/876789051980212667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6503816347236610996/posts/default/876789051980212667'/><link rel='alternate' type='text/html' href='http://embeddede-lab.blogspot.com/2013/07/tutorialpanelizingmerging-different.html' title='Tutorial–Panelizing/Merging Different PCBs in Proteus ARES'/><author><name>HAFEEZULLAH KHAN</name><uri>http://www.blogger.com/profile/04833253284359069129</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhELgBoM_aEmxB2uApw_0AZIcC26f4fB_OP4Tmm0_BgfcJahhRe2UMypGvSar7IBsr_dQFigepu47R_z6C-G7uVjckQuDNMLdnFj3zo69paqPbUrLBTZiSo3R6o41UEhl6vFDaHDDwp1-0L/s72-c/?imgmax=800" height="72" width="72"/><thr:total>6</thr:total></entry></feed>