tag:blogger.com,1999:blog-76655625871012410082024-03-06T02:54:22.004-05:00Make Your Own PIC12F683 Development BoardAnd Have Fun!Unknownnoreply@blogger.comBlogger15125tag:blogger.com,1999:blog-7665562587101241008.post-83842963122997747592011-06-05T12:22:00.002-04:002011-06-05T12:24:20.584-04:00Add more I/O ports to PIC12F683 with MCP23008 port expanderPIC12F683 microcontroller has got only 6 I/O pins. We saw how to interface a standard character LCD to PIC12F683 using a 74HC595 shift register. The same technique can be implemented for interfacing a seven segment LED display. However, shift registers like 74HC595 allows to add more output ports but not any input port. MCP23008 is a GPIO port expander that can provide additional 8 port pins that can be configured as digital inputs or outputs. This tutorial describes all the details about using MCP23008 with PIC12F683 to expand its I/O capability.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOKndGyW51t7TJ60AkjMoR1Wy6eZ-lJt8Wz9_apg_u8mw5IQvo_LYk-hYwAOfVGj092iyUkJMQc3U68XdUs9zuhwKKS_oIgQbRdb4F_X-sVTGd7r3R7q3bhbCXkJQanbfzIqEe3Jk9bDk/s1600/MCP23008_Output.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="297" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOKndGyW51t7TJ60AkjMoR1Wy6eZ-lJt8Wz9_apg_u8mw5IQvo_LYk-hYwAOfVGj092iyUkJMQc3U68XdUs9zuhwKKS_oIgQbRdb4F_X-sVTGd7r3R7q3bhbCXkJQanbfzIqEe3Jk9bDk/s400/MCP23008_Output.jpg" width="400" /></a></div><a name='more'></a><br />
<br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center><br />
<br />
<div style="text-align: center;"><b><a href="http://embedded-lab.com/blog/?p=2834">Read details of this experiment</a></b></div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7665562587101241008.post-2607714988369846992010-11-28T20:50:00.077-05:002011-06-24T16:09:08.315-04:00Experiment No. 7: Generating Melody with a Microcontroller<b>Introduction</b><br />
This experiment is about generating a melody tune using a PIC microcontroller. Well, this won't be difficult if you know the notes of the tune, and their respective frequencies. Here's a <a href="http://www.phy.mtu.edu/%7Esuits/notefreqs.html"><b>chart</b></a> for note to frequency conversion. We will play the 'Happy Birthday' tune with a PIC12F683 microcontroller. The microcontroller will generate the frequencies of the various notes (with proper timing) in the tune and the melody will be played in a piezoelectric buzzer.<br />
<br />
<b>Circuit Setup</b><br />
The piezo buzzer is connected to the GP2 port of PIC12F683.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuPECfyeaGu-P8Ya1-dgzCbX-uDJZZHVvzkpOVpO_04YCf14oP5LuOtsyj31qYzugUyc5mXawploq-eCqsyKWfxu3lWziAEPZbCL_LLa8mY2Zwb3yF0F02-ZsUig_bFyuoYHUqylz4D0k/s1600/PIC12F683_HBD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuPECfyeaGu-P8Ya1-dgzCbX-uDJZZHVvzkpOVpO_04YCf14oP5LuOtsyj31qYzugUyc5mXawploq-eCqsyKWfxu3lWziAEPZbCL_LLa8mY2Zwb3yF0F02-ZsUig_bFyuoYHUqylz4D0k/s400/PIC12F683_HBD.png" width="400" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiabpWQwuOdzOp4BleaEZJdPZOqe5xF8APcHJigrjfnMrGDG2ic5lwEwjJ2ND06P4KXuC-qIeI7pSR6IXzdm1nHEknM7tlp2OZG81O-WONjXmPmChiRyEayjid4GDX7kURAVGEK0-2T6v8/s1600/DSC00754.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiabpWQwuOdzOp4BleaEZJdPZOqe5xF8APcHJigrjfnMrGDG2ic5lwEwjJ2ND06P4KXuC-qIeI7pSR6IXzdm1nHEknM7tlp2OZG81O-WONjXmPmChiRyEayjid4GDX7kURAVGEK0-2T6v8/s400/DSC00754.JPG" width="400" /></a></div><a name='more'></a><br />
<b>Software</b><br />
<br />
The notes for Happy Birthday tune is like this.<br />
<br />
Happy birthday to you<br />
C4 C4 D4 C4 F4 E4<br />
<br />
Happy birthday to you<br />
C4 C4 D4 C4 G4 F4<br />
<br />
Happy birthday dear xxxx<br />
C4 C4 C5 A4 F4 E4 D4<br />
<br />
Happy birthday to you $$$.<br />
B4b B4b A4 F4 G4 F4 <br />
<br />
By using the <a href="http://www.phy.mtu.edu/%7Esuits/notefreqs.html"><b>chart</b></a>, these notes are first converted into respective frequencies. Then the tones for these frequencies are generated using MikroC's built in sound function, Sound_Play(). The syntax is,<br />
Sound_Play(frequency in Hz, duration in ms). <br />
<br />
<br />
<div style="color: #990000;">/*</div><div style="color: #990000;"> Experiment No. 7: Playing Happy Birthday Tune with PIC12F683</div><div style="color: #990000;"> Compile with MikroC Pro for PIC</div><div style="color: #990000;"> Internal clock @ 4.0 MHz, MCLR disabled, PWRT OFF</div><div style="color: #990000;"><br />
</div><div style="color: #990000;">*/</div><div style="color: #990000;"><br />
</div><div style="color: #990000;">void Delay_100(){</div><div style="color: #990000;"> Delay_ms(100);</div><div style="color: #990000;">}</div><div style="color: #990000;"><br />
</div><div style="color: #990000;">void main() {</div><div style="color: #990000;">CMCON0 = 7;</div><div style="color: #990000;">TRISIO = 0b00001000; // GP5, 5 I/P's, Rest O/P's</div><div style="color: #990000;">GPIO = 0;</div><div style="color: #990000;">Sound_Init(&GPIO,2); // Initialize sound o/p pin</div><div style="color: #990000;"><br />
</div><div style="color: #990000;"><br />
</div><div style="color: #990000;">do {</div><div style="color: #990000;"> </div><div style="color: #990000;"> Sound_Play(262, 400); // Hap</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(262, 400); // Py</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(294, 800); // Birth</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(262, 800); // Day</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(349, 800); // To</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(330, 1000); // You</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> // Another Para</div><div style="color: #990000;"> Sound_Play(262, 400); // Hap</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(262, 400); // Py</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(294, 800); // Birth</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(262, 800); // Day</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(392, 800); // To</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(349, 1000); // You</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> // Another Para</div><div style="color: #990000;"> Sound_Play(262, 400); // Hap</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(262, 400); // Py</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(523, 700); // Birth</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(440, 800); // Day</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(349, 800); // Dear</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(330, 800); // XX</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(294, 700); // XX</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"><br />
</div><div style="color: #990000;"> Sound_Play(466, 400); // Hap</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(466, 400); // Py</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(440, 700); // Birth</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(349, 800); // Day</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(392, 800); // To</div><div style="color: #990000;"> Delay_100();</div><div style="color: #990000;"> Sound_Play(349, 1600); // You $ $ $</div><div style="color: #990000;"> Delay_ms(1000); // Wait for 1 sec and replay</div><div style="color: #990000;"><br />
</div><div style="color: #990000;"> }while(1);</div><div style="color: #990000;">}</div><br />
<b>Output</b><br />
<object height="385" width="480"><param name="movie" value="http://www.youtube.com/v/QncE-MF0jCw?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/QncE-MF0jCw?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br />
<center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>Unknownnoreply@blogger.com8tag:blogger.com,1999:blog-7665562587101241008.post-66070168518495750992010-10-28T21:09:00.002-04:002011-06-24T16:10:21.427-04:00Contact-less tachometer based on PIC16F628A uC<div class="separator" style="clear: both; text-align: left;">Check out my new tachometer project based on PIC16F628A microcontroller. It uses an infrared sensor module to sense the rotation speed of a shaft or disc. The range of measurement is 0-9999 RPM. The full details on hardware and software is available.<b></b></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKvJl5u1vlVi3OrieBnQ_mM_DWKaEq4fBImPpRdNDsNAAT-xz5bN6_bE4jvjYmIiqp-RyOr4RYlMY2bd_38ExSzprmqVWlOEVbSAtKOdkcP0RcIooH1jInfqTBxPESCXO4rd6nFoI86LQ/s1600/DSC00495.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKvJl5u1vlVi3OrieBnQ_mM_DWKaEq4fBImPpRdNDsNAAT-xz5bN6_bE4jvjYmIiqp-RyOr4RYlMY2bd_38ExSzprmqVWlOEVbSAtKOdkcP0RcIooH1jInfqTBxPESCXO4rd6nFoI86LQ/s400/DSC00495.JPG" width="400" /></a></div><a name='more'></a><br />
<br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center><br />
<div style="text-align: right;"><a href="http://pic16f628a.blogspot.com/2010/10/contact-less-tachometer.html"><b>Read detail of the project.</b></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7665562587101241008.post-44859747616703313952010-10-03T17:41:00.003-04:002011-06-24T16:11:08.289-04:000-20V Digital Voltmeter (DVM) using PIC12F683After finishing the <a href="http://picboard.blogspot.com/2010/09/serial-lcd-for-low-pin-count-pic.html">serial LCD project</a>, it is time to do some cool projects using PIC12F683. Now we can have a nice LCD display with PIC12F683. This project shows how to make a digital voltmeter of range 0-20V using PIC12F683. Enjoy!<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqx-VkimUsi_xC8_lUwzfGSa18hEDkoFVHBvO4eaFQSyb4wsXrHfSnHS008U4cfT5YP4um0Qvgs4XXhre3vF-boTky0KRn207wDfZkEhailqM6Fd0UKXRJLlL8gM0gkbevzUZohu0fIh0/s1600/DSC00183.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqx-VkimUsi_xC8_lUwzfGSa18hEDkoFVHBvO4eaFQSyb4wsXrHfSnHS008U4cfT5YP4um0Qvgs4XXhre3vF-boTky0KRn207wDfZkEhailqM6Fd0UKXRJLlL8gM0gkbevzUZohu0fIh0/s400/DSC00183.JPG" width="400" /></a></div><br />
<b>Background</b><br />
You cannot feed 20V directly to a PIC I/O pin, you need a resistor divider network that converts 0-20V range into 0-5V. The figure below shows how it will be achieved.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGYNbh3vPkq0iZwAHMWViknAA42p0N-P3US_LhTJR85zYYYJkCsq_A6LTZ42dNVub21U6Lu_HeXL_g1vdWWb9WemQ6BY7x95Tvug5o89Xyqef2R3l464olnXuZipObFl2JyeTv1vmfMw4/s1600/ResistorNW.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGYNbh3vPkq0iZwAHMWViknAA42p0N-P3US_LhTJR85zYYYJkCsq_A6LTZ42dNVub21U6Lu_HeXL_g1vdWWb9WemQ6BY7x95Tvug5o89Xyqef2R3l464olnXuZipObFl2JyeTv1vmfMw4/s400/ResistorNW.jpg" width="400" /></a></div>At any instant, the voltage Va will be 1/4th of the input voltage, Vin. So, for maximum input voltage of 20V, the Va will be 5V. A 5.1V Zener diode in the figure is to prevent Va to rise above 5.1V if the input voltage goes much above 20V. This will protect the microcontroller port. The analog voltage Va is read through AN0 port and is converted to 10-bit digital number (0-1023) by PIC12F683.<br />
<br />
<a name='more'></a><br />
<b>ADC Math</b><br />
0-5V Analog I/P ---> 0-1023 Digital Count<br />
=> Resolution = (5-0)/(1023-0) = 0.00489 V/Count<br />
=> I/P voltage = 4*Va = 4* Digital Count * 0.00489 = 0.01956 * Digital Count<br />
<br />
To avoid floating point, use I/P voltage = 196*Digital Count. This number is a <b>long</b> integer.<br />
Example, suppose<br />
Vin = 13.6V. Then,<br />
Va = 0.25*Vin = 3.4V<br />
=> Digital Count = 3.4/0.00489 = 695<br />
=> Calculated I/P Voltage = 196*695 = 136220 = 13.6V (First 3 digits of 6 digit product)<br />
<br />
<b>Sources of error</b><br />
The above math looks pretty easy but when you implement it, you will not errors in output measurements because the above calculations are based on following ideal conditions:<br />
<br />
<ul><li><i>Vcc supply voltage to PIC12F683 is exactly 5V,</i></li>
<li><i>R1 and R2 are exact 1.3K and 3.9K respectively</i></li>
</ul><br />
So, let's revise the math above with real figures. I measured the supply voltage to PIC and it is 5.02V. R1 and R2 are measured to be 1267 and 3890 Ohms. So this gives,<br />
<br />
<div style="margin: 0px;"> 0 - 5.02 V Analog I/P ---> 0-1023 Digital Count</div><div style="margin: 0px;">=> Resolution = (5.02-0)/(1023-0) = 0.004907 V/Count</div><div style="margin: 0px;">Va = 1267*Vin/(1267+3890) = 0.2457*Vin</div><div style="margin: 0px;">=> I/P voltage = 4.07*Va = 4.07* Digital Count * 0.004907 </div><div style="margin: 0px;"> = 0.01997 * Digital Count </div><div style="margin: 0px;"> = 0.02*Digital Count (Approx.)</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;">To avoid floating point, use I/P voltage = 2*Digital Count. No need for Long integer.</div><div style="margin: 0px;">Example, suppose </div><div style="margin: 0px;">Vin = 4.6V. Then, </div><div style="margin: 0px;">Va = 0.2457*Vin = 1.13V</div><div style="margin: 0px;">=> Digital Count = 1.13/0.004907 = 230</div><div style="margin: 0px;">=> Calculated I/P Voltage = 2*230 = 0460 = 04.6V (First 3 digits of 4 digit product)</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><b>Circuit Setup</b></div><div style="margin: 0px;">Connect the Va terminal in the above resistor network to AN0 (GP0) input of PIC12F683. Also connect the serial LCD the same way as we did in our 3-wire serial LCD project. Just maintain the same setup for display as shown below.</div><div style="margin: 0px;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1IJVlmTixty-KGZi1yTmyDNCg4pOlqWDy8EfLzJA9TQ3M13kHg26Z_Jw8JXjF_bGakUHTs1c5JqBMyddyfi06zT1fDK7OiDWKbPLcXZrFOI9IREGOwr2xppW1cjEuO0RtLtHIi4d4-Bc/s1600/CircuitSetup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="355" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1IJVlmTixty-KGZi1yTmyDNCg4pOlqWDy8EfLzJA9TQ3M13kHg26Z_Jw8JXjF_bGakUHTs1c5JqBMyddyfi06zT1fDK7OiDWKbPLcXZrFOI9IREGOwr2xppW1cjEuO0RtLtHIi4d4-Bc/s400/CircuitSetup.png" width="400" /></a></div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><b>Software</b></div><div style="margin: 0px;"><br />
/* Digital Voltmeter and<br />
3-wire Serial LCD using 74HC595<br />
Rajendra Bhatt, Oct 3, 2010<br />
*/<br />
<br />
sbit Data_Pin at GP5_bit;<br />
sbit Clk_Pin at GP1_bit;<br />
sbit Enable_Pin at GP2_bit;<br />
<br />
// Always mention this definition statement<br />
unsigned short Low_Nibble, High_Nibble, p, q, Mask, N,t, RS, Flag, temp;<br />
<br />
void Delay_50ms(){<br />
Delay_ms(50);<br />
}<br />
<br />
void Write_LCD_Nibble(unsigned short N){<br />
Enable_Pin = 0;<br />
// ****** Write RS *********<br />
Clk_Pin = 0;<br />
Data_Pin = RS;<br />
Clk_Pin = 1;<br />
Clk_Pin = 0;<br />
// ****** End RS Write<br />
<br />
// Shift in 4 bits<br />
Mask = 8;<br />
for (t=0; t<4; t++){<br />
Flag = N & Mask;<br />
if(Flag==0) Data_Pin = 0;<br />
else Data_Pin = 1;<br />
Clk_Pin = 1;<br />
Clk_Pin = 0;<br />
Mask = Mask >> 1;<br />
}<br />
// One more clock because SC and ST clks are tied<br />
Clk_Pin = 1;<br />
Clk_Pin = 0;<br />
Data_Pin = 0;<br />
Enable_Pin = 1;<br />
Enable_Pin = 0;<br />
}<br />
// ******* Write Nibble Ends<br />
<br />
void Write_LCD_Data(unsigned short D){<br />
RS = 1; // It is Data, not command<br />
Low_Nibble = D & 15;<br />
High_Nibble = D/16;<br />
Write_LCD_Nibble(High_Nibble);<br />
Write_LCD_Nibble(Low_Nibble);<br />
}<br />
<br />
void Write_LCD_Cmd(unsigned short C){<br />
RS = 0; // It is command, not data<br />
Low_Nibble = C & 15;<br />
High_Nibble = C/16;<br />
Write_LCD_Nibble(High_Nibble);<br />
Write_LCD_Nibble(Low_Nibble);<br />
}<br />
<br />
void Initialize_LCD(){<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x20); // Wake-Up Sequence<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x20);<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x20);<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x28); // 4-bits, 2 lines, 5x7 font<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x0C); // Display ON, No cursors<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x06); // Entry mode- Auto-increment, No Display shifting<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x01);<br />
Delay_50ms();<br />
}<br />
<br />
void Position_LCD(unsigned short x, unsigned short y){<br />
temp = 127 + y;<br />
if (x == 2) temp = temp + 64;<br />
Write_LCD_Cmd(temp);<br />
}<br />
<br />
void Write_LCD_Text(char *StrData){<br />
q = strlen(StrData);<br />
for (p = 0; p < q; p++){<br />
temp = StrData[p];<br />
Write_LCD_Data(temp);<br />
}<br />
<br />
}<br />
<br />
char Message1[] = "DVM Project";<br />
unsigned int ADC_Value, DisplayVolt;<br />
char *volt = "00.00";<br />
<br />
void main() {<br />
CMCON0 = 7; // Disable Comparators<br />
TRISIO = 0b00001001; // All Outputs, except GP0 and GP3<br />
ANSEL = 0x01; // GP0 analog i/p<br />
<br />
Initialize_LCD();<br />
Position_LCD(1,3);<br />
Write_LCD_Text(Message1);<br />
Position_LCD(2,10);<br />
Write_LCD_Data('V');<br />
<br />
do {<br />
<br />
ADC_Value = ADC_Read(0);<br />
DisplayVolt = ADC_Value * 2;<br />
<br />
volt[0] = DisplayVolt/1000 + 48;<br />
volt[1] = (DisplayVolt/100)%10 + 48;<br />
volt[3] = (DisplayVolt/10)%10 + 48;<br />
volt[4] = DisplayVolt%10 + 48;<br />
Position_LCD(2,4);<br />
Write_LCD_Text(volt);<br />
delay_ms(100);<br />
} while(1);<br />
<br />
}<br />
<div><br />
</div></div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><b>Testing</b></div><div style="margin: 0px;">I tested my DVM with my variable power supply and also verified with another digital multimeter.</div><div class="separator" style="clear: both; text-align: center;"></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKDkhYaHJv544cGnp0dimyRD4NK9IVhWHE42andDBoEk10zkke7d32phhaSZnTqlAIoXacN3Zt6MEOAGD90PtAPvtZznA50fAJJ4NI8ieO9ceIzO2yVmEfXPi3vJZ4FeQ36LunYEX7rKg/s1600/OutPut.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKDkhYaHJv544cGnp0dimyRD4NK9IVhWHE42andDBoEk10zkke7d32phhaSZnTqlAIoXacN3Zt6MEOAGD90PtAPvtZznA50fAJJ4NI8ieO9ceIzO2yVmEfXPi3vJZ4FeQ36LunYEX7rKg/s400/OutPut.jpg" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgunT81lD4dqOvZgLoYtxElxZZt-5wFzXqWQ_kuEcJS3STpSM-4PeMCugXWs_SwgVmRzv9OwSlahS74ewm-OFppXw0XNOWlTccxAQgdUm83ZDi-NAP8RX_Ii3QoQgoVybGAq1BhYjjLsTA/s1600/Test1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgunT81lD4dqOvZgLoYtxElxZZt-5wFzXqWQ_kuEcJS3STpSM-4PeMCugXWs_SwgVmRzv9OwSlahS74ewm-OFppXw0XNOWlTccxAQgdUm83ZDi-NAP8RX_Ii3QoQgoVybGAq1BhYjjLsTA/s400/Test1.JPG" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpiOVnJzy_qUyfySWzAYcsv5JnoG6lVIyXyGk7_V2ZG-aSJ-yc9SBXiHvZCrp7WOipMuRUCirRmb1eeBAdEQIwpRKJB3R3QeHlk5o3gLHyOFV7GL9Cenrz7LdKt-6vMGxPhqKvZDgDIs8/s1600/Test2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpiOVnJzy_qUyfySWzAYcsv5JnoG6lVIyXyGk7_V2ZG-aSJ-yc9SBXiHvZCrp7WOipMuRUCirRmb1eeBAdEQIwpRKJB3R3QeHlk5o3gLHyOFV7GL9Cenrz7LdKt-6vMGxPhqKvZDgDIs8/s400/Test2.JPG" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="margin: 0px;">I hope you liked this project.</div><br />
I have another version of this project that uses PIC16F688 and no serial LCD driver. If you are interested, find <a href="http://pic16f628a.blogspot.com/2010/10/pic16f688-based-digital-voltmeter.html" target="blank"><b>here</b></a>.<br />
<br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center>Unknownnoreply@blogger.com36tag:blogger.com,1999:blog-7665562587101241008.post-18641892958807769382010-09-27T19:48:00.007-04:002011-06-24T16:13:01.033-04:00Serial LCD for Low Pin-Count PIC Microcontrollers using 74HC595 Shift Register<b>Introduction</b><br />
<br />
<div style="text-align: left;">HD44780 based character LCD displays are very popular among hobbyists. They are easy to interface with microcontrollers and most of the present day high-level compilers have in-built routines for them. However, the bad part is at least 6 I/O pins of microcontroller are required to use them in your project. Therefore, they are not applicable for 8-pin devices like PIC12F series microchips. The aim of this project is to allow LCD interfacing to such devices using 3-wires. I am going to demonstrate this with PIC12F683 microcontroller. The character data or command from the microcontroller will be transferred serially to an 8-bit serial-in parallel-out shift register (74HC595), and the parallel output will be fed to the LCD driver pins.<o:p></o:p></div><div class="MsoNormal" style="text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2cX25XGomfx55CXf_ApN050C-lh-fJfbdO7txOg8Va_2JKA1v4U7MyfL3IkPuEheaP76XcvSKROIRD_iQIK3mNtIldA-6k_ZUvhkB3EHN14wmOeJSrATyyDXoJIhYP40zwHFqNcI3nA/s1600/Output1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2cX25XGomfx55CXf_ApN050C-lh-fJfbdO7txOg8Va_2JKA1v4U7MyfL3IkPuEheaP76XcvSKROIRD_iQIK3mNtIldA-6k_ZUvhkB3EHN14wmOeJSrATyyDXoJIhYP40zwHFqNcI3nA/s400/Output1.JPG" width="400" /></a></div><a name='more'></a><br />
<center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />
<br />
<b>About 74HC595<o:p></o:p></b><br />
<div class="MsoNormal"><br />
74HC595 is a high-speed 8-bit serial in, serial or parallel-out <b>shift register</b> with a <b>storage register</b> and 3-state outputs. The shift register and storage registers have separate clocks, SH_CP and ST_CP respectively. Data in the shift register is shifted on the positive-going transitions of SH_CP, and the content of shift register will be transferred to the storage register on a positive-going transition of the ST_CP. If we tie both the clocks together, the shift register will always be one clock ahead of the storage register. The 8-bit data of the storage register will appear at the parallel output (Q0-Q7) when the output enable (OE) is low.<br />
<br />
</div><div class="separator" style="clear: both; text-align: center;"></div><div class="MsoNormal" style="text-align: center;"><o:p> </o:p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieXJEKiaJE0e0Oj4Mv0I9DsXHCJ90rnqJIJ7SQmwadtDNSdNkhzMycRAJbxbGaICPqanGe33jcJYWQJAsfwYxZgde_BoZ4CvvX2U9i0MHBdpAp7gC0wwT_KoF2uFP4uuoVmjY67jbKEg4/s1600/74HC595.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="243" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieXJEKiaJE0e0Oj4Mv0I9DsXHCJ90rnqJIJ7SQmwadtDNSdNkhzMycRAJbxbGaICPqanGe33jcJYWQJAsfwYxZgde_BoZ4CvvX2U9i0MHBdpAp7gC0wwT_KoF2uFP4uuoVmjY67jbKEg4/s400/74HC595.png" width="400" /></a></div><br />
<div class="MsoNormal" style="text-align: center;"><div style="text-align: left;">In this project, SH_CP and ST_CP are tied together. So, if we want to receive a serially transferred 8-bit into parallel form at Q0-Q7, an extra clock pulse is required after transmitting the 8-th bit of serial data because the clocks are tied and the storage register is 1-clock behind the shift register.</div><div style="text-align: left;"><br />
<b>HD44780-based character LCD</b><br />
<br />
All HD44780 based character LCD displays are connected using 14 wires: 8 data lines (D0-D7), 3 control lines (RS, E, R/W), and three power lines (Vdd, Vss, Vee). Some LCDs may have LED backlight and so they may have additional connections (usually two: LED+ and LED-). <br />
<br />
<b>Pin Description</b><br />
<br />
<i>Control pins</i><br />
The control pin RS determines if the data transfer between the LCD module and an external microcontroller are actual character data or command/status. When the microcontroller needs to send commands to LCD or to read LCD status, it must be pulled low. Similarly, this must be pulled high if character data is to be sent to and from the LCD module.<br />
<br />
The direction of data transfer is controlled by the R/W pin. If it is pulled Low, the commands or character data is written to the LCD module. And, when it is pulled high, the character data or status information from the LCD registers is read. In this project, we will use one way data transfer, i.e., from microcontroller to LCD module, so the R/W pin will be grounded permanently.<br />
<br />
The enable pin (E) initiates the actual data transfer. When writing to the LCD display, the data is transferred only on the high to low transition of the E pin.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_VAVwRhSpOAFHTcuq675TynQiG1aHEj25oOmTU6_PncM11vVOThq6LD_6KCDfglv1D7-ytcdbbIjeXQI_Nv2TD3C8yJXat5XDdT599wPHRP6eJkzOKdHOoZBJ8NTqicsY-3efsB_TVKE/s1600/LCD+Pins.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_VAVwRhSpOAFHTcuq675TynQiG1aHEj25oOmTU6_PncM11vVOThq6LD_6KCDfglv1D7-ytcdbbIjeXQI_Nv2TD3C8yJXat5XDdT599wPHRP6eJkzOKdHOoZBJ8NTqicsY-3efsB_TVKE/s400/LCD+Pins.JPG" width="400" /></a></div><i><br />
</i><br />
<i>Power supply pins</i><br />
Although most of the LCD module data sheets recommend +5V d.c. supply for operation, some LCDs may work well for a wider range (3.0 to 5.5 V). The Vdd pin should be connected to the positive power supply and Vss to ground. Pin 3 is Vee, which is used to adjust the contrast of the display. In most of the cases, this pin is connected to a voltage between 0 and 2V by using a preset potentiometer.<br />
<br />
<i>Data pins</i><br />
Pins 7 to 14 are data lines (D0-D7). Data transfer to and from the display can be achieved either in 8-bit or 4-bit mode. The 8-bit mode uses all eight data lines to transfer a byte, whereas, in 4-bit mode, a byte is transferred as two 4-bit nibbles. In the later case, only the upper 4 data lines (D4-D7) are used. This technique is beneficial as this saves some input/output pins of microcontroller.<br />
<br />
</div><div style="text-align: left;">For further details on LCDs, I recommend to read these two articles first from Everyday Practical Electronics magazine : How to use intelligent LCDs <br />
Part 1: http://lcd-linux.sourceforge.net/pdfdocs/lcd1.pdf<br />
Part 2. http://lcd-linux.sourceforge.net/pdfdocs/lcd2.pdf<br />
<br />
<b>Circuit Diagram</b><br />
<span class="Apple-style-span">The hardware part of this project is fairly simple. The challenging part is to write the driver software that is responsible for a proper sequence of operations required to serially transfer character data and command to 74HC595 serial-in parallel-out shift register. The shift register parallel output is then connected to LCD data lines (D4-D7) and RS control pin. This arrangement requires 3-pins of microcontroller to display character data on a parallel LCD display: 2 pins for providing Clock and Data to 74HC595, and 1 pin for enable control (E) pin of LCD module. Since the data transfer uses 4-bit mode, any 8-bit command or character data is sent in two steps: send the higher nibble first, and then the lower nibble. The R/W control pin is grounded, and therefore no data or status read from the LCD module is possible in this case. </span></div></div><div style="text-align: left;"><br />
</div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtq5FVLHTfs_My7c9DXKoCd237OyKMRBQGPNNOz2SFLnjJblrsgroW2a5FEGytk0r_xbIaSRsRxqeITjBHvgjz74fdab1gLJ9CgK1MYmOX2YI6-18y1EWUlY-70qEDwSlG9Sikf1UDLJA/s1600/74HC595.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="325" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtq5FVLHTfs_My7c9DXKoCd237OyKMRBQGPNNOz2SFLnjJblrsgroW2a5FEGytk0r_xbIaSRsRxqeITjBHvgjz74fdab1gLJ9CgK1MYmOX2YI6-18y1EWUlY-70qEDwSlG9Sikf1UDLJA/s400/74HC595.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"></div><div class="MsoNormal">The SH_CP (11) and ST_CP (12) clock inputs of 75HC595 are tied together, and will be driven by one microcontroller pin. Serial data from microcontroller is fed to the shift register through DS (14) pin. OE (13) pin is grounded and reset pin MR (10) is pulled high. Parallel outputs Q0-Q3 from 74HC595 are connected to D4-D7 pins of the LCD module. Similarly, Q4 output serves for RS control pin. If the LCD module comes with a built-in backlight LED, it can simply be turned ON or OFF through LED control pin shown above. Pulling the LED pin to logic high will turn the back light ON. I soldered this circuit on a general prototyping board (shown below).<o:p></o:p></div><br />
<br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2cX25XGomfx55CXf_ApN050C-lh-fJfbdO7txOg8Va_2JKA1v4U7MyfL3IkPuEheaP76XcvSKROIRD_iQIK3mNtIldA-6k_ZUvhkB3EHN14wmOeJSrATyyDXoJIhYP40zwHFqNcI3nA/s1600/Output1.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br />
</a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2cX25XGomfx55CXf_ApN050C-lh-fJfbdO7txOg8Va_2JKA1v4U7MyfL3IkPuEheaP76XcvSKROIRD_iQIK3mNtIldA-6k_ZUvhkB3EHN14wmOeJSrATyyDXoJIhYP40zwHFqNcI3nA/s1600/Output1.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br />
</a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2cX25XGomfx55CXf_ApN050C-lh-fJfbdO7txOg8Va_2JKA1v4U7MyfL3IkPuEheaP76XcvSKROIRD_iQIK3mNtIldA-6k_ZUvhkB3EHN14wmOeJSrATyyDXoJIhYP40zwHFqNcI3nA/s1600/Output1.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br />
</a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2cX25XGomfx55CXf_ApN050C-lh-fJfbdO7txOg8Va_2JKA1v4U7MyfL3IkPuEheaP76XcvSKROIRD_iQIK3mNtIldA-6k_ZUvhkB3EHN14wmOeJSrATyyDXoJIhYP40zwHFqNcI3nA/s1600/Output1.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br />
</a></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOur87VHYRjy5txFCn7sf6eSDljn1O8BN0si1k1ibJ9yE0lMjmhPKjBbJOXNhWUbT-3Qv0kCwtrGGxnC5-l88eFOapKlcCTerzrXrHiAOlVaTSWCulTp20-UA-ZkNUtrw-MWck85yA2_s/s1600/CircuitBoard.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="color: black;"></span></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOur87VHYRjy5txFCn7sf6eSDljn1O8BN0si1k1ibJ9yE0lMjmhPKjBbJOXNhWUbT-3Qv0kCwtrGGxnC5-l88eFOapKlcCTerzrXrHiAOlVaTSWCulTp20-UA-ZkNUtrw-MWck85yA2_s/s1600/CircuitBoard.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="235" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOur87VHYRjy5txFCn7sf6eSDljn1O8BN0si1k1ibJ9yE0lMjmhPKjBbJOXNhWUbT-3Qv0kCwtrGGxnC5-l88eFOapKlcCTerzrXrHiAOlVaTSWCulTp20-UA-ZkNUtrw-MWck85yA2_s/s400/CircuitBoard.JPG" width="400" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguPhu4gAnGGK8cK3dYsC55yITWMrjraYJAx7OfF-J96sMHJ5q2h2R5cT0qCN2judCVgRsF4IJ4rE6Aor5lfm3tYGw91OuZYf4c_uGW-vrJTi6InHDSo6lmlVycCisQ51tQpTzIxFLiPxE/s1600/CircuitBoardwithLCD2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguPhu4gAnGGK8cK3dYsC55yITWMrjraYJAx7OfF-J96sMHJ5q2h2R5cT0qCN2judCVgRsF4IJ4rE6Aor5lfm3tYGw91OuZYf4c_uGW-vrJTi6InHDSo6lmlVycCisQ51tQpTzIxFLiPxE/s400/CircuitBoardwithLCD2.JPG" width="400" /></a></div><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_468x15, created 9/27/10 */
google_ad_slot = "8355620411";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script><br />
<br />
<div class="MsoNormal"><b>Software<o:p></o:p></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">A bit of data fed to DS pin of 74HC595 appears at Q0 output after 2 clocks (because SH_CP and ST_CP are tied). So, sending 4-bit data (D4-D7) and an RS signal require 6 clock pulses till they appear at Q0-Q4 outputs respectively. When the LCD module is turned ON, it is initialized in 8-bit mode. A number of initializing commands should be sent to operate the LCD module in 4-bit mode. All the driver routines that are discussed here are written in mikroC compiler. They work only for a 16x2 LCD module. User can modify the initialization operations inside the Initialize_LCD() routine to account for other LCD configurations. The driver routines and their functions are described below.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings;">l<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><span class="Apple-style-span" style="font-size: medium;"> </span></span></span>Initialize_LCD() : It initializes the LCD module to operate into 4-bit mode, 2 lines display, 5x7 size</div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"> character, display ON, and no cursor.<o:p></o:p></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings;">l<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><span class="Apple-style-span" style="font-size: medium;"> </span></span></span>Write_LCD_Data() : Sends a character byte to display at current cursor position.<o:p></o:p></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings;">l<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><span class="Apple-style-span" style="font-size: medium;"> </span></span></span>Write_LCD_Cmd() : Write a command byte to the LCD module.<o:p></o:p></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings;">l<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><span class="Apple-style-span" style="font-size: medium;"> </span></span></span>Write_LCD_Nibble() : Data or command byte is sent to the LCD module as two nibbles. So this function</div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"> routine takes care for sending the nibble data to the LCD module.<o:p></o:p></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings;">l<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><span class="Apple-style-span" style="font-size: medium;"> </span></span></span>Write_LCD_Text() : This routine is for sending a character string to display at current cursor position.<o:p></o:p></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings;">l<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><span class="Apple-style-span" style="font-size: medium;"> </span></span></span>Position_LCD() : To change the current cursor position. <o:p></o:p></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><br />
</div><div class="MsoNormal">At the beginning of your program, you need to define Data_Pin, Clk_Pin, and Enable_Pin to the chosen microcontroller ports. I am going to demonstrate here how to use these driver routines to display two blinking character strings, Message1 and Message2, at different locations. I am going to test our serial LCD module with a PIC12F683 microcontroller. The test circuit is shown below.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b>Note:</b> My PIC12F683 Settings<o:p></o:p></div><div class="MsoNormal">Running at 4 MHz internal clock, MCLR disabled, WDT OFF.<o:p></o:p></div><div class="MsoNormal">Clock, Data, and Enable lines are served through GP1, GP5, and GP2 ports. <o:p></o:p></div><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRfJNRFXccG82_7UOVi6dMCxB-2_sc61aiWOg3OQWXoJDwSWCAaV_LUhlgmqHPS6GN6s5c2oS115jegdA6HCQ9LMZeaS3Iy10AtMFAbFSwt4o-sNVUUHozgaz8ROxlAezX6dCokh0sQfE/s1600/TestCircuit.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRfJNRFXccG82_7UOVi6dMCxB-2_sc61aiWOg3OQWXoJDwSWCAaV_LUhlgmqHPS6GN6s5c2oS115jegdA6HCQ9LMZeaS3Iy10AtMFAbFSwt4o-sNVUUHozgaz8ROxlAezX6dCokh0sQfE/s400/TestCircuit.png" width="400" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDIZOEg6AwdZOhkCL-CTGFaqEJp4_P88i0jk8tulqFMpmHZg5MkkUDgauNdbqlFc1BHXQDZ1l68N36miVelI13Ytdqg61X4kHdvCe4mYRX-xlM5y_HX7_0k-cN0YK7kMHHiu59xofjqwQ/s1600/TestCircuit.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDIZOEg6AwdZOhkCL-CTGFaqEJp4_P88i0jk8tulqFMpmHZg5MkkUDgauNdbqlFc1BHXQDZ1l68N36miVelI13Ytdqg61X4kHdvCe4mYRX-xlM5y_HX7_0k-cN0YK7kMHHiu59xofjqwQ/s400/TestCircuit.JPG" width="400" /></a></div><br />
<br />
<span style="color: #cc0000;">This must be compiled with MikroC Pro for PIC from MikroElektronika. </span><br />
<br />
/* 3-wire Serial LCD using 74HC595<br />
Rajendra Bhatt, Sep 6, 2010<br />
*/<br />
<br />
sbit Data_Pin at GP5_bit;<br />
sbit Clk_Pin at GP1_bit;<br />
sbit Enable_Pin at GP2_bit;<br />
<br />
// Always mention this definition statement<br />
unsigned short Low_Nibble, High_Nibble, p, q, Mask, N,t, RS, Flag, temp;<br />
<br />
void Delay_50ms(){<br />
Delay_ms(50);<br />
}<br />
<br />
void Write_LCD_Nibble(unsigned short N){<br />
Enable_Pin = 0;<br />
// ****** Write RS *********<br />
Clk_Pin = 0;<br />
Data_Pin = RS;<br />
Clk_Pin = 1;<br />
Clk_Pin = 0;<br />
// ****** End RS Write<br />
<br />
// Shift in 4 bits<br />
Mask = 8;<br />
for (t=0; t<4; t++){<br />
Flag = N & Mask;<br />
if(Flag==0) Data_Pin = 0;<br />
else Data_Pin = 1;<br />
Clk_Pin = 1;<br />
Clk_Pin = 0;<br />
Mask = Mask >> 1;<br />
}<br />
// One more clock because SC and ST clks are tied<br />
Clk_Pin = 1;<br />
Clk_Pin = 0;<br />
Data_Pin = 0;<br />
Enable_Pin = 1;<br />
Enable_Pin = 0;<br />
}<br />
// ******* Write Nibble Ends<br />
<br />
void Write_LCD_Data(unsigned short D){<br />
RS = 1; // It is Data, not command<br />
Low_Nibble = D & 15;<br />
High_Nibble = D/16;<br />
Write_LCD_Nibble(High_Nibble);<br />
Write_LCD_Nibble(Low_Nibble);<br />
}<br />
<br />
void Write_LCD_Cmd(unsigned short C){<br />
RS = 0; // It is command, not data<br />
Low_Nibble = C & 15;<br />
High_Nibble = C/16;<br />
Write_LCD_Nibble(High_Nibble);<br />
Write_LCD_Nibble(Low_Nibble);<br />
}<br />
<br />
void Initialize_LCD(){<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x20); // Wake-Up Sequence<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x20);<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x20);<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x28); // 4-bits, 2 lines, 5x7 font<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x0C); // Display ON, No cursors<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x06); // Entry mode- Auto-increment, No Display shifting<br />
Delay_50ms();<br />
Write_LCD_Cmd(0x01);<br />
Delay_50ms();<br />
}<br />
<br />
void Position_LCD(unsigned short x, unsigned short y){<br />
temp = 127 + y;<br />
if (x == 2) temp = temp + 64;<br />
Write_LCD_Cmd(temp);<br />
}<br />
<br />
void Write_LCD_Text(char *StrData){<br />
q = strlen(StrData);<br />
for (p = 0; p<q; p++){<br />
temp=StrData[p]; <br />
write_lcd_data(temp);<br />
}<br />
}<br />
<br />
char Message1[] = "3-Wire LCD";<br />
char Message2[] = "using 74HC595";<br />
<br />
void main() {<br />
CMCON0 = 7; // Disable Comparators<br />
TRISIO = 0b00001000; // All Outputs except GP3<br />
ANSEL = 0x00; // No analog i/p<br />
<br />
Initialize_LCD();<br />
<br />
do {<br />
Position_LCD(1,4);<br />
Write_LCD_Text(Message1);<br />
Position_LCD(2,2);<br />
Write_LCD_Text(Message2);<br />
Delay_ms(1500);<br />
Write_LCD_Cmd(0x01); // Clear LCD<br />
delay_ms(1000);<br />
} while(1);<br />
<br />
}<br />
<div><br />
</div><br />
<div class="MsoNormal"><span class="Apple-style-span" style="color: blue;"><b><span style="font-size: 11pt;">Output<o:p></o:p></span></b></span></div><div class="MsoNormal"><span class="Apple-style-span" style="color: blue;"><b><span style="font-size: 11pt;"><br />
</span></b></span></div><span class="Apple-style-span" style="color: blue;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="color: blue;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidXHVeQ3DST7eyTCfv7iqinvlJcUMlKuyE2dx8YPA_Ziac2ZCrV1m0oGX6FNEncWPyoxp-4dOcllwHpuNFjGtIqUEgY_pGfzy3ZRmvAoABI4TZOjtuLztNx8PsJMG6IeKu62R570HH0js/s1600/Output2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidXHVeQ3DST7eyTCfv7iqinvlJcUMlKuyE2dx8YPA_Ziac2ZCrV1m0oGX6FNEncWPyoxp-4dOcllwHpuNFjGtIqUEgY_pGfzy3ZRmvAoABI4TZOjtuLztNx8PsJMG6IeKu62R570HH0js/s400/Output2.JPG" width="400" /></a></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="color: blue;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="color: blue;"><b>Reference:</b></span></div><div class="separator" style="clear: both; text-align: left;"></div><ul style="color: blue;"><li><span class="Apple-style-span"><i>How to use Intelligent Liquid Crystal Displays, by Julyan Ilett, (February, March 1997 EPE)</i></span></li>
<span class="Apple-style-span">
<li><i>Two-wire LCD:ATM18 display for the Elektor AVR Project, by Jurss and Rudolph, (elektor -5/2008)</i></li>
</span></ul>Unknownnoreply@blogger.com31tag:blogger.com,1999:blog-7665562587101241008.post-19228472921523528242010-09-25T17:39:00.001-04:002011-06-24T16:14:01.002-04:00Experiment No. 6: PIC12F683 Timer1 used as a Frequency Counter<b>Objective: </b><i>Determine the frequency of an external clock source (0-65535 Hz), send it to PC through serial port, and display it on a hyperterminal application window. </i><br />
<br />
<b>Introduction</b><br />
<br />
The Timer1 module in PIC12F683 is a 16-bit timer/counter. It can operate as Timer or as a synchronous/asynchronous counter. In asynchronous mode, the Timer1 will increment at the arrival of each external clock pulse at T1CKI port. Whereas, in synchronous mode the input clock pulse to Timer1 module is synchronized to the microcontroller internal clock. A dedicated control register, T1CON, is available to set-up and control the Timer1 module. We are going to use the counter feature of it to measure the frequency of an external clock source. The Timer1 register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. When Timer1 rolls over, it indicates timer overflow by setting Timer1 interrupt flag (TMR1IF) bit of PIR1 register. To enable the interrupt on rollover, following bits must be set:<br />
<ul><li>Timer1 interrupt enable (TMR1IE) bit of PIE1 register (PIE1 = 01h could do that)</li>
<li>PEIE and GIE bits of the INTCON register (INTCON = C0h could do that) </li>
</ul>Since the 16-bit counter can count up to 65535, the external clock source with frequency higher than this will overflow the Timer1 counter, and generate the Timer1 overflow interrupt. The external clock source will be obtained from a 555 Timer IC operating as an astable multivibrator, and will be fed to GP5/T1CKI pin (2) of PIC12F683. Once I made a 555 experiment board for myself, I am going to use the same. In this board I can vary the frequency of the multivibrator using a potentiometer. Search internet for more detail on 555 astable multivibrator.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg97r2b15BZhuWk5owQYRI2Eb74YyhKD9YLyZmAObqfRJJfq37u_VrWW7rY03ECG3DbP5_hDN2WuSQSjvzTYT73gCWvHVIXOKIp7zCwV9-g0uGN-WTgD89Y_4bS03-cVZvOx-5iXQncg_w/s1600/555Circuit.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="250" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg97r2b15BZhuWk5owQYRI2Eb74YyhKD9YLyZmAObqfRJJfq37u_VrWW7rY03ECG3DbP5_hDN2WuSQSjvzTYT73gCWvHVIXOKIp7zCwV9-g0uGN-WTgD89Y_4bS03-cVZvOx-5iXQncg_w/s400/555Circuit.JPG" width="400" /></a></div><div style="text-align: center;"><span style="font-size: x-small;"><b>My 555 Timer IC Experiment Board</b></span></div><br />
<a name='more'></a><br />
Since, we need to determine the frequency of an external clock source, we will use Timer1 as an <i>asynchronous counter</i>. This requires proper setting of T1CON register bits shown below.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_FyIKepNaIHuOF9GzCpVxdpMD0ItYd0Z-gMuk-8ONS638qbN03CRNN9gqDsyfYMS6faLIxnMgDaGlYTH-jF1KV6KRbnz9CS_JcYzvK4_VXzwLsXoqd_T2zIWOUgNibe2FF9EQfnVInjM/s1600/T1CON.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="375" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_FyIKepNaIHuOF9GzCpVxdpMD0ItYd0Z-gMuk-8ONS638qbN03CRNN9gqDsyfYMS6faLIxnMgDaGlYTH-jF1KV6KRbnz9CS_JcYzvK4_VXzwLsXoqd_T2zIWOUgNibe2FF9EQfnVInjM/s400/T1CON.PNG" width="400" /></a></div><br />
So, for our purpose, we are going to set T1SYNC, TMRCS, and TMR1ON bits to turn the Timer1 counter ON and clear TMR1ON to stop the counter.<br />
<br />
<b>PIC12F683 Port Settings</b><br />
<br />
GP5/T1CKI : Feed + 5V peak external clock source (input)<br />
GP4 : Serial data transfer to PC (output)<br />
GP3 : Serial data receive from PC (input, not used but needed to be defined while using software UART library routines of mikroC) <br />
This gives TRISIO = 28h<br />
<br />
<b>Programming Sequence</b><br />
<br />
<ol><li>Disable comparator inputs (CMCON0 = 07h).</li>
<li>Define TRISIO = 28h.</li>
<li>Disable analog inputs (ANSEL = 00h).</li>
<li>Enable GIE and PEIE interrupts (INTCON = C0h).</li>
<li>Enable TMR1 interrupt (PIE1 = 01h). </li>
<li>Initialize software UART, 9600 baud at GP4 port.</li>
<li>Do {</li>
</ol> TMR1H = 00, TMR1L = 00,<br />
Start Timer1 (T1CON = 7)<br />
Wait 1 sec<br />
Stop Timer1 (T1CON = 6)<br />
If Timer1 overflow, send message "Frequency Out of Range" and clear TMR1IF flag<br />
Else,<br />
Frequency = (TMR1H << 8) + TMR1L<br />
Display Frequency<br />
<br />
} While (1) <br />
<br />
<b>Experimental Setup</b><br />
<br />
Connect uTx pin to GP4 port, and external clock source to GP5 port. Also connect Rx, Tx, and Gnd pins to corresponding pins of RS232 port of PC. Open a new hyperterminal window with following settings:<br />
<ol><ol><ul><li>bps : 9600</li>
<li>Databits: 8</li>
<li>Parity : None</li>
<li>Stop Bits : 1</li>
<li>Flow Control : Hardware</li>
</ul></ol></ol><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIte6-_NFLjgeanrsEFU6sixpmGiVgQEjm5GlbMQkSEwtG-KYM3igdagmDIsrX0c-lQUftv6yeO9kiA-H7UXQpdgkOTPtwZ5s5FxtUC2s1ykCLDj2g8ptFE6Rb7j-vyWs2koOYX6MHzXI/s1600/SetUp.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIte6-_NFLjgeanrsEFU6sixpmGiVgQEjm5GlbMQkSEwtG-KYM3igdagmDIsrX0c-lQUftv6yeO9kiA-H7UXQpdgkOTPtwZ5s5FxtUC2s1ykCLDj2g8ptFE6Rb7j-vyWs2koOYX6MHzXI/s400/SetUp.JPG" width="400" /> </a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><br />
</div> <b>Software</b><br />
<div style="color: blue;"><br />
</div><div style="color: #cc0000;">/*<br />
PIC12F683 Experiment Board<br />
Experimen No. 6 : Frequency Counter 0-65535 Hz<br />
display on Hyperterminal window on PC using Software UART.<br />
Date: 09/25/2010<br />
Clock input to Timer1 (GP5, pin 2, input)<br />
UART Tx = GP4, pin 3, output; output; RX = GP3, input<br />
*/<br />
char Message1[] = "Frequency (Hz) =";<br />
char Message2[] = "Frequency Over Range";<br />
unsigned int frequency, backup=0 ;<br />
char *temp = "00000", error;<br />
unsigned short i, TMR1_OverFlow=0;<br />
<br />
void LineFeed(){<br />
Soft_UART_Write(10); // Line Feed<br />
Soft_UART_Write(13); // Carriage Return<br />
}<br />
<br />
void interrupt(void){<br />
if(PIR1.TMR1IF) {<br />
TMR1_OverFlow = 1;<br />
PIR1.TMR1IF = 0;<br />
}<br />
}<br />
<br />
void main() {<br />
CMCON0 = 7; // Disable comparators<br />
TRISIO = 0b00101000; // GP3, and 5 Inputs; Rest are O/Ps<br />
ANSEL = 0x00; // No analog inputs<br />
GPIO = 0;<br />
INTCON = 0b11000000 ; // Enable GIE and PEIE for Timer1 overflow interrpt<br />
PIE1 = 0b00000001 ; // Enable TMR1IE<br />
<br />
// Define GPIO.3 as UART Rx, and 4 as Tx<br />
error = Soft_UART_Init(&GPIO,3, 4, 9600, 0 );<br />
Delay_ms(100);<br />
<br />
do {<br />
TMR1H = 0x00;<br />
TMR1L = 0x00;<br />
T1CON = 0b00000111; // Enable Timer 1<br />
Delay_ms(1000);<br />
T1CON = 0b00000110; // Disable Timer 1<br />
frequency = TMR1H;<br />
frequency = frequency << 8 ;<br />
frequency = frequency + TMR1L ;<br />
<br />
if(TMR1_OverFlow){<br />
for (i=0; i<= 19; i++) {<br />
Soft_UART_Write(Message2[i]);<br />
Delay_ms(50);<br />
}<br />
LineFeed();<br />
TMR1_OverFlow = 0;<br />
}<br />
else {<br />
if(frequency != backup) {<br />
<br />
temp[0] = frequency/10000 + 48;<br />
temp[1] = (frequency/1000)%10 + 48;<br />
temp[2] = (frequency/100)%10 + 48;<br />
temp[3] = (frequency/10)%10 + 48;<br />
temp[4] = frequency%10 + 48;<br />
for (i=0; i<= 15; i++) {<br />
Soft_UART_Write(Message1[i]);<br />
Delay_ms(50);<br />
}<br />
for (i=0; i<= 4; i++) {<br />
Soft_UART_Write(temp[i]);<br />
Delay_ms(50);<br />
}<br />
LineFeed();<br />
}<br />
}<br />
<br />
delay_ms(100);<br />
backup = frequency;<br />
} while(1);<br />
}</div><br />
<b>Output</b><br />
<br />
My 555 timer board can generate frequency from approximately 1 KHz to over 100 KHz by a varying 100K potentiometer. Here's a snapshot of few frequency measurements shown on the hyperterminal window. <br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVfJD_plprU4mpeEeoedXZI-2rHp4sRimIgPCJYGaKU038G8VJzP21TCz-vbWW3XJUFEa0HI_TIaBtInBW4F3ukx33m6jA_Rwt2Xb0MdoNN661D2A7BHhrkUUGWwSAFrJuh_woSbCHSUg/s1600/HyperTerminal.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="313" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVfJD_plprU4mpeEeoedXZI-2rHp4sRimIgPCJYGaKU038G8VJzP21TCz-vbWW3XJUFEa0HI_TIaBtInBW4F3ukx33m6jA_Rwt2Xb0MdoNN661D2A7BHhrkUUGWwSAFrJuh_woSbCHSUg/s400/HyperTerminal.JPG" width="400" /></a></div><br />
<b>Application of this idea</b><br />
<br />
<i>You can extend this idea to make a frequency counter of higher range. Higher frequency measurements can be achieved by incrementing a user defined variable (say X) every time the Timer1 overflows. At the end of 1 sec gate interval, you can compute the frequency as 65535*X + current Timer1 value. </i><br />
<br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7665562587101241008.post-42263827912521600292010-08-27T11:54:00.001-04:002011-06-24T16:15:43.895-04:00A Versatile Temperature Data Logger using PIC12F683 and DS1820<b>Introduction</b><br />
There are varieties of digital temperature logger projects available online based on different microcontrollers. The one I am going to talk about is based on a Microchip's 8-pin microcontroller, PIC12F683. It reads temperature values from a DS1820 digital sensor and stores in its internal EEPROM. PIC12F683 has 256 bytes of internal EEPROM and we are going to store the temperature values in 8-bit format. This means only the eight most significant bits of temperature data from DS1820 will be read and as such the temperature resolution will be of 1 degree C.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixwGxhfNl9LnPYPjQmgCPAsCsHo5x3n8zIxejx5UJc6qZHIVbhxySVmsRGZww6eYOQc8wjB3dAu6iL0MvkG7Y6qxA-rXGr2dFISP3jxmOw_kGz-jFKo0dI7VlFP_VwCQ-4VKQBkZx68Tc/s1600/LEDBlinks.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="231" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixwGxhfNl9LnPYPjQmgCPAsCsHo5x3n8zIxejx5UJc6qZHIVbhxySVmsRGZww6eYOQc8wjB3dAu6iL0MvkG7Y6qxA-rXGr2dFISP3jxmOw_kGz-jFKo0dI7VlFP_VwCQ-4VKQBkZx68Tc/s400/LEDBlinks.JPG" width="400" /></a></div><br />
My temperature logger has following features:<br />
<ul><li>Reads temperature from a DS1820 sensor and stores in the internal EEPROM locations.</li>
<li>Can store up to 254 temperature values. EEPROM location 0 is used to store the sampling interval, and location 1 is used to store the number of records.</li>
<li>Three sampling interval options: 1 sec, 1 min, and 10 min. This can be selected during powering up.</li>
<li>Start and Stop buttons for control operations.</li>
<li>The recorded temperature values can be sent to PC through a serial port. A separate Send button is available to initiate data transfer.</li>
<li>A LED to indicate various ongoing operations.</li>
<li>Reset button to clear all previous records. </li>
</ul><br />
<div><b><a name='more'></a>Circuit Design</b></div><div>PIC12F683 has 6 I/O pins, out of which one (GP3, pin 4) is I/P only pin. Here is how we are going to assign the port pins.</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlIcnTlUpfo9Gwv-hlXvW4QeFrJowL5gh_6Bc6a4FjpRS1WCUeS-U32b7mywttF4Nx8KHgvnD2I6Ghhe5LSt4l4DfgQKk4A2ZqzeXP735gq21HnFrDbbIIr2YlIa63SOqj3fJtvQ-Ys8/s1600/Picture+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="107" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlIcnTlUpfo9Gwv-hlXvW4QeFrJowL5gh_6Bc6a4FjpRS1WCUeS-U32b7mywttF4Nx8KHgvnD2I6Ghhe5LSt4l4DfgQKk4A2ZqzeXP735gq21HnFrDbbIIr2YlIa63SOqj3fJtvQ-Ys8/s400/Picture+7.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"></div><div style="margin-bottom: 0in;">The six I/O pins of PIC12F683 are assigned as follows:</div><div style="margin-bottom: 0in;">1. GP0 (Pin 7, I/P): This pin will be used to read the temperature value from DS1820 sensor.</div><div style="margin-bottom: 0in;">2. GP1 (Pin 6, O/P): This will be used for serial data transfer to a PC.</div><div style="margin-bottom: 0in;">3. GP2 (Pin 5, O/P): LED output pin.</div><div style="margin-bottom: 0in;">4. GP3 (Pin 4, I/P): Send (tactile switch)</div><div style="margin-bottom: 0in;">5. GP4 (Pin 3, I/P): Stop (tactile switch)</div><div style="margin-bottom: 0in;">6. GP5 (Pin 2, I/P): Start (tactile switch) </div><div style="margin-bottom: 0in;"><br />
</div><div style="margin-bottom: 0in;">A simple transistor based level shifting will be used to convert the TTL voltage from PIC12F683 to appropriate RS232 level for serial data transfer to PC. The required negative voltage is derived from PC RS232 port pin 3 (Tx), which remains idle as no data transfer occurs from PC to PIC. I soldered all the components on a general-purpose prototyping board. Besides, my finished product runs on 3-AAA batteries with a diode in series for reverse polarity protection. I also have a power switch on the board. The PIC uses internal oscillator at 4MHz, and MCLR is disabled.</div><div style="margin-bottom: 0in;"><br />
</div><div style="margin-bottom: 0in;"><b>List of Components</b></div><ul><li><br />
<div style="margin-bottom: 0in;">PIC12F683 microcontroller</div></li>
<li><br />
<div style="margin-bottom: 0in;">DS1820 temperature sensor</div></li>
<li><br />
<div style="margin-bottom: 0in;">BC557 NPN transistor</div></li>
<li><br />
<div style="margin-bottom: 0in;">Resistors: 10K (4), 4.7K (2), 470 Ohm (1) </div></li>
<li><br />
<div style="margin-bottom: 0in;">Capacitor: 10uF, 50V (1)</div></li>
<li><br />
<div style="margin-bottom: 0in;">LED (1)</div></li>
<li><br />
<div style="margin-bottom: 0in;">Tact switches (3)</div></li>
</ul><div style="margin-bottom: 0in;"><b>Software</b></div><div style="margin-bottom: 0in;">The firmware is written in C and compiled with mikroC compiler from MikroElektronika. I used the free version of it because our HEX output is going to be less than 2K. The download link for mikroC is <span style="color: blue;"><u><a href="http://www.mikroe.com/eng/downloads/get/29/mikroc_pro_pic_2010_v380_setup.zip">http://www.mikroe.com/eng/downloads/get/29/mikroc_pro_pic_2010_v380_setup.zip</a></u></span></div><div style="margin-bottom: 0in;"><br />
</div><div style="margin-bottom: 0in;">The 3 user input switches work on <i>interrupt-on-change</i> mode. That means any time the user presses any button, an interrupt is generated except at times when the microcontroller is reading temperature values from DS1820 (which is instantaneous) and when it is transferring data to a PC through serial port. The interrupts are disabled at those instants. The data transfer takes place at 9600 baud rate. You can write your own software to receive data on PC side, but I have used the Hyperterminal application for this purpose. My Hyperterminal settings are</div><div style="margin-bottom: 0in;">bps : 9600, Data Bits: 8, Parity : None, Stop Bits : 1, Flow Control : Hardware</div><div style="margin-bottom: 0in;"><b>Configuration: </b>Internal clock @ 4 MHz, MCLR Disabled, WDT OFF</div><br />
<div class="separator" style="clear: both; text-align: center;"></div><div><div class="separator" style="clear: both; text-align: center;"><a href="http://www.electronics-lab.com/projects/test/012/Schematic.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="268" src="http://www.electronics-lab.com/projects/test/012/Schematic.png" width="400" /></a></div></div><br />
<div><br />
As I mentioned earlier, the sampling time of the data logger is selectable to 1 sec (this is for test purpose), 1 min, or 10 min. With 10 min sampling time, 254 EEPROM locations would provide temperature logging for 42 hours. Each of the three buttons (Start, Stop, and Send) provide more than one function. For example, if you keep pressing the "Send" button for more than 2 sec, you are going to reset the system, which means all the past recorded values will be erased and the default sampling interval will be set to 1 sec. In order to program the sampling interval, first turn the power OFF. Now suppose if we want 1 min sampling time, we will hold pressing the Stop button and turn the power ON. At start, PIC12F683 checks any key pressed, and determine what the sampling interval is going to be. Once it finds any button pressed, the LED will glow to indicate it is the time to release the key. Similarly, for 10 min sampling interval, use the Send key, and for 1 sec, use the Start key. </div><br />
<div><b>Program Sequence</b></div><div>The firmware inside the PIC does the following sequence of operations.</div><div><ol><li>Power ON.</li>
<li>Blinks the LED for 3 times.</li>
<li>Check any key pressed. If yes, identify the key and store the appropriate sampling interval to EEPROM location 0. After it identifies the pressed key, the LED will glow up, and you need to release the key. Once the key is released, the selected sampling interval is stored in the EEPROM. Every time when a EEPROM location is written, the LED blinks for 3 times. </li>
<li>Read EEPROM location 0, and get Sampling Time. Now the program is inside the main loop. The three switches (Start, Stop, and Send) connected to GPIO 5, 4, and 3 work in Interrupt-on-Change mode. That means, when any of these buttons is pressed, an interrupt will be generated, and served accordingly. Start will start the logging of temperature values. Stop will interrupt the logging process, and Send will transfer data to serial port. If the Send is pressed for more than 2 sec, the EEPROM memory will be cleared.</li>
</ol></div><div><b>Pictures</b></div><div class="separator" style="clear: both; text-align: center;">Finished Board</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDSdF8vUz2er2DJf7Y4WeXCSXefg-FpZamHcRj7dY75iNRfVikmQrEmTkpDhunVEgrGYZyXjGDsBl79k8M-cqhNqqp0oHEjuk_4_cou02QRGEO20crJKTwovzidUWIF2ahyphenhyphenmSvCiBrllI/s1600/FinishedBoard.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDSdF8vUz2er2DJf7Y4WeXCSXefg-FpZamHcRj7dY75iNRfVikmQrEmTkpDhunVEgrGYZyXjGDsBl79k8M-cqhNqqp0oHEjuk_4_cou02QRGEO20crJKTwovzidUWIF2ahyphenhyphenmSvCiBrllI/s400/FinishedBoard.JPG" width="400" /></a></div><div style="text-align: center;"><br />
</div><div style="text-align: center;">Serial connection to PC</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSxefUoyOf1GrNXKdPVhbhUlXe-TRs8zeqnHUnFrEghDizvtriLtw2OJaKNss-efpOjqSDSYUFZRHnTpU9WpnCgapx8v_PhcjJPEBcJd1e366xPDj9zRKrV4JfNhwaGrc9Ba389daYDo/s1600/SerialConnected.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSxefUoyOf1GrNXKdPVhbhUlXe-TRs8zeqnHUnFrEghDizvtriLtw2OJaKNss-efpOjqSDSYUFZRHnTpU9WpnCgapx8v_PhcjJPEBcJd1e366xPDj9zRKrV4JfNhwaGrc9Ba389daYDo/s400/SerialConnected.JPG" width="400" /></a></div><div style="text-align: center;"><br />
</div><div style="text-align: center;">Data Logger is clear (Default sampling time = 1 sec after reset)</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5SnLilkS1WNfVOE7HMJsMvRgqivR9_4z4Ax7q5t6mjQRVGxBwYxwsM7U8h4SAt9fCKAScLajDYjZh8xUtqgF_0RuyYcTvZSWJF9khzgXlZ5qbWO_bnnLptFNTInRU3NNLmM4q7ELQZZY/s1600/StartHyper1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="347" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5SnLilkS1WNfVOE7HMJsMvRgqivR9_4z4Ax7q5t6mjQRVGxBwYxwsM7U8h4SAt9fCKAScLajDYjZh8xUtqgF_0RuyYcTvZSWJF9khzgXlZ5qbWO_bnnLptFNTInRU3NNLmM4q7ELQZZY/s400/StartHyper1.JPG" width="400" /></a></div><div style="text-align: center;"><br />
</div><div style="text-align: center;">LED blinks during data transfer</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie7bftp8j7RxJ7Qzhilu2Fsknizr4ZBw3xD7b1c5Qc1_MZBK17FDTVyYQ2JoWbUeI1InXTyXhvf8lMbMQDW-eH0X2sKDxDMNN8wfZbRuS_kAXF1nlpLHOAdF6PhMntWvLFpj9chvx3U2I/s1600/LEDBlinks.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie7bftp8j7RxJ7Qzhilu2Fsknizr4ZBw3xD7b1c5Qc1_MZBK17FDTVyYQ2JoWbUeI1InXTyXhvf8lMbMQDW-eH0X2sKDxDMNN8wfZbRuS_kAXF1nlpLHOAdF6PhMntWvLFpj9chvx3U2I/s400/LEDBlinks.JPG" width="400" /></a></div><div style="text-align: center;"><br />
</div><div style="text-align: center;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh2GYMh_xcFjKnKJXXwVmcjV7KFSwnhGvcQz8u1cpmccx_az7MEdpmA-mjG903h4DeDeztCQvxE_gSqTtaVnjT0qZWx4UJdL0-S1-dkhsuPROxX4n-daXAQLPE3n-yB1T5mXvhhLacNW0/s1600/DSC09936.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh2GYMh_xcFjKnKJXXwVmcjV7KFSwnhGvcQz8u1cpmccx_az7MEdpmA-mjG903h4DeDeztCQvxE_gSqTtaVnjT0qZWx4UJdL0-S1-dkhsuPROxX4n-daXAQLPE3n-yB1T5mXvhhLacNW0/s400/DSC09936.JPG" width="400" /></a></div><br />
</div><div style="text-align: center;">Various sampling time select and recorded values</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKRrFRZ2fG4B6yjNBe_rQbqD7cHVUSXGzknF7D1sk7d1IGUpaAVXyXDSWorwqD-HyokdfcMxE23igxp6Xu67dMf2-d0zWhn2ULCG1KknOwosmKyDmfbZeRoH-vBvzicthlVINzfqysZtY/s1600/LogExample.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKRrFRZ2fG4B6yjNBe_rQbqD7cHVUSXGzknF7D1sk7d1IGUpaAVXyXDSWorwqD-HyokdfcMxE23igxp6Xu67dMf2-d0zWhn2ULCG1KknOwosmKyDmfbZeRoH-vBvzicthlVINzfqysZtY/s400/LogExample.JPG" width="342" /></a></div><div style="text-align: center;"><br />
</div><div>I have posted this project on Electronics-Lab website. The complete project including firmware is downloadable from there. Here is the <b><a href="http://www.electronics-lab.com/projects/test/012/index.html" target="blank">link.</a></b></div><center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7665562587101241008.post-78337962326472988012010-07-31T12:25:00.001-04:002011-06-24T16:16:58.066-04:00Experiment No. 5: DC Motor Speed Control using Pulse Width Modulation (PWM)<b>Introduction</b><br />
<br />
PIC12F683 has a built-in PWM module. The PWM output (CCP1 pin) is multiplexed with GPIO.2 (pin 5). So the TRISIO<2> bit must be cleared to make the CCP1 pin an output.<br />
The objective of this experiment is to control the speed of a DC motor with an input from a potentiometer. This will be achieved in two steps:<br />
<ul><li>Read analog value (potentiometer output) through AN0 channel and generate a PWM wave at CCP1 pin (5) with duty cycle proportional to the analog value.</li>
<li>Feed the PWM to motor driver transistor and observe the speed.</li>
</ul><div><b>mikroC library routines for PWM</b></div><div>PWM1_Init</div><div>PWM1_Set_Duty</div><div>PWM1_Start</div><div>PWM1_Stop</div><br />
<div>Since PWM1_Set_Duty library function takes duty cycle input as an 8-bit integer, the digital value of analog signal, which is 10-bit, must be converted to 8-bit first. This will give 256 speed levels (0-255).</div><br />
<b>Experimental Setup</b><br />
Connect POT2 output to pin 7 (AN0) of PIC12F683 and pin 5 (CCP1) to the input of motor driver transistor.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7qbAvTPgsRBB8xFdKoUYo8RFiU9uoAdm54GeolVin-P-eHfmq6zvTCbjvOKN9jgvuZ9XjGV-x_9W703PlGHu5Hei_zrLQmokDyBYr6s48O65kc4TGFl-7GRgI4d85131oajXwDszMfns/s1600/P1007311619516.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7qbAvTPgsRBB8xFdKoUYo8RFiU9uoAdm54GeolVin-P-eHfmq6zvTCbjvOKN9jgvuZ9XjGV-x_9W703PlGHu5Hei_zrLQmokDyBYr6s48O65kc4TGFl-7GRgI4d85131oajXwDszMfns/s400/P1007311619516.jpg" width="400" /></a></div><br />
<b><a name='more'></a></b><br />
<b>Software</b><br />
<br />
<span class="Apple-style-span" style="color: #cc0000;">/*</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> PIC12F683 Experiment Board</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> Experimen No. 5 : DC Motor Speed Control using PWM</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> Date: 07/28</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> /2010</span><br />
<span class="Apple-style-span" style="color: #cc0000;">*/</span><br />
<span class="Apple-style-span" style="color: #cc0000;">unsigned short DutyCycle=0;</span><br />
<span class="Apple-style-span" style="color: #cc0000;">unsigned int adc_value;</span><br />
<span class="Apple-style-span" style="color: #cc0000;"><br />
</span><br />
<span class="Apple-style-span" style="color: #cc0000;">void main() {</span><br />
<span class="Apple-style-span" style="color: #cc0000;">CMCON0 = 7;</span><br />
<span class="Apple-style-span" style="color: #cc0000;">TRISIO = 9; // GPIO 0 and 3 Inputs; Rest are O/Ps</span><br />
<span class="Apple-style-span" style="color: #cc0000;">ANSEL = 0x01;</span><br />
<span class="Apple-style-span" style="color: #cc0000;">GPIO = 0;</span><br />
<span class="Apple-style-span" style="color: #cc0000;"><br />
</span><br />
<span class="Apple-style-span" style="color: #cc0000;">PWM1_Init(5000); // PWM module initialization (5KHz)</span><br />
<span class="Apple-style-span" style="color: #cc0000;">PWM1_Start(); // Start PWM1 module with Zero DC</span><br />
<span class="Apple-style-span" style="color: #cc0000;">PWM1_Set_Duty(DutyCycle);</span><br />
<span class="Apple-style-span" style="color: #cc0000;">do {</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> adc_value = ADC_Read(0);</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> DutyCycle = adc_value >> 2; // Convert 10-bit ADC value to 8-bit</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> PWM1_Set_Duty(DutyCycle);</span><br />
<span class="Apple-style-span" style="color: #cc0000;"> } while(1);</span><br />
<span class="Apple-style-span" style="color: #cc0000;">}</span><br />
<span class="Apple-style-span" style="color: #cc0000;"><br />
</span><br />
<b>Output</b><br />
<br />
The speed of the DC motor is controlled with the potentiometer.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHaRqYUSoIbsao6n-hbn2HvLSvNOs9GAkpOZ2SgT2K2MJOlLYnyHzBJn_u32wzVyeC5YbGTYFepWO6N3lmZhK7A6tZC144e02GibEZ_kbMvpnQtDCMRMKf8iHV28y8_CVoI2XaYjsdV3Y/s1600/P1007311620355.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHaRqYUSoIbsao6n-hbn2HvLSvNOs9GAkpOZ2SgT2K2MJOlLYnyHzBJn_u32wzVyeC5YbGTYFepWO6N3lmZhK7A6tZC144e02GibEZ_kbMvpnQtDCMRMKf8iHV28y8_CVoI2XaYjsdV3Y/s400/P1007311620355.jpg" width="400" /></a></div><br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-7665562587101241008.post-49524373341265607562010-06-26T19:43:00.001-04:002011-06-24T16:18:51.266-04:00Experiment No. 4: External InterruptPIC12F683 has got one external interrupt pin (GP2, pin 5) which is edge-triggered:<br />
<ul><li>rising edge if INTEDG bit in OPTION register is SET,or </li>
<li>falling edge if INTEDG bit in OPTION register is CLEAR</li>
</ul>In this experiment we are going to simulate an external interrupt event by a tact switch which when pressed gives a falling edge (5->0V) to external interrupt pin. When a valid edge appears on GP2/INT pin, the INTF bit (INTCON<1>) is set. This interrupt can be disabled by clearing INTE control bit (INTCON<4>). While exiting from the Interrupt Service Routine, INTF flag must be cleared to re-enable the interrupt again. ANSEL and CMCON0 must be initialized to configure GPIO as digital I/Os.<br />
<br />
On the arrival of an interrupt, the new value of counter will increase by 1 and is displayed as no. of interrupts serviced. <br />
<br />
<b>Experimental Setup:</b><br />
<b></b>External interrupt will be simulated by a tact switch on the board.<b> </b>So connect SW1 to GP2 with a jumper wire. For display purpose we will again use a hyperterminal window on a PC.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq70n8_N5rqh9N4QazrmzUBULlq3uVJ3HtbFLK83TMWh_U2HifzkY9MVETkMoCO156-b8hb7aOsrHyCzuRuLxIHEb7NK_j8N8rLc_B8RrHLqvsV9TSqejQIykwsYK7qnyqyF0d6MdKW1M/s1600/PIC12F683_Ex_No_4_Setup.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq70n8_N5rqh9N4QazrmzUBULlq3uVJ3HtbFLK83TMWh_U2HifzkY9MVETkMoCO156-b8hb7aOsrHyCzuRuLxIHEb7NK_j8N8rLc_B8RrHLqvsV9TSqejQIykwsYK7qnyqyF0d6MdKW1M/s400/PIC12F683_Ex_No_4_Setup.JPG" width="400" /></a></div><br />
<a name='more'></a><br />
<br />
<b>Software:</b><br />
<div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> /*</div><div style="color: #cc0000;"> PIC12F683 Experiment Board</div><div style="color: #cc0000;"> Experimen No. 4 : External Interrupt</div><div style="color: #cc0000;"> Date: 06/26/2010</div><div style="color: #cc0000;">*/</div><div style="color: #cc0000;">char Message1[] = "Interrupt Demonstration!";</div><div style="color: #cc0000;">char Message2[] = "Interrupt No.= ";</div><div style="color: #cc0000;">char *temp = "00", error;</div><div style="color: #cc0000;">unsigned int i, old_count=0, new_count=0;</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;">// Interrupt Service Routine</div><div style="color: #cc0000;">void interrupt(void){</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> if (INTCON.INTF == 1) // Check if INTF flag is set</div><div style="color: #cc0000;"> {</div><div style="color: #cc0000;"> new_count++; // If yes, increase counter</div><div style="color: #cc0000;"> temp[0] = new_count/10 + 48; // Convert count digits into characters</div><div style="color: #cc0000;"> temp[1] = new_count%10 + 48;</div><div style="color: #cc0000;"> INTCON.INTF = 0; // Clear interrupt flag before exiting ISR</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;">// Main program </div><div style="color: #cc0000;">void main() {</div><div style="color: #cc0000;">CMCON0 = 7;</div><div style="color: #cc0000;">TRISIO = 15; // GPIO 0, 1, 2, 3 Inputs; Rest are O/Ps</div><div style="color: #cc0000;">ANSEL = 0;</div><div style="color: #cc0000;">OPTION_REG = 0x00; // Clear INTEDG, External Interrupt on falling edge</div><div style="color: #cc0000;">// Interrupt Setup</div><div style="color: #cc0000;"> INTCON.INTF = 0; // Clear interrupt flag prior to enable</div><div style="color: #cc0000;"> INTCON.INTE = 1; // enable on change interrupts</div><div style="color: #cc0000;"> INTCON.GIE = 1; // enable Global interrupts</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;">// Define GPIO.3 as UART Rx, and 5 as Tx</div><div style="color: #cc0000;">error = Soft_UART_Init(&GPIO,3, 5, 9600, 0 );</div><div style="color: #cc0000;">Delay_ms(100);</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;">do {</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> for (i=0; i<= 23; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(Message1[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> Soft_UART_Write(10); // Line Feed</div><div style="color: #cc0000;"> Soft_UART_Write(13); // Carriage Return</div><div style="color: #cc0000;"> delay_ms(500);</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> if (new_count > old_count)</div><div style="color: #cc0000;"> {</div><div style="color: #cc0000;"> for (i=0; i<= 13; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(Message2[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> for (i=0; i<= 1; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(temp[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> Soft_UART_Write(10); // Line Feed</div><div style="color: #cc0000;"> Soft_UART_Write(13); // Carriage Return</div><div style="color: #cc0000;"> old_count=new_count;</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> } while(1);</div><div style="color: #cc0000;">}</div><br />
<b>Experimental Output:</b><br />
On hyperterminal window, you will continuously see a message "Interrupt Demonstration!". When you press the tact switch, that will give an interrupt (falling edge), and the counter value goes up by 1. The updated counter value will be displayed.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhScs_9__8Mv6oLmV9pkOSRQHAbcxzSwmsscTKQuyiZtWWtgTPreOb9jgyYeNImFYjNO8zeS6RlEZTeBsH_MPj7buKDvOCsDyLb0pNcxtLzLI-WQvYsLuEsTk5SmxYgSwQnFf9tA3_WM7Y/s1600/intrdemo.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="277" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhScs_9__8Mv6oLmV9pkOSRQHAbcxzSwmsscTKQuyiZtWWtgTPreOb9jgyYeNImFYjNO8zeS6RlEZTeBsH_MPj7buKDvOCsDyLb0pNcxtLzLI-WQvYsLuEsTk5SmxYgSwQnFf9tA3_WM7Y/s400/intrdemo.JPG" width="400" /></a></div><br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7665562587101241008.post-46377599104200030832010-06-26T16:03:00.001-04:002011-06-24T16:19:52.480-04:00Experiment No. 3: Analog to Digital Converter with PIC12F683As mentioned before, 4 out of 6 GPIOs in a PIC12F683 also provide analog-to-digital converter inputs with 10-bit resolution. They are GP0-GP2, and GP4. In this experiment we will feed an analog voltage to one of the ADC inputs (say AN0, which is GP0) and display the output digital value on a hyper-terminal window on PC. The analog voltage will be simulated with the potentiometer on our board.<br />
<br />
<b>Experimental Setup:</b><br />
Connect the output of potentiometer (POT2) to AN0 (pin 7). GP5 (pin 2) will serve as TX pin for Software UART so connect it to input Tx of TTL to RS232 Level Shifter circuit. Also connect Rx (2) and Gnd (5) of a RS232 port to the board. This is similar to what we did in Experiment No. 2.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-vpcGI7jPB_bkiT9J6Uswkmi7WuXXRzN6-u-EK8IpeNlXWpDnluFN2mbSJoI2Z7RMD5Gr4Cwogta7Fc7y106HXi6V1axpYIuns_I6KlguoPLm7OQ5a0D8oCfgL7yBSbLIS4JnaZKKuUI/s1600/PIC12F683_Ex_No_3_Setup.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-vpcGI7jPB_bkiT9J6Uswkmi7WuXXRzN6-u-EK8IpeNlXWpDnluFN2mbSJoI2Z7RMD5Gr4Cwogta7Fc7y106HXi6V1axpYIuns_I6KlguoPLm7OQ5a0D8oCfgL7yBSbLIS4JnaZKKuUI/s400/PIC12F683_Ex_No_3_Setup.JPG" width="400" /></a></div><br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipqfsxcSIITvYektxPe2-VOEfL_WhfMoXix6W-fS3Xcgq-bzFw9uTkO8hzYyHcm5cvOvOAu8VluBtIB_VIbdNPr9_TIyUQ2LzoWs_Jwk2KArZuMBB9udzJqK8C9SOuTwTr2MJXLnEkua0/s1600/145326.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipqfsxcSIITvYektxPe2-VOEfL_WhfMoXix6W-fS3Xcgq-bzFw9uTkO8hzYyHcm5cvOvOAu8VluBtIB_VIbdNPr9_TIyUQ2LzoWs_Jwk2KArZuMBB9udzJqK8C9SOuTwTr2MJXLnEkua0/s400/145326.jpg" width="400" /></a></div><br />
<b>Software:</b><br />
<div style="color: red;"><b><br />
</b></div><div style="color: red;"></div><div style="color: #cc0000;">/*</div><div style="color: #cc0000;"> PIC12F683 Experiment Board</div><div style="color: #cc0000;"> Experimen No. 3 : Read analog voltage from AN0 and diplay</div><div style="color: #cc0000;"> on Hyperterminal window on PC using Software UART.</div><div style="color: #cc0000;"> Date: 06/25/2010</div><div style="color: #cc0000;">*/</div><div style="color: #cc0000;">char Message1[] = "Digital Value= ";</div><div style="color: #cc0000;">unsigned int adc_value, backup=0 ;</div><div style="color: #cc0000;">char *temp = "0000", error;</div><div style="color: #cc0000;">int i;</div><div style="color: #cc0000;">void main() {</div><div style="color: #cc0000;">CMCON0 = 7;</div><div style="color: #cc0000;">TRISIO = 11; // GPIO 0, 1, 3 Inputs; Rest are O/Ps</div><div style="color: #cc0000;">ANSEL = 0x01;</div><div style="color: #cc0000;">GPIO = 0;</div><div style="color: #cc0000;">// Define GPIO.3 as UART Rx, and 5 as Tx</div><div style="color: #cc0000;">error = Soft_UART_Init(&GPIO,3, 5, 9600, 0 );</div><div style="color: #cc0000;">Delay_ms(100);</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;">do {</div><div style="color: #cc0000;"> adc_value = ADC_Read(0);</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> if(adc_value != backup) {</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> if (adc_value/1000)</div><div style="color: #cc0000;"> temp[0] = adc_value/1000 + 48;</div><div style="color: #cc0000;"> else</div><div style="color: #cc0000;"> temp[0] = '0';</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> temp[1] = (adc_value/100)%10 + 48;</div><div style="color: #cc0000;"> temp[2] = (adc_value/10)%10 + 48;</div><div style="color: #cc0000;"> temp[3] = adc_value%10 + 48;</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> for (i=0; i<= 13; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(Message1[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> for (i=0; i<= 3; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(temp[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> Soft_UART_Write(10); // Line Feed</div><div style="color: #cc0000;"> Soft_UART_Write(13); // Carriage Return</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> backup = adc_value;</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> delay_ms(100);</div><div style="color: #cc0000;"> } while(1);</div><div style="color: #cc0000;">}</div><br />
<b>Output:</b><br />
The digital value of input analog voltage will be displayed on hyperterminal window. The digital value will have range from 0-1023 (10-bit ADC).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHcd8sm2tOVu0n6GLflPIrgpdcQHDRDAOLh3RAkkxdXtBG0NDBs6ZWKeO9FHrfYXudtLw76rliZckQEGw6xpf5THtGgDAfEcegoa8ef8ZIS1hWGm3LDzSH3qpYtOyiH9dzvJPbrwIdbZ0/s1600/ADCHyperTerminal.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHcd8sm2tOVu0n6GLflPIrgpdcQHDRDAOLh3RAkkxdXtBG0NDBs6ZWKeO9FHrfYXudtLw76rliZckQEGw6xpf5THtGgDAfEcegoa8ef8ZIS1hWGm3LDzSH3qpYtOyiH9dzvJPbrwIdbZ0/s400/ADCHyperTerminal.JPG" width="400" /></a></div><center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-7665562587101241008.post-5690509198834957712010-04-03T16:15:00.001-04:002011-06-24T16:20:59.537-04:00Experiment No. 2: User Inputs from Tact Switches and Software UARTIn this experiment, we will demonstrate how to read inputs from tact switches, and then will also show how to send character data from PIC12F683 to a desktop PC Hyper-Terminal program through UART communication. Remember that PIC12F683 doesn't have hardware UART module, so we are going to use the Soft_UART library routines from mikroC for this purpose. Regarding the Hyper-Terminal setup on PC, <b><a href="http://pic16f628a.blogspot.com/2010/01/experiment-no-10-use-of-uart-library-to.html">read this</a></b>. Besides, to read the user inputs from tact switches, Button Library routines in mikroC will be used.<br />
<div style="text-align: center;"><i><b>Snapshots of the required Library Routines from mikroC User's Manual </b></i></div><br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4fzzdZKki0WcBlCjP4SMWfxRuHm1AdjhfKvqq0XQ5OWgDlxSh2evcdj5OytieBHOT57vpFsfI8rB9XiG6Rcwtz5Dpo35Ordv9DSyUZyGipriK2h1g15GqMFzLfLyQEp1mhrQhMkEJBso/s1600/button.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="335" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4fzzdZKki0WcBlCjP4SMWfxRuHm1AdjhfKvqq0XQ5OWgDlxSh2evcdj5OytieBHOT57vpFsfI8rB9XiG6Rcwtz5Dpo35Ordv9DSyUZyGipriK2h1g15GqMFzLfLyQEp1mhrQhMkEJBso/s400/button.JPG" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVva78ouD9XkQSi4iYpKMihhjtOQNVky4DYQTYXDGTkmrGXKxaAHHJ_ESXmzZ5uJrm8k0laMxAaVQiNGQz_stcERX1wwYwwoZgRCUiRGma_XA3JThqaxGtGbIuVY315DKRe6tJ7pWB36w/s1600/Picture+21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="383" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVva78ouD9XkQSi4iYpKMihhjtOQNVky4DYQTYXDGTkmrGXKxaAHHJ_ESXmzZ5uJrm8k0laMxAaVQiNGQz_stcERX1wwYwwoZgRCUiRGma_XA3JThqaxGtGbIuVY315DKRe6tJ7pWB36w/s400/Picture+21.png" width="400" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdpRv5-ji9-YNvsACL1Zs_yvIQJqGcoMIwgpjv7TZ3S3kvjmTefVVirkauS-lTuuDICuYbyNeSCaC7nvOdW52_B606Bc2O0rnqzhg8erUAQUz-6eIiBuxJgIrkiMQc57lE8kJFGO1W8Rw/s1600/Picture+22.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdpRv5-ji9-YNvsACL1Zs_yvIQJqGcoMIwgpjv7TZ3S3kvjmTefVVirkauS-lTuuDICuYbyNeSCaC7nvOdW52_B606Bc2O0rnqzhg8erUAQUz-6eIiBuxJgIrkiMQc57lE8kJFGO1W8Rw/s400/Picture+22.png" width="400" /></a></div><br />
<b>Setup:</b><br />
The two switch inputs in our board will be connected to GP0 and GP1 port (Pins 7 and 6 respectively). GP5 (Pin 2) will be used for Software UART Tx. So here is what you need to do:<br />
<ul><li>Connect SW1 and SW2 (tact switches) to GP0 and GP1 using jumper wires,</li>
<li>Connect GP5 to input Tx of TTL to RS232 Level Shifter circuit,</li>
<li>Connect Rx(2) and Gnd(5) pins of a RS232 port to the board.</li>
</ul><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzPrM1je07FKMQTbfHQY18qR8MuIyXySSROmO-zt0qmyH81eB-7wJ5rewYHUCjlOcd2WTlzrDFp41lMjXS_wGiaS6fc-AQJOhX55YmaCjfgXcbjhr_Joc5CT9gDCe8UCoOp739orpgqQA/s1600/DSC00041.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzPrM1je07FKMQTbfHQY18qR8MuIyXySSROmO-zt0qmyH81eB-7wJ5rewYHUCjlOcd2WTlzrDFp41lMjXS_wGiaS6fc-AQJOhX55YmaCjfgXcbjhr_Joc5CT9gDCe8UCoOp739orpgqQA/s400/DSC00041.JPG" width="400" /></a></div><br />
<a name='more'></a><br />
<br />
<b>Software:</b><br />
This code will detect which of the two tact switches is pressed and then send a message to the PC through UART, e.g. if SW1 is pressed, it will say "SW1 Pressed".<br />
<br />
<div style="color: #cc0000;">/*</div><div style="color: #cc0000;"> PIC12F683 Experiment Board</div><div style="color: #cc0000;"> Experimen No. 2 : Input from tact switches and send info to</div><div style="color: #cc0000;"> desktop PC using Software UART.</div><div style="color: #cc0000;"> Date: 04/03/2010</div><div style="color: #cc0000;">*/</div><div style="color: #cc0000;">char Message1[] = "SW1 Pressed";</div><div style="color: #cc0000;">char Message2[] = "SW2 Pressed";</div><div style="color: #cc0000;">char i, error;</div><div style="color: #cc0000;">void main() {</div><div style="color: #cc0000;">CMCON0 = 7;</div><div style="color: #cc0000;">TRISIO = 11; // GPIO 0, 1, 3 Inputs; Rest are O/Ps</div><div style="color: #cc0000;">ANSEL = 0;</div><div style="color: #cc0000;">GPIO = 0;</div><div style="color: #cc0000;">// Define GPIO.3 as UART Rx, and 5 as Tx</div><div style="color: #cc0000;">error = Soft_UART_Init(&GPIO,3, 5, 9600, 0 );</div><div style="color: #cc0000;">Delay_ms(100);</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;">do {</div><div style="color: #cc0000;"> if (Button(&GPIO, 0, 1, 0)) { // Detect logical one to zero</div><div style="color: #cc0000;"> Delay_ms(300);</div><div style="color: #cc0000;"> for (i=0; i<= 10; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(Message1[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> Soft_UART_Write(10); // Line Feed</div><div style="color: #cc0000;"> Soft_UART_Write(13); // Carriage Return</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> if (Button(&GPIO, 1, 1, 0)) { // Detect logical one to zero</div><div style="color: #cc0000;"> Delay_ms(300) ;</div><div style="color: #cc0000;"> for (i=0; i<= 10; i++) {</div><div style="color: #cc0000;"> Soft_UART_Write(Message2[i]);</div><div style="color: #cc0000;"> Delay_ms(50);</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"> Soft_UART_Write(10); // Line Feed</div><div style="color: #cc0000;"> Soft_UART_Write(13); // Carriage Return</div><div style="color: #cc0000;"> }</div><div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"> } while(1);</div><div style="color: #cc0000;">}</div><br />
<b>Output: </b><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzczeMt1gQIYT4ebVtZVuC2lh9_3cXjI8YJh9KKzKD07L-WEFNVNcPobi1Np92oqzG0TAgLGsIRsjaXMkg4KVbn1KSM1p1cCg1ADMWzJ5KFVLMIdc0-82z_WHTOMG4iG1VozgkvM5In0Q/s1600/DSC00040.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzczeMt1gQIYT4ebVtZVuC2lh9_3cXjI8YJh9KKzKD07L-WEFNVNcPobi1Np92oqzG0TAgLGsIRsjaXMkg4KVbn1KSM1p1cCg1ADMWzJ5KFVLMIdc0-82z_WHTOMG4iG1VozgkvM5In0Q/s400/DSC00040.JPG" width="400" /></a></div><center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-7665562587101241008.post-7552350456950087442010-02-13T18:41:00.001-05:002011-06-24T16:21:54.233-04:00Experiment No. 1: 3-bit LED Up CounterThis is the first and the simplest project we are going to test on our PIC12F683 experiment board. We are going to make a 3-bit up counter that counts from 0 to 7. After 7, we are going to reset it to 0 and then start again, and so on. The 3-bit counter output will be displayed on 3-LEDs on the board. There will be a 1s delay between each up count.<br />
<b>Setup:</b><br />
Connect GP0, GP1, and GP2 (pins 7, 6, and 5 of PIC12F683) to LEDs 3, 2, and 1 respectively.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSvbaojsTc_srmH44Ua5YUjEEWrSaVR2n-rd2GGE0bAMt2CtqPvD58JvPI2XlYsqt8aAfCFSGKQ6SviFiRq7i7px8I30O6CSmHD9VepsL_T0MA6qC_sOYegXOjomv-CbiNQNbhKXWk-cw/s1600-h/3bit1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSvbaojsTc_srmH44Ua5YUjEEWrSaVR2n-rd2GGE0bAMt2CtqPvD58JvPI2XlYsqt8aAfCFSGKQ6SviFiRq7i7px8I30O6CSmHD9VepsL_T0MA6qC_sOYegXOjomv-CbiNQNbhKXWk-cw/s400/3bit1.JPG" width="400" /></a> </div><div class="separator" style="clear: both; text-align: center;"><i>Connect GPIO2, 1, 0 pins to LEDs 1, 2, 3 using jumper wires. </i></div><div style="text-align: center;"><br />
<a name='more'></a><br />
</div><b>Software:</b><br />
<br />
/*<br />
PIC12F683 Experiment Board<br />
Experimen No. 1 : 3-bit Up Counter<br />
"LEDs 1, 2, and 3 are connected to GPIO2, GPIO1, and GPIO0<br />
respectively"<br />
*/<br />
<br />
short i;<br />
void main() {<br />
CMCON0 = 7;<br />
TRISIO = 8; // GPIO0-GPIO2 are Outputs<br />
ANSEL = 0;<br />
GPIO = 0;<br />
delay_ms(500);<br />
i=0;<br />
do {<br />
GPIO=i;<br />
delay_ms(1000);<br />
i = i+1;<br />
if(i == 8) i=0;<br />
<br />
}while(1);<br />
}<br />
<br />
<b>Output:</b><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVO4N1xskRQLdgAqoca0DFYn-DNHuWp7V4Uh2Nz-tP2nl3tGMHfWfub2ZVu_a_v0KDnPdoYUcaADr2EjogjDn9G9gBUQxVuOZly6VS9Yw6kjocgSTJRvwIlel5zkQLGIuXVCjeFMTnhVU/s1600-h/3bit2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="283" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVO4N1xskRQLdgAqoca0DFYn-DNHuWp7V4Uh2Nz-tP2nl3tGMHfWfub2ZVu_a_v0KDnPdoYUcaADr2EjogjDn9G9gBUQxVuOZly6VS9Yw6kjocgSTJRvwIlel5zkQLGIuXVCjeFMTnhVU/s400/3bit2.JPG" width="400" /></a></div><div style="text-align: center;">3 LEDs count up to 7, then reset and count starts again.</div><center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7665562587101241008.post-37464344986700026322010-02-13T18:38:00.001-05:002011-06-24T16:22:25.765-04:00What else you need to start experimenting on this board?After you finish constructing the development board, here are few more things to do before doing some real experiments with it.<br />
<br />
<ul><li>Of course, you need a 9V DC adapter for power supply. I sometimes use the power supply from my PIC programmer which derives power from a USB port of my computer. But do this only if you are sure that the experiment you doing draws current which is within the safe limit of the USB port.</li>
<li>Next, you also need jumper wires to interconnect the various terminals while doing experiments.</li>
<li>It depends on you what kind of platform you want to choose for programming the PIC. If you want to use assembly language, you need to download MPLAB. It is free to download from the Microchip website. You can also find an installation guide for this, which might be helpful. However, I prefer high-level language like C for programming my PIC. I am going to use mikroC compiler from Mikroelektronika for all the experiments I am going to show here. You can download a demo version of this compiler for free. The demo version restricts the output HEX file size to 2K, but we don't care because PIC12683 doesn't have programming memory more than that. So, you decide. <a name='more'></a></li>
</ul><br />
<center><script type="text/javascript">
<!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></center>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7665562587101241008.post-11233216387919855842010-02-05T09:07:00.001-05:002011-06-24T16:23:30.920-04:00Make Your Own PIC12F683 Microcontroller Development Board<div class="separator" style="clear: both; text-align: left;">Our purpose here is to explore the potential of PIC12F683 microcontroller for which we need a development board. The good thing is we are going to make our own board. The schematic and the actual board that I have built are shown below. I soldered all the components on a 12 x 8 cm general purpose prototyping board. </div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7c59ibizDiTNghZNnJYRwc6BLQrSbparPkuwqGhf9mVi_BuNkAJPUgzNP5wWtITvihNiR6q0_Q57V7W9o4d8GtG-_Q6uPnNWzwfHirVzRnXys0-Eg-A2N8Jvvnrflh5YHipBntaoO2bc/s1600/lunapic_128413505138086_19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7c59ibizDiTNghZNnJYRwc6BLQrSbparPkuwqGhf9mVi_BuNkAJPUgzNP5wWtITvihNiR6q0_Q57V7W9o4d8GtG-_Q6uPnNWzwfHirVzRnXys0-Eg-A2N8Jvvnrflh5YHipBntaoO2bc/s400/lunapic_128413505138086_19.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;">Completed Board </div><br />
<div class="separator" style="clear: both; text-align: left;">It has following features in it:</div><div class="separator" style="clear: both; text-align: left;"><i>1. A Regulated +5V power supply.</i></div><div class="separator" style="clear: both; text-align: left;"><i>2. 3 Output LEDs that can be connected to any GPIO pins using jumper wires.</i></div><div class="separator" style="clear: both; text-align: left;"><i>3. ON/OFF power supply switch.</i></div><div class="separator" style="clear: both; text-align: left;"><i>4. A Green LED as a power ON indicator.</i></div><div class="separator" style="clear: both; text-align: left;"><i>5. An 8-pin IC socket for PIC12F683 microcontroller.</i></div><div class="separator" style="clear: both; text-align: left;"><i>6. Two potentiometers: one for providing Vref, and other for simulating analog input to ADC.</i></div><div class="separator" style="clear: both; text-align: left;"><i>7. An ICSP header connector.</i></div><div class="separator" style="clear: both; text-align: left;"><i>8. Two tactile switches for input operation.</i></div><div class="separator" style="clear: both; text-align: left;"><i>9. A TTL to RS232 level shifter using a transistor circuit.</i></div><div class="separator" style="clear: both; text-align: left;"><i>10. A piezo buzzer.</i></div><div class="separator" style="clear: both; text-align: left;"><i>11. A DC motor with driving circuit.</i></div><div class="separator" style="clear: both; text-align: left;"><i></i></div><div class="separator" style="clear: both; text-align: left;"></div><a name='more'></a><br />
<br />
<div>Most of these features on the board are accessible through female header pins. None of the 6-I/O pins of PIC12F683 are hardwired to anything and they are accessible through header pins too. Only the ISCP pins are accessible through male header pins. Figures below show PIC12F683 ports, header pins that I used and schematic of the development board.</div><br />
<div class="separator" style="clear: both; text-align: center;"><span style="color: #990000;"></span></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyyn6DMeCowSM1tPzKAiMxRsvs_vEkuATURVxQkomzgHMo9sGevbyfNwffCjeStfJX_DWRTV5CbamO3898xjPbthWFUDzYf1LjCLr_23U7BqVr7_kVE5c-Zf3XisdFNPc9UYCEc1OeOA/s1600/photo_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="255" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyyn6DMeCowSM1tPzKAiMxRsvs_vEkuATURVxQkomzgHMo9sGevbyfNwffCjeStfJX_DWRTV5CbamO3898xjPbthWFUDzYf1LjCLr_23U7BqVr7_kVE5c-Zf3XisdFNPc9UYCEc1OeOA/s400/photo_1.png" width="400" /> </a></div><div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvqj0Otx0jAVh3CgIaYBMFEuhdXkoqGe1Im97dDeKwqWKe-shweKvFHyKQspiBu9kzVWHhLugrH7kc_ywxN58lhIqz2GQsoOd2bxU1I0R7jjJIJEvhPKN-uFX8IRPqLhUqpxWKi51OCCI/s1600/Circuit.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="296" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvqj0Otx0jAVh3CgIaYBMFEuhdXkoqGe1Im97dDeKwqWKe-shweKvFHyKQspiBu9kzVWHhLugrH7kc_ywxN58lhIqz2GQsoOd2bxU1I0R7jjJIJEvhPKN-uFX8IRPqLhUqpxWKi51OCCI/s400/Circuit.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigfolT_bbt0PA98jMUMY52B9lib2Tn1N_pwmabzONvoFyrXHYWiQtnjAEs1JPIsyCKV9I22jlKRMyV8phWGZfbo2TQJohVI0dFzhBOa6hMD9a5WExi8enfZMWj0HkI2zugEc5-NAmVRik/s1600-h/DSC00002_phixr.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="291" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigfolT_bbt0PA98jMUMY52B9lib2Tn1N_pwmabzONvoFyrXHYWiQtnjAEs1JPIsyCKV9I22jlKRMyV8phWGZfbo2TQJohVI0dFzhBOa6hMD9a5WExi8enfZMWj0HkI2zugEc5-NAmVRik/s400/DSC00002_phixr.gif" width="400" /></a></div><br />
<div class="separator" style="clear: both; color: #073763; text-align: center;"><b></b></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ1s0v8TLTGfob3Y76wOYsJusCeN7SjPTQcKd2m5pBVTURNaoVtcNvGfc8hm4WggBXqY_BgjX4nqZtKw2kEW8MWieuizusQt4e4pDoT0JjiI-cIzvVFjJlPxppp4ciXjHW5OvtFPuzrG0/s1600-h/board2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="253" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ1s0v8TLTGfob3Y76wOYsJusCeN7SjPTQcKd2m5pBVTURNaoVtcNvGfc8hm4WggBXqY_BgjX4nqZtKw2kEW8MWieuizusQt4e4pDoT0JjiI-cIzvVFjJlPxppp4ciXjHW5OvtFPuzrG0/s400/board2.JPG" width="400" /></a></div><div style="color: #073763; text-align: center;"><b>Figure 2.</b> My PIC12F683 Development Board</div><div style="color: #073763; text-align: left;"><br />
</div><div style="text-align: left;"><b>List of things needed:</b><br />
<ol><li>3 general purpose Red LEDs</li>
<li>1 green LED</li>
<li>1 PIC12F683 microcontroller</li>
<li>1 8-pin IC socket</li>
<li>1 7805 regulator IC</li>
<li>1 DC adapter socket</li>
<li>1 BC557 PNP transistor</li>
<li>1 S8050 (or BC547 will work too) NPN transistor</li>
<li>1 piezo buzzer</li>
<li>1 5V DC motor (I got one from an old CD player)</li>
<li>2 5K potentiometers (I got from an old TV circuit board)</li>
<li>2 Tactile switches</li>
<li>Male and Female header pins as required</li>
<li>3 10uf, 50V electrolyte capacitor</li>
<li>1 0.1uf capacitor</li>
<li>3 general purpose diodes</li>
<li>2 4.7K resistances</li>
<li>3 330 Ohms resistances</li>
<li>3 10K resistances</li>
<li>1 1K resistance</li>
<li>1 470 Ohm resistance</li>
<li>1 1.5K resistance </li>
</ol><b> </b><br />
<b>Description:</b><br />
As you see the output LEDs have 470Ω current limiting resistors in series so that a PIC pin can be safely drive them. The piezo buzzer is also driven directly by a PIC pin through a series resistor. The DC motor, however, is connected as a load to the collector of S8050 transistor as the required current to drive the motor cannot be supplied by the PIC port. So, the PIC port can switch on the transistor by pulling its base HIGH and the collector current of the transistor provides the sufficient current to drive the motor. <br />
<br />
The TTL to RS232 level converter and vice-versa is achieved with two transistors and few other components. The negative voltage required for RS232 level (for logic '1') is stolen from the RS232 port of PC itself. Note that there is no hardware UART inside PIC12F683, so the serial data transfer from the microcontroller to PC will be possible only through a software UART through any of GP0, GP1, GP2, GP4, and GP5 ports (GP3 is input only). The transmitter and receiver port on microcontroller side are denoted by uTx and uRx, whereas on the PC side are denoted by Tx and Rx, respectively.<br />
<br />
The circuit diagram shows that the two input tact switches with the two potentiometer outputs and all the eight PIC12F683 pins are accessible through female headers. The tact switches are active low, i.e., under normal condition, a tact switch output is HIGH and when it is pressed, the output is LOW. There are couple of extra headers for Vcc and Gnd terminals which may be required while doing experiments.<br />
<br />
The power supply circuit is the standard circuit of 7805 regulator IC. A power-on LED is connected across Vcc and Gnd with a 470Ω series resistor.<br />
<br />
The in-circuit serial programming (ICSP) of PIC12F683 can be done with two pins: ICSPDAT (pin 7), and ICSPCLK (pin 6). The programming voltage, Vpp, should be provided to pin 4 of PIC12F683 while programming. All the required ISCP pins are available through a male header, so the PIC can be programmed through any ICSP PIC programmer. Make sure that the sequence of ISCP pins on the programmer side and our learning board match.<br />
<br />
<b>Important:</b> During ICSP, pins 4, 6, and 7 of PIC12F683 should not be connected to anything; leave them open so that there won't be any voltage conflict between the programmer and the external circuit. <br />
<br />
<span style="font-size: large;"><i><b>Note: <span style="color: #cc0000;">Turn OFF the power supply switch during ICSP programming.</span></b></i></span><br />
<br />
<b>Software:</b><br />
<br />
If you have made this board, get ready to have fun! <span class="style12" lang="EN-US">You can write your experimental programs for PIC12F683 in assembly or high level language. But for the experiments that I am going to demonstrate here, I am using the free version of mikroC compiler from MikroElektronica. It is a C compiler for PIC microchips, and the free version limits output program size to 2K. But we don't need more than that for PIC12F683.</span><br />
<span class="style12" lang="EN-US"> </span> <br />
<div class="style8"><span class="style12" lang="EN-US">We will use the following configuration bits for PIC12F683. </span></div><div class="style8"><br />
</div><div class="style8"><i><span class="style25" lang="EN-US">Oscillator : Internal RC, No Clock<br />
WDT OFF<br />
Master Clear Disabled<o:p></o:p></span></i></div><div class="MsoNormal"><i><span class="style12" lang="EN-US">For all the experiments demonstrated here, use internal clock at 4.0 MHz.</span></i></div><div class="MsoNormal"><span class="style12" lang="EN-US">In mikroC, you can select these in Edit Project window.</span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="text-align: center;"><b><span class="style12" lang="EN-US">More Snapshots</span></b></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi14CB8sGIC54A4jXO7gjqySNuR3swh5MJPWLSHvuT5IQHhqvumYymQr715BOuuE-P5vZ56FlhHOelY96zuuePln6SWXtExeRkNbdOAOpNQJpbTZBhAe9jMy6Qf_IHiUuPCFpcsYbOQrPA/s1600/photo_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="291" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi14CB8sGIC54A4jXO7gjqySNuR3swh5MJPWLSHvuT5IQHhqvumYymQr715BOuuE-P5vZ56FlhHOelY96zuuePln6SWXtExeRkNbdOAOpNQJpbTZBhAe9jMy6Qf_IHiUuPCFpcsYbOQrPA/s400/photo_6.png" width="400" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9gHVFJ-cZMatxuTSazt-ERVU7EbVYCksHCdXFuTwbeQBl8eYjokY_T_4OYRL48FVB876RiEZ6Iw1MpD-j_aW5q4U1neENJyT5oFLrYAtHZ75q9sLesvUHhSK_GwdlD9EDtfDSY8dabgM/s1600/photo_4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9gHVFJ-cZMatxuTSazt-ERVU7EbVYCksHCdXFuTwbeQBl8eYjokY_T_4OYRL48FVB876RiEZ6Iw1MpD-j_aW5q4U1neENJyT5oFLrYAtHZ75q9sLesvUHhSK_GwdlD9EDtfDSY8dabgM/s400/photo_4.png" width="400" /></a></div></div><center><script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* PIC12F683_336x280_InlineAd, created 9/24/10 */
google_ad_slot = "4387785255";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-7665562587101241008.post-72574861536939217932010-02-04T23:05:00.000-05:002010-02-13T18:58:25.787-05:00PIC12F683: A brief IntroductionPIC12F683 is a 8-pin Flash based, 8bit RISC microcontroller from Microchip. This little PIC microcontroller offers up to 6 I/O pins (the remaining two are power supply pins). It needs no external oscillator, as it has an in-built oscillator with software selectable frequency from 8 MHz to 125 KHz. It also offers a feature that allows external signals to wake it upfrom the sleep state. Here are the various features as mentioned on the datasheet.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3251335376149574";
/* 336x280, pic12f683created 2/13/10 */
google_ad_slot = "6566427410";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<b>High-Performance RISC CPU:</b><br />
• Only 35 instructions to learn:<i> All single-cycle instructions except branches</i><br />
• Operating speed:<br />
<i> - DC – 20 MHz oscillator/clock input<br />
- DC – 200 ns instruction cycle</i><br />
• Interrupt capability<br />
• 8-level deep hardware stack<br />
• Direct, Indirect and Relative Addressing modes<br />
<br />
<b>Special Microcontroller Features:</b><br />
• Precision Internal Oscillator:<br />
<i>- Factory calibrated to ±1%, typical<br />
- Software selectable frequency range of 8 MHz to 125 kHz<br />
- Software tunable<br />
- Two-Speed Start-up mode<br />
- Crystal fail detect for critical applications<br />
- Clock mode switching during operation for power savings</i><br />
• Power-Saving Sleep mode<br />
• Wide operating voltage range (2.0V-5.5V)<br />
• Industrial and Extended temperature range<br />
• Power-on Reset (POR)<br />
• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)<br />
• Brown-out Reset (BOR) with software control option<br />
• Enhanced Low-Current Watchdog Timer (WDT) with on-chip oscillator (software selectable nominal 268 seconds with full prescaler) with software enable<br />
• Multiplexed Master Clear with pull-up/input pin<br />
• Programmable code protection<br />
• High Endurance Flash/EEPROM cell:<br />
<i>- 100,000 write Flash endurance<br />
- 1,000,000 write EEPROM endurance<br />
- Flash/Data EEPROM Retention: > 40 years</i><br />
<br />
<b>Peripheral Features:</b><br />
• 6 I/O pins with individual direction control:<br />
<i> - High current source/sink for direct LED drive<br />
- Interrupt-on-pin change<br />
- Individually programmable weak pull-ups<br />
- Ultra Low-Power Wake-up on GP0</i><br />
• Analog Comparator module with:<br />
<i> - One analog comparator<br />
- Programmable on-chip voltage reference (CVREF) module (% of VDD)<br />
- Comparator inputs and output externally accessible</i><br />
• A/D Converter: <i>10-bit resolution and 4 channels</i><br />
• Timer0: <i>8-bit timer/counter with 8-bit programmable prescaler</i><br />
• Enhanced Timer1:<br />
<i> - 16-bit timer/counter with prescaler<br />
- External Timer1 Gate (count enable)<br />
- Option to use OSC1 and OSC2 in LP mode as Timer1 oscillator if INTOSC mode selected<br />
• Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler</i><br />
• Capture, Compare, PWM module:<br />
- 16-bit Capture, max resolution 12.5 ns<br />
- Compare, max resolution 200 ns<br />
- 10-bit PWM, max frequency 20 kHz<br />
• In-Circuit Serial Programming™ (ICSP™) via two pins<br />
<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlIcnTlUpfo9Gwv-hlXvW4QeFrJowL5gh_6Bc6a4FjpRS1WCUeS-U32b7mywttF4Nx8KHgvnD2I6Ghhe5LSt4l4DfgQKk4A2ZqzeXP735gq21HnFrDbbIIr2YlIa63SOqj3fJtvQ-Ys8/s1600-h/Picture+7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="107" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlIcnTlUpfo9Gwv-hlXvW4QeFrJowL5gh_6Bc6a4FjpRS1WCUeS-U32b7mywttF4Nx8KHgvnD2I6Ghhe5LSt4l4DfgQKk4A2ZqzeXP735gq21HnFrDbbIIr2YlIa63SOqj3fJtvQ-Ys8/s400/Picture+7.png" width="400" /></a></div><br />
<br />
The I/O port of PIC12F683 is called the GPIO (<b>g</b>eneral <b>p</b>urpose <b>i</b>nput/<b>o</b>utput file register), and the corresponding data direction register is TRISIO. It works mostly the same way as ports in other PIC microcontrollers. Setting a TRISIO bit (= 1) will make the corresponding GPIO pin an input, and clearing the TRISIO bit (= 0) will make it an output. One important thing to note is that GP3 is input only pin, and cannot be configured as an output.<br />
<br />
PIC12F683 has a 13-bit program counter that can address up to 8K x 14 program memory, but only the first 2K x 14 (0000h-07FFh) is physically implemented. PIC12F683 also has 256 bytes of data EEPROM with an address range from 0h to FFh.<br />
For details, read the <a href="http://ww1.microchip.com/downloads/en/devicedoc/41211B.pdf">datasheet</a>.Unknownnoreply@blogger.com0