<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>edeca.net &#187; Electronics</title>
	<atom:link href="http://edeca.net/wp/category/electronics/feed/" rel="self" type="application/rss+xml" />
	<link>http://edeca.net/wp</link>
	<description>Musings of a geek</description>
	<lastBuildDate>Tue, 14 Feb 2012 00:18:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The ST7565 display controller</title>
		<link>http://edeca.net/wp/2012/02/the-st7565-display-controller/</link>
		<comments>http://edeca.net/wp/2012/02/the-st7565-display-controller/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 20:36:18 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[glcd]]></category>
		<category><![CDATA[st7565]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=695</guid>
		<description><![CDATA[This post covers the theory of using a graphic LCD based on the ST7565 controller. These are widely available with popular sizes of 132&#215;32 and 128&#215;64, a number cost below £10. (Image © Electronic Assembly, lcd-module.de) The tutorial follows the same path I took whilst developing a simple library for a screen I had bought. [...]]]></description>
			<content:encoded><![CDATA[<p>This post covers the theory of using a graphic LCD based on the ST7565 controller. These are widely available with popular sizes of 132&#215;32 and 128&#215;64, a number cost below £10.</p>
<p><img class="aligncenter size-full wp-image-725" title="EADOGL28B" src="http://edeca.net/wp/wp-content/uploads/2012/02/ea_dogl128b-6.jpg" alt="" width="150" height="146" /></p>
<p><em>(Image © Electronic Assembly, lcd-module.de)</em></p>
<p>The tutorial follows the same path I took whilst developing a simple library for a screen I had bought. I set myself the challenge of doing this from scratch, rather than using code from the internet.</p>
<p><span id="more-695"></span></p>
<p>Whilst this post uses a 128&#215;64 screen as an example it is equally applicable to different sizes. <em></em></p>
<h4>Pros:</h4>
<ul>
<li>Easy to interface using fewer pins than other graphic LCDs</li>
<li>Onboard voltage booster for the liquid crystal display</li>
<li>Software controlled contrast and rotation</li>
<li>Works at faster clock speeds</li>
<li>Good selection of backlight colours</li>
</ul>
<h4>Cons:</h4>
<ul>
<li>3.3v logic only (not such a problem any more)</li>
<li>In SPI mode a large buffer is required in local memory</li>
</ul>
<h2>Getting started</h2>
<p>The most important thing needed when developing a library is a good datasheet. The information provided by screen manufacturers is often lacking in detail or quality.  The datasheet I used can be <a href="http://edeca.net/downloads/electronics/ST7565R_V17_960601.pdf" target="_blank">found here</a>.</p>
<h2>Basic operation (hardware)</h2>
<p>The most basic pinout for the ST7565 is shown below.  To drive it from a microcontroller in SPI mode 5 pins are required.  All of these pins are outputs from the microcontroller and inputs to the screen.  Because it is not possible to read from the screen there is no requirement for inputs.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-SPI-pinout.png"><img class="aligncenter size-medium wp-image-834" title="ST7565 - SPI pinout" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-SPI-pinout-300x273.png" alt="" width="300" height="273" /></a></p>
<p>It is necessary to connect RESET to the microcontroller as the initialisation procedure involves toggling this pin.  This pin should not be tied high or low or it may not be possible to reset the screen correctly.</p>
<p>Depending on your GLCD module it may be necessary to connect a number of capacitors, this is discussed in the next section.</p>
<h4>Voltage boosting and regulation</h4>
<p>The ST7565 has an integrated voltage booster (charge pump) circuit that can provide the high voltages needed by the liquid crystal display. If the circuit only has a single supply such as 3.3v then the charge pump is the easiest way to power the screen. If the circuit contains a voltage source of between 9v and 12v then it is possible to reduce the number of external components needed by using this directly.</p>
<p>The internal booster can provide from 2x to 6x the input voltage depending on how capacitors are connected between the CAPxx terminals. Full details are provided on page 31 to 34 of the datasheet above. The only limitation is that the maximum voltage after boosting must not exceed Vout, which is 13.5v.</p>
<p>Many LCD specific datasheets will provide the exact capacitors required for a particular model. For some display modules these capacitors are included on the circuit board and do not need to be added.  Check the datasheet carefully!  For example, the image below is taken from the datasheet for an inexpensive model available from Mouser, the EA DOGM132-5:</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/Screen-Shot-2012-02-04-at-14.44.02.png"><img class="aligncenter size-medium wp-image-762" title="Example capacitors for an ST7565 screen" src="http://edeca.net/wp/wp-content/uploads/2012/02/Screen-Shot-2012-02-04-at-14.44.02-300x135.png" alt="" width="300" height="135" /></a></p>
<p><em>(© Electronic Assembly, lcd-module.de)</em></p>
<p>In addition to the voltage booster the ST7565 contains an integrated voltage regulator. This has 8 steps and regulates the reference voltage used to drive the liquid crystal display. It is necessary to find a value between 0 and 7 which works well with the specific hardware as this is used with the dynamic contrast feature.  Typically a &#8220;middle&#8221; value such as 3 will work with any screen.</p>
<h2>Basic operation (software)</h2>
<p>SPI mode provides an easy mechanism to drive the screen using few pins.  A single bit is written to the data pin and the clock is pulsed high then low.  The implementation of SPI by the ST7565 is fairly standard, more information can be found on the <a href="http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus">Wikipedia SPI Bus</a> page.</p>
<p>One limitation of using the screen in SPI mode is that it only supports writing commands or data. It is not possible to read from the screen therefore it is necessary to keep a copy of the current screen data in memory on the microcontroller. The size of this software buffer can be calculated easily, there are 128 columns and 64 rows for a total of 8192 bits (1 bit per pixel for black and white). Therefore 1024 bytes in total are required to store a copy of the screen, which can be a large amount on many smaller microcontrollers.</p>
<p>With software (&#8216;bit banged&#8217;) SPI it is possible to use the screen at very fast clock speeds. On an PIC 18F I have used my screen with a 64Mhz internal oscillator and it works absolutely fine. It is possible to calculate (or simulate/measure) whether the microcontroller can exceed the ST7565 minimum clock period.</p>
<h4>Screen layout</h4>
<p>Unlike displays using the KS0108 the ST7565 has a single controller for the whole screen. There is no need to swap between the left and right in order to send commands.</p>
<p>A 128&#215;64 screen is made up of 8 pages, each of which is 8 pixels high and 132 wide. This maps nicely to the software buffer required for caching the screen contents because each page is a byte high.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-outline-light-pixels-pages.png"><img class="aligncenter size-medium wp-image-753" title="ST7565 - pages" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-outline-light-pixels-pages-300x170.png" alt="" width="300" height="170" /></a></p>
<p><em></em>It is easiest to imagine the top left of the screen as 0,0 and the bottom right as 127,63. This makes some of the maths required in software much easier.  To write data at (0,0) it is necessary to select page 0, column 0 and then set the individual bit.  In contrast the location (32,32) is in page 5.  The simplest method of writing data to the screen is to send a whole page at a time, starting from the left in column 0 and continuining to the right at column 127.</p>
<h4>Sending a command to the screen</h4>
<p>Issuing a single command to the screen is the most basic building block of the interface code.  The steps required are:</p>
<ul>
<li>Set the A0 pin low to indicate that command data is being sent</li>
<li>Set the chip select (CS) pin low</li>
<li>Send each bit of the command, starting with the <em>most significant</em> bit and working down to the <em>least significant</em></li>
<li>Set the chip select (CS) pin high, to free the bus</li>
</ul>
<p>Therefore the &#8220;display on&#8221; command (which is 0xAF or 0b10101111) should be sent as: 1, 0, 1, 0, 1, 1, 1, 1.</p>
<p>As long as the SPI timings are not violated there is no need to introduce any delays as the screen will never be &#8220;busy&#8221;.</p>
<h4>Screen initialisation</h4>
<p>Now that we can send a single command to we need to follow a number of steps to setup the screen.</p>
<ul>
<li>Strobe the RESET pin low then high, to initiate a hardware reset</li>
<li>Setup the duty cycle (either 1/7 or 1/9) depending on the physical LCD</li>
<li>Set the horizontal and vertical orientation to a known state</li>
<li>Configure the internal resistor divider which is used by the voltage regulator</li>
<li>Turn on the internal voltage booster to provide power to the LCD glass</li>
<li>Initialise the dynamic contrast to a default value</li>
<li>Reset the current display position to the top left</li>
</ul>
<p>The commands for these are a single byte except the dynamic contrast, which is explained later.  Below is an image captured from a logic analyser while the initialisation code runs.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Screen-initialisation1.png"><img class="aligncenter size-medium wp-image-805" title="ST7565 - Screen initialisation" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Screen-initialisation1-300x58.png" alt="" width="300" height="58" /></a></p>
<p>In this trace the following things can be seen:</p>
<ul>
<li>Command 0xA2: set the LCD bias to 1/9th</li>
<li>Command 0xA0: horizontally &#8220;normal&#8221; (not flipped)</li>
<li>Command 0xC8: vertically &#8220;flipped&#8221; (complements the command above)</li>
<li>Command 0&#215;23: the internal resistor divider set to 3 (from 0..7)</li>
<li>Command 0x2F: power control, all internal blocks ON</li>
<li>Command 0&#215;81: enter dynamic contrast mode</li>
<li>Data for the dynamic contrast mode, set to 31 (from 0..63)</li>
<li>Command 0&#215;40: go back to the top left of the display</li>
</ul>
<p>When power is first applied to the screen it is also important to clear the onboard screen memory. As it is non-volatile RAM it will start in an unknown state.</p>
<h4>Sending data to the screen</h4>
<p>The only difference between sending a command and data is the A0 pin.  When sending data the A0 pin must be high to differentiate</p>
<p>To start we send a command to reset the position to the top left corner (0,0). After this a quick trick is to write a single byte and see how it is displayed. It is important to know which way round the screen will display the data it receives, whether the &#8220;most significant bit&#8221; or &#8220;least significant bit&#8221; is displayed at the top.  The illustration below shows the output if the byte 0&#215;80 is sent four times to the screen:</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Basic-data.png"><img class="aligncenter size-medium wp-image-779" title="ST7565 - Basic data" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Basic-data-300x190.png" alt="" width="300" height="190" /></a></p>
<p>From this it can be seen that the <em>most</em> significant bit displays at the bottom of the page.  That is the first bit we send is at the bottom, then subsequent bits work upwards toward the top of the page.  This will be important later when we try to set an individual pixel.</p>
<h4>Displaying a basic test pattern</h4>
<p>The easiest way to test if the driver code is working is to send a very basic test pattern. A quick check is to send constant bytes of 0xFF to fill the screen. If this works then variations can be tried, such as 0xF0 or 0xAA.</p>
<p>At the end of each row, after every 128 bytes, it is necessary to select the next page and move to the start of the row.  The following image is the basic test card I used to demonstrate that my display was wired up correctly.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/IMG_0631.jpg"><img class="aligncenter size-medium wp-image-825" title="ST7565 - Test card" src="http://edeca.net/wp/wp-content/uploads/2012/02/IMG_0631-300x225.jpg" alt="" width="300" height="225" /></a></p>
<h4>Writing to specific pixels</h4>
<p>Writing specific pixels opens up a whole world of possibilities from lines, circles, 1 bit-per-pixel graphics and variable height fonts. As these graphics functions are not dependant on a specific controller or screen it is best to split them out into a separate library which is portable across any screen.  This is perhaps the most difficult portion whilst developing a library to work with any screen.</p>
<p>In order to set a specific pixel it is necessary to break the process into a number of steps:</p>
<ul>
<li> Find the corresponding byte in the software buffer</li>
<li>Calculate the bit within this byte</li>
<li>Use logical XOR (to set the bit) or AND (to clear the bit)</li>
</ul>
<p>Finding the correct byte is straightforward.  The first position in our array is at the top left of the screen.  The 128th byte in the array (Array[127]) is on the first page at the right hand side of the screen.  The next bit &#8220;wraps&#8221; to the next page, at page 1 column 1.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Relationship-to-software-buffer1.png"><img class="aligncenter size-medium wp-image-842" title="ST7565 - Relationship to software buffer" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Relationship-to-software-buffer1-300x192.png" alt="" width="300" height="192" /></a></p>
<p>To calculate which byte we need to use we need to divide the Y position by 8 and multiple the result by 128.  To this we add the X position, then subtract 1 (as C arrays start from 0).  The equation X + ( ( Y / 8 ) * 128 ) &#8211; 1 works well in C.  To verify this is correct:</p>
<ul>
<li>(1,1) on the screen would give 1 + ( 1 / 8 ) * 128 &#8211; 1 = 0</li>
<li>(61,52) on the screen would give 61 + ( 52 / 8 ) * 128 &#8211; 1 = 828</li>
</ul>
<p>To calculate the bit inside this byte we must remember that the 8th (most significant) bit appears at the bottom of the page.  So to write to Y location 8 we need to set the 8th bit of a byte on the first page.  To write to Y location 16 we need to write to the 8th bit of the corresponding byte on the second page.  Therefore we need the remainder after the Y position is divided by 8, which can be found using the <a href="http://en.wikipedia.org/wiki/Modulo_operation">modulo operator</a>.  This is as simple as Y % 8:</p>
<ul>
<li>(1,1) means setting 1 % 8 = the 1st bit</li>
<li>(61,49) means setting 49 % 8 = the 1st bit</li>
<li>(61,53) means setting 53 % 8 = the 5th bit</li>
</ul>
<p>It is now possible to set the correct bit inside the byte, on PIC microcontrollers this can be achieved using very efficient bit operators such as bsf or bcf.</p>
<h4>Displaying text</h4>
<p>Like many other graphic LCDs the ST7565 has no built-in font.  The quickest &amp; easiest way of displaying text on this screen is to define an 8 pixel high font. This maps directly to one page (or &#8216;line&#8217;) of the display and therefore we can use very fast instructions to copy the data from a predefined font to the right area of the screen.</p>
<p>However this limits us to a fixed height and only 8 lines of the screen. Now that we know how to set individual pixels there are much nicer ways of displaying text. Consider the following image:</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/IMG_0629.jpg"><img class="aligncenter size-medium wp-image-824" title="ST7565 - Variable size fonts" src="http://edeca.net/wp/wp-content/uploads/2012/02/IMG_0629-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Larger fonts take up more room but can be used to provide a much nicer looking user interface for a project.  With the knowledge that we can set a specific pixel it is easy to make advanced graphics functions.  However these are separate to the ST7565 screen itself, so I will cover them in a future blog post.  Impatient readers can check my <a href="https://github.com/edeca/Electronics/blob/master/Include/graphics.h">graphics library</a> (Doxygen documentation <a href="http://edeca.net/temp/Documentation/html/graphics_8h.html">can be found here</a>).</p>
<h2>Using advanced features</h2>
<p>So far all of the features are common to all standard graphic LCDs. However there are a number of additional tricks that ST7565 based displays can offer.</p>
<h4>Inverting the screen</h4>
<p>With a single command the ST7565 can be instructed to invert the display.  This can be useful for emphasis or to make the screen easier to read in certain situations.  The command &#8220;display normal or reverse&#8221; is 0b1010011X, where X is 1 for reversed or 0 for normal.</p>
<p>The picture below shows the same font demonstration as above, but with the inverse feature turned on.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/IMG_0626.jpg"><img class="aligncenter size-medium wp-image-823" title="ST7565 - Inverse screen" src="http://edeca.net/wp/wp-content/uploads/2012/02/IMG_0626-300x225.jpg" alt="" width="300" height="225" /></a></p>
<h4>Blacking the screen</h4>
<p>The ST7565 is capable of setting all points on the display to black without affecting the screen RAM.  Whilst it is hard to think of a situation where this might be useful the command &#8220;display all points&#8221; is a single byte and can be used to turn the display black if required.</p>
<h4>Dynamic contrast control</h4>
<p>Unlike other common graphic LCDs the contrast for the ST7565 is set by an internal resistor divider. This means that it can be set in software and altered dynamically. To change the contrast we need to send two commands. The first enters &#8220;volume mode set&#8221; and the second sets the contrast from 0..63.</p>
<p>The number of useful steps may be less than 64, on my test screen the visible steps are from 12 (very light) to 40 (very dark). Lower values are not visible as the voltage is too low, higher values make the screen completely black as there is no distinction between pixels which are off or on.</p>
<p>This feature could be used with a light sensor to dim the screen depending on ambient conditions. It can also be used to fade the screen in or out.</p>
<h4>Screen rotation and mirroring</h4>
<p>In the same way that the screen can be inverted without affecting the display data it is possible to flip the screen in either the horizontal or vertical direction.  This means that the screen can be used either way up with no changes required to the software except sending extra two commands to the screen.</p>
<p>Flipping the screen horizontally (from left to right) is achieved with the confusingly named &#8220;ADC Select&#8221; command.  Flipping the screen vertically (from top to bottom) is possible with the &#8220;COM Output Mode Select&#8221; command.  Unless you want to view the screen in a mirror it is necessary to use both commands at once!</p>
<p>As mentioned earlier the memory on the screen is actually 132 columns wide, to support a maximum screen size of 132&#215;64.  On 128 pixel wide models there is an important consideration if rotating the display.  If the screen is not rotated as the extra 4 rows are on the right hand side and not visible, as illustrated below:</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Normal-screen.png"><img class="aligncenter size-medium wp-image-741" title="ST7565 - Normal orientation" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Normal-screen-300x202.png" alt="" width="300" height="202" /></a><em class="aligncenter size-medium wp-image-741" title="ST7565 - Normal orientation"></em></p>
<p>&nbsp;</p>
<p>When the screen is rotated the controller outputs these columns in the opposite order, <em>starting with the last column</em>.  Therefore the unused 4 columns from the screen memory are output first, leaving an empty space on the left hand side.</p>
<p>&nbsp;</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Rotated-screen.png"><img class="aligncenter size-medium wp-image-742" title="ST7565 - Rotated screen" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Rotated-screen-300x202.png" alt="" width="300" height="202" /></a><em></em></p>
<p>In order fix this it is necessary to keep track in software of whether the screen is rotated or not.  When it is rotated the column address should be incremented by 4 each time a new line is sent to the screen, skipping the extra columns which would otherwise be displayed.</p>
<h2>Improving efficiency</h2>
<p>Refreshing the screen involves sending the entire local buffer to the screen RAM. If only a few changes have been made then this is a very inefficient way to update the screen.</p>
<p>It would be possible to send each individual write to the screen, simply by copying the single byte that has changed each time a pixel is written. However this is inefficient if more than a single bit (or pixel) is set in the same byte in subsequent operations. Changes to the screen would also be very visible at slower speeds.</p>
<p>As the screen has 8 pages the most efficient method on a small microcontroller is to send only the pages which have changed. Each time a pixel is set or cleared the corresponding page in the local buffer is marked as &#8216;dirty&#8217;. When it comes to refreshing the screen only the dirty pages are transferred.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Improving-efficiency.png"><img class="aligncenter size-medium wp-image-746" title="ST7565 - Improving efficiency" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-Improving-efficiency-300x175.png" alt="" width="300" height="175" /></a><em></em></p>
<p>In the example above only pages 2 and 5 have had changes made.  Therefore these will be sent to the screen, which takes 1/4 of the time as sending all 8 pages.</p>
<p>The screen could be subdivided into even smaller regions, for example 16 half pages. The trade-off of extra code each time a pixel is set and the reduced bus time sending data should be considered carefully.</p>
<p>&nbsp;</p>
<h3>Verifying speeds</h3>
<p>Above I commented that it was possible to run a PIC at 64Mhz and not violate the SPI timings.  The important values are shown in Table 28 of the datasheet:</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-SPI-timings.png"><img class="aligncenter size-medium wp-image-784" title="ST7565 - SPI timings" src="http://edeca.net/wp/wp-content/uploads/2012/02/ST7565-SPI-timings-300x116.png" alt="" width="300" height="116" /></a></p>
<p>We are interested in Tscyc, Tshw and Tslw.  These relate to the total clock cycle, the HIGH portion of the cycle and the LOW portion respectively.  The overall clock pulse must be <em>at least</em> 50ns and the high and low portions must be <em>at least</em> 25ns each.</p>
<h4>Crunching the numbers</h4>
<p>Assume that the SPI code turns ON the clock pin and then OFF again immediately in 2 instructions.  The pin will be HIGH at the end of the first instruction and LOW again after the second, therefore it is only HIGH for the period of 1 instruction.</p>
<p>On the PIC 12/16/18 family of microcontrollers each instruction takes 4 cycles.  At 64Mhz this means that each instruction takes 1/(64000000/4) seconds, or 62.5ns.  From this we can expect that the HIGH period of the clock pulse should be about 62.5ns, easily within the required timings.</p>
<h4>Checking with a logic analyser</h4>
<p>It is also possible to measure and see how long the pulse lasts on real hardware.  The screenshot below shows the HIGH portion of the clock pulse being measured, this is the shortest part of the cycle.  The PIC being used is an 18F25K22 running at 64Mhz.  The code toggles the pin ON and OFF in two instructions.</p>
<p><a href="http://edeca.net/wp/wp-content/uploads/2012/02/screenshot3.png"><img class="aligncenter size-medium wp-image-788" title="ST7565 - Verifying the clock pulse" src="http://edeca.net/wp/wp-content/uploads/2012/02/screenshot3-300x193.png" alt="" width="300" height="193" /></a></p>
<p>Remember that it must be at least 25ns long in order to be acceptable.  The measurement shows 41.7ns, which is shorter than calculated but still acceptable.  A number of reasons could produce the difference between our calculation and the physical measurement:</p>
<ul>
<li>The resolution of the logic analyser (24Mhz in this example) might not be sufficient for the measurement.</li>
<li>Setting or clearing bits in hardware might not take the entire 4 cycles.</li>
<li>The PIC might not be running at exactly 64Mhz due to instability of the oscillator or PLL.</li>
</ul>
<p>&nbsp;</p>
<h2>See also</h2>
<p>If you are interested in using a ST7565 based screen in an Arduino project then you should check out <a href="http://www.ladyada.net/learn/lcd/st7565.html" target="_blank">Ladyada&#8217;s tutorial</a> on Adafruit.  My <a href="https://github.com/edeca/Electronics/blob/master/Include/st7565.h">C library is available</a> which was designed for PIC 18F parts with HiTech C.  It would be trivial to change for another compiler or chip.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2012/02/the-st7565-display-controller/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eagle outline for the Evatron PC00 series enclosure</title>
		<link>http://edeca.net/wp/2011/12/eagle-outline-for-the-evatron-pc00-series-enclosure/</link>
		<comments>http://edeca.net/wp/2011/12/eagle-outline-for-the-evatron-pc00-series-enclosure/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 21:35:54 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[eagle]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[enclosures]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=687</guid>
		<description><![CDATA[I found a neat plastic enclosure with a battery compartment that I plan on using for a current project. It is made by Evatron and comes from the PC00 series (I picked a PC003N). Below is a ZIP file containing the case drawn in Eagle to measurements from the datasheet. A dimension layer is included [...]]]></description>
			<content:encoded><![CDATA[<p>I found a neat plastic enclosure with a battery compartment that I plan on using for a current project.  It is made by Evatron and comes from the PC00 series (I picked <a href="http://tinyurl.com/c8j3d2n">a PC003N</a>).</p>
<p>Below is a ZIP file containing the case drawn in Eagle to measurements from the datasheet.  A dimension layer is included that makes the most of the internal space.<br />
<a href="http://edeca.net/wp/wp-content/uploads/2011/12/Evatron-PC00-series.png"><img src="http://edeca.net/wp/wp-content/uploads/2011/12/Evatron-PC00-series-300x102.png" alt="" title="Evatron PC00 series" width="300" height="102" class="aligncenter size-medium wp-image-689" /></a></p>
<p class="download"><a href="http://edeca.net/downloads/electronics/Evatron PC00 series.zip">Download the Eagle board file</a> &#8211; free for any use (but credit is nice)</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2011/12/eagle-outline-for-the-evatron-pc00-series-enclosure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BatchPCB</title>
		<link>http://edeca.net/wp/2011/04/batchpcb/</link>
		<comments>http://edeca.net/wp/2011/04/batchpcb/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 20:37:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[batchpcb]]></category>
		<category><![CDATA[pcb]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=641</guid>
		<description><![CDATA[I have previously raved about BatchPCB, a low cost prototyping service run by SparkFun out of the USA. However, it seems that you now can&#8217;t select shipping to the UK (and perhaps other parts of Europe) and they don&#8217;t seem to be doing too much about it. I emailed a few weeks ago and have [...]]]></description>
			<content:encoded><![CDATA[<p>I have previously raved about <a href="http://batchpcb.com">BatchPCB</a>, a low cost prototyping service run by SparkFun out of the USA.  However, it seems that you now can&#8217;t select shipping to the UK (and perhaps other parts of Europe) and they don&#8217;t seem to be doing too much about it.  </p>
<p>I emailed a few weeks ago and have received no reply, so all I have to go on is a few posts <a href="http://forum.sparkfun.com/viewtopic.php?f=16&#038;t=26198">on</a> <a href="http://forum.sparkfun.com/viewtopic.php?f=16&#038;t=25511&#038;start=15">their</a> <a href="http://forum.sparkfun.com/viewtopic.php?f=16&#038;t=26962">forums</a> which confirm I&#8217;m not the only one experiencing the issue.</p>
<p>So BatchPCB, unless you can get this fixed I&#8217;m afraid I&#8217;ll be seeking an alternative.  Comments suggesting other cheap PCB fabrication houses welcome, I&#8217;ll probably try <a href="http://dorkbotpdx.org/wiki/pcb_order">DorkbotPDX</a> first.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2011/04/batchpcb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCB antenna design</title>
		<link>http://edeca.net/wp/2010/12/pcb-antenna-design/</link>
		<comments>http://edeca.net/wp/2010/12/pcb-antenna-design/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 10:28:23 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[antenna]]></category>
		<category><![CDATA[pcb]]></category>
		<category><![CDATA[rf]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=607</guid>
		<description><![CDATA[One of the circuit boards I&#8217;m developing would benefit from an onboard antenna, so I started hunting for design tips.  The following three PDF documents do a great job of explaining the basics: Freescale &#8220;Compact Integrated Antennas&#8220; Kent Smith &#8220;Antennas for low power applications&#8220; Ingecom &#8220;V / UHF Antenna Design&#8220; I will update the blog [...]]]></description>
			<content:encoded><![CDATA[<p>One of the circuit boards I&#8217;m developing would benefit from an onboard antenna, so I started hunting for design tips.  The following three PDF documents do a great job of explaining the basics:</p>
<ul>
<li>Freescale &#8220;<a href="http://www.freescale.com/files/rf_if/doc/app_note/AN2731.pdf">Compact Integrated Antennas</a>&#8220;</li>
</ul>
<ul>
<li>Kent Smith &#8220;<a href="http://www.numatechnologies.com/pdf/foilantennas.pdf">Antennas for low power applications</a>&#8220;</li>
</ul>
<ul>
<li>Ingecom &#8220;<a href="http://www.numatechnologies.com/pdf/an_antenna.pdf">V / UHF Antenna Design</a>&#8220;</li>
</ul>
<p>I will update the blog once the circuit board is designed and I have managed to test range and effectiveness.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/12/pcb-antenna-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCB0002 &#8211; LED matrix</title>
		<link>http://edeca.net/wp/2010/10/pcb0002-led-matrix/</link>
		<comments>http://edeca.net/wp/2010/10/pcb0002-led-matrix/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 12:31:20 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[pcb]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=556</guid>
		<description><![CDATA[It has been ages since I have updated this site. I have started to document some of the PCBs I have created The first is an 8&#215;8 LED matrix, with code for some whizzy effects. More information and downloads on this page. If anybody wants to see the code, I could tidy it up a [...]]]></description>
			<content:encoded><![CDATA[<p>It has been ages since I have updated this site. I have started to document some of the PCBs I have created </p>
<p>The first is an 8&#215;8 LED matrix, with code for some whizzy effects.  More information and downloads <a href="http://edeca.net/wp/electronics/pcb0002-led-matrix/">on this page</a>.</p>
<p>If anybody wants to see the code, I could tidy it up a bit and post with some explanation.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/10/pcb0002-led-matrix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cooking with gas, my first SMD board</title>
		<link>http://edeca.net/wp/2010/05/cooking-with-gas-my-first-smd-board/</link>
		<comments>http://edeca.net/wp/2010/05/cooking-with-gas-my-first-smd-board/#comments</comments>
		<pubDate>Mon, 10 May 2010 18:30:29 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=512</guid>
		<description><![CDATA[My first bunch of boards arrived back from BatchPCB and I&#8217;m really impressed.  Great printing for the silkscreen and a really professional looking product.  One of the boards I ordered was a breakout board for the SMD PIC 18F2321, the first surface mount board I have tried. The original board was designed and kindly sent [...]]]></description>
			<content:encoded><![CDATA[<p>My first bunch of boards arrived back from BatchPCB and I&#8217;m really impressed.  Great printing for the silkscreen and a really professional looking product.  One of the boards I ordered was a breakout board for the SMD PIC 18F2321, the first surface mount board I have tried.<br />
<span id="more-512"></span><br />
The original board was designed and kindly sent to me by 3v0, I tidied up the silkscreen before shipping it off to be produced.</p>
<div id="attachment_513" class="wp-caption aligncenter" style="width: 285px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-board.png"><img class="size-full wp-image-513" title="PCB0001 board" src="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-board.png" alt="" width="275" height="137" /></a><p class="wp-caption-text">Copper layers</p></div>
<p style="text-align: left;">
<div id="attachment_514" class="wp-caption aligncenter" style="width: 285px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-silkscreen.png"><img class="size-full wp-image-514" title="PCB0001 silkscreen" src="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-silkscreen.png" alt="" width="275" height="137" /></a><p class="wp-caption-text">Silkscreen</p></div>
<p style="text-align: left;">This board uses 0803 SMD parts, but boy are they tiny.  These are some of the larger surface mount components, I definitely would not try the smaller ones.  After applying paste by hand to the board (I used <a href="http://uk.farnell.com/edsyn/cr44/solder-paste-in-syringe/dp/876768">this stuff</a>) I carefully placed the components using a <a href="http://uk.farnell.com/shesto/cl5044/seizer-straight-jaw-125mm/dp/202708">pair of tweezers</a> I bought specially.</p>
<p style="text-align: left;">Most board houses will apply a solder mask to manufactured PCBs, this is a special layer on top of the board that covers up everything except the pads.  This means a thin line of paste can be run along all the pins of the chip, there is no need to try and put an individual dot on every pad!  As the paste heats up and turns into solder the flux will evaporate and surface tension pulls the solder paste back onto each pad.</p>
<p style="text-align: left;">The original board, paste and tweezers can be seen in the image below.</p>
<p style="text-align: left;">
<div id="attachment_517" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-tools.jpg"><img class="size-medium wp-image-517" title="SMD tools" src="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-tools-300x199.jpg" alt="" width="300" height="199" /></a><p class="wp-caption-text">SMD board tools</p></div>
<p style="text-align: left;">After assembly came the fun bit, cooking time!  I kept an old frying pan specially for this, into which I placed the board.  Cooking time was no more than a few minutes, it is very visible when the paste starts to reflow and turn into molten solder.  As soon as that happened I turned off the gas hob and left it to cool.</p>
<p style="text-align: left;">
<div id="attachment_518" class="wp-caption aligncenter" style="width: 209px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/Cooking-SMD-PCB.jpg"><img class="size-medium wp-image-518" title="Cooking SMD PCB" src="http://edeca.net/wp/wp-content/uploads/2010/05/Cooking-SMD-PCB-199x300.jpg" alt="" width="199" height="300" /></a><p class="wp-caption-text">Cooking an SMD PCB!</p></div>
<p>Note that the oven thermometer really doesn&#8217;t work, it had barely reached 50°C by the time the board was finished.  A non contact IR thermometer apparently works much better and should be considered if you want to roughly follow a specific reflow profile.</p>
<p style="text-align: left;">The final result is shown below, after the header pins were hand soldered.</p>
<p style="text-align: left;">
<div id="attachment_519" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/Finished-SMD-PCB.jpg"><img class="size-medium wp-image-519" title="Finished SMD PCB" src="http://edeca.net/wp/wp-content/uploads/2010/05/Finished-SMD-PCB-300x199.jpg" alt="" width="300" height="199" /></a><p class="wp-caption-text">The finished SMD PCB</p></div>
<p style="text-align: left;">Did it work first time?  Well, mostly.  The PIC powered up, the LED blinked on and it talked to PICKit2 on the PC.  After a little examination I found that two of the pads on the chip were not properly soldered, which played havoc with some code I was writing.</p>
<p style="text-align: left;">Next time I think I would use more paste, I was quite frugal with the syringe and had to fix the two bad joints by hand.  I also probably wouldn&#8217;t design all future PCBs as SMD, populating and reflowing the board is easy but the parts are fairly expensive compared to standard &#8220;through hole&#8221; alternatives.</p>
<p style="text-align: left;">One more picture now of it in use.  This little thing really speeds up prototyping time, no need to connect a pull-up resistor, power and ICSP lines manually.  If only writing code was so easy..</p>
<p style="text-align: left;">
<div id="attachment_523" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-breakout-in-use.jpg"><img class="size-medium wp-image-523" title="SMD breakout in use" src="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-breakout-in-use-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">SMD breakout in use with a graphic LCD</p></div>
<p>For more information, watch this <a href="http://www.youtube.com/watch?v=lqYjPJJBiZo">useful video</a> on Youtube and read the excellent <a href="http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=36">SMD How To</a> from Sparkfun.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/05/cooking-with-gas-my-first-smd-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the hardware USART with BoostC and a PIC</title>
		<link>http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/</link>
		<comments>http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 17:08:17 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=416</guid>
		<description><![CDATA[This post looks at what is needed to get a serial connectiong working with BoostC using a PIC with a hardware USART. A later post will cover the BoostC software implementation, when I have finished figuring it out. By the end of this post there will be a PIC uC talking to Hyperterminal on the [...]]]></description>
			<content:encoded><![CDATA[<p>This post looks at what is needed to get a serial connectiong working with <a href="http://www.sourceboost.com/">BoostC</a> using a PIC with a hardware USART.  A later post will cover the BoostC software implementation, when I have finished figuring it out.</p>
<p>By the end of this post there will be a PIC uC talking to Hyperterminal on the PC using less than 50 lines of code.<br />
<span id="more-416"></span></p>
<h3>Pros &amp; cons of using the BoostC library</h3>
<p>There main advantage to using this library to implement serial communication is that it sets up all registers and control bits for you (including <tt>TRIS</tt> for the <tt>TX</tt> and <tt>RX</tt> pins).  This means limited digging around in the datasheet, you can code without worrying about the underlying hardware.</p>
<p>However it may be a disadvantage too.  The limited control over the hardware means that certain things are fixed.  For example, 8-bit transmission is the default.  It might be possible to change these by modifying the PIC registers directly but I haven&#8217;t tried this yet.  Leave a comment if you know it works!</p>
<h3>Requirements</h3>
<p>A few things are necessary to make this work.  Firstly a PIC with hardware USART support, in this post I&#8217;ll be using the PIC 18F1320 as an example.  The hardware USART is listed under &#8220;peripherals&#8221; in datasheets.</p>
<p>In order to talk to a PC we also need some form of level convertor from logic levels (+5v/0v) to <a href="http://en.wikipedia.org/wiki/RS-232">RS-232</a> (maximum voltage range +12/-12v).  I use a MAX232 breakout board that I built myself, but <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=449">this board</a> or <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=133">this board</a> from Sparkfun should work just fine.</p>
<h3>Connecting it up</h3>
<p>The purpose of this post isn&#8217;t to discuss connectivity, but briefly the PIC <tt>TX</tt> and <tt>RX</tt> pins need to be connected to the level shifter, as do +5v and GND.  The serial pins on the PIC can be found in diagrams in the datasheet.  Remember which pins they are as they are needed later.</p>
<h3>Find the right values</h3>
<p>The BoostC library is incredibly easy to use but there are a three values to work out first.  Remember the choices so they can be used in the code later.</p>
<h4>bit_time</h4>
<p>The first value is <tt>bit_time</tt>, which is the number of CPU instruction cycles per bit (note that the header file says this is used by the software USART, but code will not compile without it so it is included here for reference).</p>
<p>Take the clock speed in hz, divide by four and then divide by your desired bit rate.  I recommend starting slow (e.g. 1200 baud) and trying to faster when it works, so for an 8Mhz clock and 1200 baud we get:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">bit_time = 8000000 / 4 / 1200<br />
bit_time = 1666</div></div>
<h4>Baud rate generator mode</h4>
<p>The second thing to work out is whether we need high or low speed mode and what divisor to use.  Fortunately these are fairly simple as they are explained in the datasheet.</p>
<p>If using a <strong>slow</strong> baud rate with a <strong>fast</strong> oscillator, the datasheet recommends using the high baud rate generator.  The datasheet also suggests that it might help to reduce baud rate error.  Enabling this means using a <tt>mode</tt> of 1.  </p>
<p>For this example I used the 8Mhz internal oscillator (fairly low speed) and did not use the high speed generator, so I set <tt>mode</tt> to 0.</p>
<h4>Baud rate generator divisor</h4>
<p>Finding the divisor number is as easy as reading the datasheet to find the &#8220;SPBRG value&#8221;.  There are tables with the combinations of oscillator speed and baud rate showing the correct value.  Be careful to use the correct table for whether you plan to work with the high or low speed generator!</p>
<p>For 1200 baud at 8Mhz using the low speed generator, the value is 103.</p>
<h3>Using the code</h3>
<p>Below is example code which shows how to use the information described above.  It was adapted from the file <tt>serial_test.c</tt> which comes with BoostC.</p>
<p>For some reason the BoostC examples use the hexadecimal locations of the correct registers.  It is possible to use their names instead, e.g. <tt>TRISB</tt>/<tt>LATB</tt>/<tt>PORTB</tt> as I have below.</p>
<p>In the code below it is necessary to change 4 things:</p>
<ul>
<li>the ports and pin numbers for <tt>TX</tt> and <tt>RX</tt> (e.g. if <tt>TX</tt> is <tt>RA6</tt>, use 6)</li>
<li>the <tt>bit_time</tt> value calculated above</li>
<li>the call to <tt>uart_init</tt>, which will need the high/low speed flag and the divisor value</li>
<li>the clock frequency, if 8Mhz is not used</li>
</ul>
<h3>Code example</h3>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/********<br />
* &nbsp; Date: 11th April 2010<br />
* Author: David Cannings<br />
*<br />
* Example BoostC code for hardware USART on a PIC18F1320<br />
********/</span><br />
<span style="color: #339933;">#pragma CLOCK_FREQ 8000000</span><br />
<br />
<span style="color: #339933;">#include &lt;system.h&gt;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Standard 18F1320 configuration, included to pacify PICkit2</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG1H, _IESO_ON_1H &amp; _INTIO2_OSC_1H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG2L, _PWRT_ON_2L &amp; _BOR_OFF_2L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG2H, _WDT_OFF_2H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG3H, _MCLRE_ON_3H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG4L, _DEBUG_OFF_4L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG5L, _CP0_OFF_5L &amp; _CP1_OFF_5L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG5H, _CPB_OFF_5H &amp; _CPD_OFF_5H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG6L, _WRT0_OFF_6L &amp; _WRT1_OFF_6L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG6H, _WRTC_OFF_6H &amp; _WRTB_OFF_6H &amp; _WRTD_OFF_6H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG7L, _EBTR0_OFF_7L &amp; _EBTR1_OFF_7L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG7H, _EBTRB_OFF_7H</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Setup the hardware USART</span><br />
<span style="color: #666666; font-style: italic;">// TODO: Set the next 6 values to the right ports and pin numbers</span><br />
<span style="color: #339933;">#define TX_PORT &nbsp; &nbsp; PORTB</span><br />
<span style="color: #339933;">#define TX_TRIS &nbsp; &nbsp; TRISB</span><br />
<span style="color: #339933;">#define TX_BIT&nbsp; &nbsp; &nbsp; 1</span><br />
<span style="color: #339933;">#define RX_PORT &nbsp; &nbsp; PORTB</span><br />
<span style="color: #339933;">#define RX_TRIS &nbsp; &nbsp; TRISB</span><br />
<span style="color: #339933;">#define RX_BIT&nbsp; &nbsp; &nbsp; 4</span><br />
<br />
<span style="color: #666666; font-style: italic;">// The following values are for 18F parts, for 16F see rs232_driver.h</span><br />
<span style="color: #339933;">#define e_SPBRG &nbsp; &nbsp; 0x0faf</span><br />
<span style="color: #339933;">#define e_RCREG &nbsp; &nbsp; 0x0fae</span><br />
<span style="color: #339933;">#define e_TXREG &nbsp; &nbsp; 0x0fad</span><br />
<span style="color: #339933;">#define e_TXSTA &nbsp; &nbsp; 0x0fac</span><br />
<span style="color: #339933;">#define e_RCSTA &nbsp; &nbsp; 0x0fab</span><br />
<span style="color: #339933;">#define e_TXIF_PIR&nbsp; 0x0f9e</span><br />
<span style="color: #339933;">#define e_RCIF_PIR&nbsp; 0x0f9e</span><br />
<span style="color: #339933;">#define e_TXIF_BIT&nbsp; 4</span><br />
<span style="color: #339933;">#define e_RCIF_BIT&nbsp; 5</span><br />
<span style="color: #339933;">#define MODE&nbsp; &nbsp; &nbsp; &nbsp; (USART_reset_wdt | USART_HW)</span><br />
<br />
<span style="color: #666666; font-style: italic;">// bit_time = FOSC / 4 / baud_rate, so 1200 baud at 8Mhz</span><br />
<span style="color: #666666; font-style: italic;">// TODO: Set bit_time here</span><br />
<span style="color: #339933;">#define bit_time 1666</span><br />
<br />
<span style="color: #339933;">#include &lt;rs232_driver.h&gt;</span><br />
<br />
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; osccon <span style="color: #339933;">=</span> <span style="color: #208080;">0x72</span><span style="color: #339933;">;</span>&nbsp; <span style="color: #666666; font-style: italic;">// 8Mhz internal oscillator</span><br />
<br />
&nbsp; &nbsp; adcon0 <span style="color: #339933;">=</span> <span style="color: #208080;">0x00</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// Disable internal ADC</span><br />
&nbsp; &nbsp; adcon1 <span style="color: #339933;">=</span> <span style="color: #208080;">0x7F</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// Set all PORTB to digital I/O</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Setup the USART, arguments are baud rate generator mode</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// and divisor</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// TODO: Set mode and divisor here</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// I chose 0 for low speed mode and 103 for 1200 baud at 8Mhz</span><br />
&nbsp; &nbsp; uart_init<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">103</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Send some text from the PIC to PC</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/puts.html"><span style="color: #000066;">puts</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// If a character is received from the PC, send it back</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>kbhit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/puts.html"><span style="color: #000066;">puts</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;You pressed: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/putc.html"><span style="color: #000066;">putc</span></a><span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/getc.html"><span style="color: #000066;">getc</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/puts.html"><span style="color: #000066;">puts</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h3>Setting up a PC client</h3>
<p>As I mentioned above the settings for serial communication are fixed by the library.  You will need to set 1200 bits per second, 8 data bits, no parity, 1 stop bit and Xon/Xoff flow control.  This is often shortened to &#8220;1200 8-N-1&#8243;.</p>
<p>If you use Hyperterminal, all settings are on the properties page for the relevant serial port.</p>
<h3>Conclusion</h3>
<p>And finally, some proof that it actually works!  If you find this post useful, or you need further help, please leave a comment below.<br />

<a href='http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/pic-hardware-usart-test/' title='PIC hardware USART test'><img width="150" height="150" src="http://edeca.net/wp/wp-content/uploads/2010/04/PIC-hardware-USART-test-150x150.jpg" class="attachment-thumbnail" alt="PIC hardware USART test" title="PIC hardware USART test" /></a>
<a href='http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/rs232-breakout-board/' title='RS232 breakout board'><img width="150" height="150" src="http://edeca.net/wp/wp-content/uploads/2010/04/RS232-breakout-board-150x150.jpg" class="attachment-thumbnail" alt="RS232 breakout board" title="RS232 breakout board" /></a>
<a href='http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/pic-rs232-screenshot/' title='PIC RS232 screenshot'><img width="150" height="150" src="http://edeca.net/wp/wp-content/uploads/2010/04/PIC-RS232-screenshot-150x150.png" class="attachment-thumbnail" alt="PIC RS232 screenshot" title="PIC RS232 screenshot" /></a>
</p>
<h3>Update</h3>
<p>Mike (K8LH) has posted a great little utility <a href="http://www.microchip.com/forums/tm.aspx?m=76411&#038;mpage=1&#038;key=&#">on the Microchip forums</a> that can help work out the correct values, if you don&#8217;t fancy digging through datasheets.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eagle components library added</title>
		<link>http://edeca.net/wp/2010/03/eagle-components-library-added/</link>
		<comments>http://edeca.net/wp/2010/03/eagle-components-library-added/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 19:51:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=407</guid>
		<description><![CDATA[A very short note to say that I have (finally) published my Eagle components library on this site. Right now it doesn&#8217;t contain many parts, but I will add to it as I make more boards.]]></description>
			<content:encoded><![CDATA[<p>A very short note to say that I have (finally) published my <a href="http://edeca.net/wp/electronics/">Eagle components library</a> on this site.  Right now it doesn&#8217;t contain many parts, but I will add to it as I make more boards.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/03/eagle-components-library-added/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DIY pcb making &#8211; my first board</title>
		<link>http://edeca.net/wp/2009/07/diy-pcb-making-my-first-board/</link>
		<comments>http://edeca.net/wp/2009/07/diy-pcb-making-my-first-board/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 18:58:37 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/newsite/?p=59</guid>
		<description><![CDATA[After getting back into electronics recently, I decided to have a go at making a PCB.  A friend pointed me to Pulsar Pro FX, a special toner release paper. I learned a few things along the way: use thin board, this makes a huge difference.  I found 0.0032&#8243; board at Crownhill in the UK, which [...]]]></description>
			<content:encoded><![CDATA[<p>After getting back into electronics recently, I decided to have a go at making a PCB.  A friend pointed me to <a href="http://www.pulsarprofx.com/PCBfx/main_site/pages/index.html">Pulsar Pro FX</a>, a special toner release paper.</p>
<p>I learned a few things along the way<span id="more-59"></span>:</p>
<ul>
<li>use thin board, this makes a huge difference.  I found 0.0032&#8243; board at <a href="http://www.crownhill.co.uk/">Crownhill</a> in the UK, which seems perfect</li>
<li>let the laminator warm up enough, wait at least 15 minutes after the light comes on</li>
<li>always leave enough of an edge on the paper and board, excess can always be trimmed off later</li>
</ul>
<p>Failing to do these wastes time, paper and energy and results in lots of cleaning up to do.</p>
<p>Below is a sample of what the finished PCB looks like.  The slight roughness round the edges is due to cutting it with scissors and the black tint is because I did not have acetone to clean the toner off with.</p>
<div id="attachment_67" class="wp-caption aligncenter" style="width: 160px"><a href="http://edeca.net/wp/wp-content/uploads/2009/07/first_pcb.jpg"><img class="size-thumbnail wp-image-67  " title="First PCB made with Pulsar Pro FX" src="http://edeca.net/wp/wp-content/uploads/2009/07/first_pcb-150x150.jpg" alt="First PCB made with Pulsar Pro FX" width="150" height="150" /></a><p class="wp-caption-text">First PCB made with Pulsar Pro FX</p></div>
<p>There is an <a href="http://www.ultrakeet.com/index.php?id=article&amp;name=makepcbs">excellent guide</a> to using the paper which includes step-by-step pictures and the finished result.  SMD and double sided boards are perfectly possible, but I haven&#8217;t tried yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2009/07/diy-pcb-making-my-first-board/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

