<?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>Watty Stuff</title>
	<atom:link href="http://www.wattystuff.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wattystuff.net</link>
	<description>Musings on Technology, Broadband and Consumer Issues</description>
	<lastBuildDate>Mon, 17 May 2010 07:24:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Get out of jail Free</title>
		<link>http://www.wattystuff.net/2010/05/get-out-of-jail-free/</link>
		<comments>http://www.wattystuff.net/2010/05/get-out-of-jail-free/#comments</comments>
		<pubDate>Sun, 16 May 2010 20:16:08 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[Broadband]]></category>
		<category><![CDATA[Consumer Issues]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=381</guid>
		<description><![CDATA[See
http://www.three.ie/terms/customer_notification.htm
&#160;
and
Boards Midband
	
&#160;
Ireland Offline
	
]]></description>
			<content:encoded><![CDATA[<p>See</p>
<p><a href="http://www.three.ie/terms/customer_notification.htm" target="_blank">http://www.three.ie/terms/customer_notification.htm</a></p>
<p>&nbsp;</p>
<p>and</p>
<p><a href="http://www.boards.ie/vbulletin/showthread.php?t=2055900085">Boards Midband<br />
	</a></p>
<p>&nbsp;</p>
<p><a href="http://irelandoffline.org/2010/05/the-national-broadband-scheme-again/">Ireland Offline<br />
	</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2010/05/get-out-of-jail-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multitasking and other fun on the PIC.</title>
		<link>http://www.wattystuff.net/2010/04/multitasking-and-other-fun-on-the-pic/</link>
		<comments>http://www.wattystuff.net/2010/04/multitasking-and-other-fun-on-the-pic/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 14:41:54 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=367</guid>
		<description><![CDATA[

	
	

Multitasking and other fun on the PIC.
By Michael Watterson &#169; 2010. All rights reserved. May be copied or printed for personal use only. 
Embedded applications usually have some form of Real Time Operating system or Multitasking. We examine why the Microchip PIC microcomputer is ill-suited to this approach and an alternate methodology for Real Time [...]]]></description>
			<content:encoded><![CDATA[<p>
<style type="text/css">
	<!--{cke_protected}%3C!%2D%2D%7Bcke_protected%7D%253C!%252D%252D%257Bcke_protected%257D%25253C!%25252D%25252D%25257Bcke_protected%25257D%2525253C!%2525252D%2525252D%2525257Bcke_protected%2525257D%252525253C!%252525252D%252525252D%252525257Bcke_protected%252525257D%25252525253C!%25252525252D%25252525252D%25252525257Bcke_protected%25252525257D%2525252525253C!%2525252525252D%2525252525252D%2525252525257Bcke_protected%2525252525257D%252525252525253C!%252525252525252D%252525252525252D%252525252525257Bcke_protected%252525252525257D%25252525252525253C!%25252525252525252D%25252525252525252D%25252525252525257Bcke_protected%25252525252525257D%2525252525252525253C!%2525252525252525252D%2525252525252525252D%2525252525252525257Bcke_protected%2525252525252525257D%252525252525252525253C!%252525252525252525252D%252525252525252525252D%252525252525252525250A%2525252525252525252509%2525252525252525252509%2525252525252525252540page%2525252525252525252520%252525252525252525257B%2525252525252525252520margin%252525252525252525253A%25252525252525252525202cm%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H1%2525252525252525252520%252525252525252525257B%2525252525252525252520margin-bottom%252525252525252525253A%25252525252525252525200.11cm%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H1.western%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252522%252525252525252525252C%2525252525252525252520sans-serif%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252016pt%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H1.cjk%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252520Unicode%2525252525252525252520MS%2525252525252525252522%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252016pt%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H1.ctl%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252522%252525252525252525252C%2525252525252525252520sans-serif%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252016pt%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H2%2525252525252525252520%252525252525252525257B%2525252525252525252520margin-bottom%252525252525252525253A%25252525252525252525200.11cm%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H2.western%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252522%252525252525252525252C%2525252525252525252520sans-serif%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252014pt%252525252525252525253B%2525252525252525252520font-style%252525252525252525253A%2525252525252525252520italic%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H2.cjk%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252520Unicode%2525252525252525252520MS%2525252525252525252522%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252014pt%252525252525252525253B%2525252525252525252520font-style%252525252525252525253A%2525252525252525252520italic%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H2.ctl%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252522%252525252525252525252C%2525252525252525252520sans-serif%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252014pt%252525252525252525253B%2525252525252525252520font-style%252525252525252525253A%2525252525252525252520italic%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H3%2525252525252525252520%252525252525252525257B%2525252525252525252520margin-bottom%252525252525252525253A%25252525252525252525200.11cm%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H3.western%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252522%252525252525252525252C%2525252525252525252520sans-serif%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252013pt%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H3.cjk%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252520Unicode%2525252525252525252520MS%2525252525252525252522%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252013pt%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509H3.ctl%2525252525252525252520%252525252525252525257B%2525252525252525252520font-family%252525252525252525253A%2525252525252525252520%2525252525252525252522Arial%2525252525252525252522%252525252525252525252C%2525252525252525252520sans-serif%252525252525252525253B%2525252525252525252520font-size%252525252525252525253A%252525252525252525252013pt%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%2525252525252525252509P%2525252525252525252520%252525252525252525257B%2525252525252525252520margin-bottom%252525252525252525253A%25252525252525252525200.21cm%2525252525252525252520%252525252525252525257D%252525252525252525250A%2525252525252525252509%252525252525252525252D%252525252525252525252D%252525252525252525253E%2525252525252525252D%2525252525252525252D%2525252525252525253E%25252525252525252D%25252525252525252D%25252525252525253E%252525252525252D%252525252525252D%252525252525253E%2525252525252D%2525252525252D%2525252525253E%25252525252D%25252525252D%25252525253E%252525252D%252525252D%252525253E%2525252D%2525252D%2525253E%25252D%25252D%25253E%252D%252D%253E%2D%2D%3E-->
	</style>
</p>
<h3>Multitasking and other fun on the PIC.</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font size="2">By Michael Watterson &copy; 2010. All rights reserved. May be copied or printed for personal use only. </font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Embedded applications usually have some form of Real Time Operating system or Multitasking. We examine why the Microchip PIC microcomputer is ill-suited to this approach and an alternate methodology for Real Time Systems when programming the PIC with JAL. In passing various techniques of embedded programming using JAL will be illustrated and some suggestions regarding selection of PIC or if an alternate CPU should be used.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3>Which PIC and Why is Multitasking difficult?</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">There are a confusing variety of PIC Micro. 10F, 12F, 16F, 17F, 18F, dspPIC, PIC32. Initially we consider only the 8bit PIC family (see Choosing a PIC in appendix) as it has JAL (Just Another Language) and an architecture difficult for traditional Multi-tasking solutions.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">The architecture is basically Harvard type, with Program in Flash and really all the RAM is the same address as the Registers. Microchip actually calls the RAM the &ldquo;register file&rdquo; and the operand mnemonic is &ldquo;<i>f</i>&rdquo;. Less than 18F version (10F, 12F, 16F) only small values for <i>f</i> with bank switching flags even on 256 RAM parts. The 18F series can have 8 bit or 12 bit address sizes for <i>f</i>. This means even the large 18F (80pins) can only really use external RAM for table operations, not general register instructions as it is in the same bus/ address space as the Program Instructions, not the register file. Also these PIC have almost all 4096 bytes of &ldquo;register file&rdquo; address space in use as the specific function registers are in the same address space as the 3905 bytes RAM.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">The most serious issue is Stack. Stack is usually a block of RAM used to save and restore existing address, CPU state, parameters for Procedure, Function and Interrupt calls. Since the PIC doesn&rsquo;t really have RAM in the conventional sense (only Register File), the Stack is implemented with dedicated RAM and pointer. The lowest spec PIC have only 1 or 2 levels for Return from Interrupt. The 16F series has 3 levels to 8 depending on part. The 18F has the most at 32 levels. Also only the 18F has Push and Pop instructions to manipulate the stack. Even the 18F stack is not enough for traditional Task Switching as you can only have one stack.&nbsp; There are of course awkward &quot;work-arounds&quot; which are slow and use a lot of scarce RAM.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">If this seems strange, it&rsquo;s because in 1977 the General Instruments PIC 1650 was a Programmable Interface Computer for their 16 bit part which had poor I/O features. This part &ldquo;lives on&rdquo; as the PIC16F54, which is an almost identical Flash version. The 17F was the first attempt to really enhance the architecture. The 18F is the successful 2<sup>nd</sup> attempt at that!</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3>Review of Basic Multitasking concepts.</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Even in the earliest days of microprocessors in mid 1970s it was realised that eventually a plateau of performance would be reached for a single CPU. Also there was 30 years experience of High Level language programming. UNIX was new and shiny and Batch Time Sharing Mainframe OSes looking a bit tired. But Fortran, C, Pascal, BASIC (originally a cut down ForTran) and Cobol (the main stream languages by late 1970s) had no &ldquo;built in&rdquo; concepts of multi-threading, multitasking, concurrency and such even though Multi-User operating systems with live terminals rather than batch card/Tape jobs appearing.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Analysing systems using Data Flow Diagrams (DFD) and also Digital Signal Processing (DSP) naturally lead to solutions that are more obvious to implement as Parallel Tasks or Processes. Industrial control and other embedded applications naturally are thought of as &ldquo;real time systems&rdquo; with known response times, by parallel tasks. In contrast UNIX was not (and even Linux today still is not) a &ldquo;Real Time System&rdquo;. This is nothing to do with how fast your CPU is. Even 2ms tasks requiring only us to execute can&rsquo;t be reliably executed in a <b>timely</b> fashion on OS X, Linux, or NT (aka Win2000, XP, Vista, Win7) no matter how fast the CPU is or how little else the user is doing, without writing a hardware level device driver. Writing a Device driver is not trivial, and on some OS, may require &ldquo;signing&rdquo;, expensive tools, SDK, Non-Disclosure Agreements and much study.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">In this discussion we don&rsquo;t consider the different levels of concurrency on Intel CPU, Java or Windows. We will use Task, Process and Thread as synonymous descriptions of parallel execution, with inter-task communication via signal or other shared memory. Generally we will use the more Generic &ldquo;Task&rdquo;. A Signal is assumed to be &ldquo;atomic&rdquo;, i.e. no matter when an Interrupt occurs the Signal is either set or not. Larger area of shared memory is not Atomic and requires a Signal setup as a Mutex (Mutual Exclusion). A bit or Boolean variable may not be &ldquo;Atomic&rdquo;. What kind of variable is suitable to use as a signal is Compiler and Target dependant. Signals are required to allow inter-task communication and synchronisation safely.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h4>How we got where we are?</h4>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Early solutions were Co-operative Multitasking using Co-Routines as implemented by Modula-2 (1978, PIM2 in 1983, ISO version 1996) and also Occam (released 1983) based on David May&rsquo;s work on &ldquo;Experimental Language for Distributed Computing&rdquo; aka EPL and Tony Hoare&#39;s (Communicating Sequential Processes) aka CSP started in the late 1970s.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Both have a similar concept of process synchronisation, the Signal. Occam goes much further being a fully concurrent language.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">However it&rsquo;s implemented, or the syntax of language or library lets you program it, the underlying assumption is usually that each task (thread, process) has its own separate memory area, especially the Stack (used for calls and parameters) and Heap (used for temporary variables). With a conventional CPU (i.e. not a PIC) we can have a scheduler that has a table of Stack pointers. Switching task is as simple as saving current Program Counter, Heap Pointer, CPU state on the Stack, save Stack pointer in the table for that task, and restore a previously saved Stack pointer, then restore CPU state, heap pointer and Program counter from that stack.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Each Task (aka process, thread, co-routine) thus has its own non-overlapping block of memory, except perhaps for Signal (Mutex) protected communications / Message or other shared memory.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Each Task runs until it sends or awaits a signal. If no task awaits the signal, the sending task is suspended till one is awaiting it. If a task Awaits a signal, it&rsquo;s suspended till the signal is received. This is task synchronisation by semaphore</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">A Mutex is simply created by using a signal. A task would initialise the resource and &ldquo;send&rdquo; the signal, that task can then waits for a signal when the first user consumes the signal. Each task that requires the resource Awaits the signal before use and Sends the signal after completion. The Resource task eats that and sends a new signal so that the task using the resource does not wait till someone else needs the task.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Depending on Signal/Semaphore implementation and the language or library, a mutex may be differently implemented.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3 class="western" style="page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Penalties on a regular CPU</h3>
<ol>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Compared with a purely sequential program, a parallelised program may use much more RAM.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">On a CPU without Virtual Memory and a MMU, the programmer may have to decide how much memory to allocate to a task at creation. It may be difficult without MMU/Virtual Memory to change the allocation at run time.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Without VM/MMU, ensuring that array bound violation, Stack or Heap overflow don&rsquo;t destroy more than one process is nearly impossible.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Deadlock is possible in any parallelised system. This requires different programming skills to avoid.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Any Shared resources must have Mutual Exclusion (Mutex) so only one process at a time has access. Like a toilet cubical.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Any shared code must be &ldquo;re-entrant&rdquo;. If it uses a global value to hold state (static variable), this needs to somehow be unique to each process.</p>
</li>
</ol>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3 class="western" style="page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Advantages</h3>
<ol>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Digital Signal Processing (DSP) much simpler to implement.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Data Flow Diagrams (DFDs) especially based on realtime sampling of I/O is much easier to implement.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">A delay &ldquo;loop&rdquo; (or While Busy do Nothing) does not &ldquo;waste&rdquo; CPU or block other tasks. It takes a fixed overhead no matter how long the delay.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Real-time response / Embedded control is much easier to write.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Even interrupts could become unnecessary, implemented by Signals instead.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">If you have unknown number of cores or distributed CPUs and this is more than one, then a well designed parallelised Program with a suitable Real Time Operating system can map different Tasks</p>
</li>
</ol>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3 class="western" style="page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Problems with Multitasking on PIC.</h3>
<ol>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">There is simply not the RAM for the conventional model.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">No RAM based Stack. It&rsquo;s a Hardware stack, you can only have one of it. You would have to empty and fill the entire stack on a task switch. On less than 18F (10, 12, 16) you can&rsquo;t Push and Pop items on Stack at all. It&rsquo;s only for the Interrupt return.</p>
</li>
<li>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Even on 18F, you could only task easily on main level of a &ldquo;task&rdquo; not within a procedure/Function call.</p>
</li>
</ol>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Looks bad? Take a break from Multitasking for a moment and consider JAL.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3>JAL</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Why &ldquo;Just Another Language&rdquo; (JAL) rather than C, Basic, Forth or even Pascal or Modula-2?</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">The design of these languages assumes ample RAM, an accessible Stack and such that &ldquo;regular&rdquo; CPUs have. C, Basic and Forth do exist for the 16F and 18F. Forth obviously uses a fabricated software stack rather than the real Stack pointer. Parameter passing and Function returns are normally on the Stack. But on the PIC they have to be RAM based, i.e. &ldquo;general purpose register <i>f</i>ile&rdquo;. JAL and the JAL compiler in contrast was especially designed for the quirky architecture of the 16F. JAL also has some features not part of standard C, Basic or Forth for embedded programming:</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">1) The ChipDef / Chip Include. This allows JAL compiler and JAL programmer to use the hundreds of different PIC, some 10F, 12F, most 16F and most 18F. This is currently about 345 cpu models. There is now an automated process to create these from new Microchip datasheets.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">2) <font face="Courier New, monospace">ALIAS</font> &lt;some Identifier&gt; <font face="Courier New, monospace">IS</font> &lt;some existing variable&gt; This allows pins, ports and registers to be given meaningful application dependent names</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">3) <font face="Courier New, monospace">AT</font>, a variable declaration can be &ldquo;at&rdquo; a Register file &ldquo;location&rdquo;, or another variable. AT connects a variable name to particular pin, port or register address. Or &ldquo;AT&rdquo; can act like a &ldquo;union&rdquo;.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var dword fred </font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var byte bill[4] </font><span style="font-family: courier new,courier,monospace;">at fred </span></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">This means <font face="Courier New, monospace">bill[0]</font> is 1<sup>st</sup> byte of <font face="Courier New, monospace">fred</font> and <font face="Courier New, monospace">bill[3]</font> is last byte of <font face="Courier New, monospace">fred</font>, <font face="Courier New, monospace">dword</font> is always 32 bits.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">if you need a 64 bit variable you can</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var byte[8] bill</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">There oddly is NO main program, in sense of main() in C. The logic is that when you declare a variable that is a port you may want to set it up with a value or a direction.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var byte bill[4] = &ldquo;Hello&rdquo;</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">alias GLCD_LED is pin_E1</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">alias GLCD_LED_direction is pin_E1_direction</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">GLCD_LED = on </font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Typically, textually the last part of your file of JAL will be</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">forever loop</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">&#8211; do stuff</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">&#8211; do more stuff</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">end loop </font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">All embedded programs generally have this in the last part of the main program or else the CPU would either halt, or do nops (no operation) instructions till program counter wrapped around to reboot.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">if you had a Real Time Operating system or Scheduler, it might be started here, or the loop might just have &ldquo;suspend&rdquo; in it.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h3>Basics of Real Time</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">An embedded system or Real Time system is not about speed, per se, but about timely response. It is best to consider it in terms of data flow and sampling. The inputs read, outputs must be updated at a certain rate and processing between have a maximum latency.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h4>1. Timing and Sampling.</h4>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Not all tasks need the same time constraints. Not all inputs or outputs require the same response time. First identify the highest speed input. If it must be polled rather than generating an interrupt, the sample clock must be at least twice as fast (Nyquist). This is the minimum speed then of the master Real Time Clock Interrupt. There may be a limited number of Hardware counters / Interrupts. But really we only need one, and that is more efficient than several in use of Stack, as otherwise they may need to overlap.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Identify all the slower events, sampling and timing required. See if there is a simple common denominator as a faster, but still reasonable clock interrupt. It may be that some intervals required are not an exact integer multiple of this Master Interrupt. In this case the ISR (Interrupt Service Routine) will use two software counters to achieve fractional multiplication. All the higher speed events should be an exact integer multiple. In some cases an inexact multiple is fine.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><b>Example </b></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">We need to sample 1200Hz external clock on a pin and read a data pin, but 2400Hz is 416.666..7 micro seconds. Our clock is 64us. In this case simply over-sample faster at 256us, thus 4 counts in software of interrupt. This is 3906.25 Hz which is about 3.25 times, exceeding the minimum x2. Counting 5 ticks would be 320us which would also work and also 6 at 384us. But x7 at 448us is too slow, the 1200Hz is not maybe exactly 1200Hz and not synchronized to the CPU clock. Also the CPU clock may not be exactly as expected. So over-sampling at higher speed reduces jitter and increases margin if the remote system is in error. USART (PC serial Ports) typically over-sample at x4 to x 16.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">For a non-integer multiplication we need to periodically change the software counter that counts the &ldquo;ticks&rdquo; between two values such that the average count is correct. This does introduce some jitter, equivalent to the (difference in counts) x (tick rate).</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h4><font face="Times New Roman, serif"><font size="3">When the software counter/multiplier has counted.</font></font></h4>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Then the counter is reloaded with default value. The nature of the task decides what happens next. If you have an 18F, then you can call a procedure or function that takes longer than tick time but less than the (tick time) x (software count) period as the HW stack is 31 deep. If it is 10F, 12F, 16F, then due to lack of HW stack (1 to 3 only), the task is ideally inline and must be completed before next tick. If the task repetition time is longer than time to execute the main &ldquo;forever loop&rdquo; then you increment a semaphore. A section in the main loop skips if the semaphore is zero, otherwise executes extra code and decrements the semaphore (Must be a single byte on 8 bit PIC).</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h4>2. Functions that wait internally</h4>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">This also includes Procedures that must wait for external event or have &ldquo;<font face="Courier New, monospace">out</font>&rdquo; parameters.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">We are essentially implementing Data Flow architecture. So everything is in the main forever loop or repeatedly called by an Interrupt. The solution is for the routine (function, procedure) to either use a shared (&ldquo;private&rdquo;global&rdquo;) variable if several use the same resource (say Serial I/O) or a non-shared routine specific &ldquo;private&rdquo; global. The first action then is for the semaphore or mutex variable to be tested. If it is not in use, we set it and do the first part of the task. If it is in use we check is it &ldquo;our&rdquo; value and if the resource required (time, serial port, whatever) is ready. If it it&rsquo;s ready then we service it and set the semaphore/Mutex back to &ldquo;empty&rdquo;. If it is for &ldquo;us&rdquo; but the resource isn&rsquo;t ready we return.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">All data return has to be via &ldquo;<font face="Courier New, monospace">out</font>&rdquo; parameters. The Function return is always false if the function only did first part of &ldquo;task&rdquo; or the &ldquo;resource&rdquo; to complete the task was busy, or some other function has the &ldquo;resource&rdquo;. The Function only returns true when the resource was accessed and the Function reset the &ldquo;semaphore/Mutex&rdquo; to &ldquo;empty&rdquo;.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Thus in our procedures called by the main &ldquo;forever loop&rdquo; the code after the Function call is repeatedly skipped till there is valid data in the &ldquo;<font face="Courier New, monospace">out</font>&rdquo; parameters.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">This method makes &ldquo;blocking&rdquo; I/O non-blocking for the main &ldquo;forever loop&rdquo; and makes &ldquo;While busy do nothing&rdquo; and &ldquo;delay (xxx)&rdquo; take almost no overhead in the main loop. We have turned the main &ldquo;forever loop&rdquo; into a basic round robin scheduler without the overhead of multiple stacks and a RTOS kernel.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">example Function:</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">function CAT_FreqBCDRd(byte out ModMode, byte out bcdfreq[4]) return bit is</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">var bit status = false</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">var byte digit</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">bcdfreq[0] =0</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">bcdfreq[1] =1</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">bcdfreq[2] =0</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">bcdfreq[3] =0</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">modMode = 16</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><code><span style="font-family: courier new,courier,monospace;">if ( _CAT_QueuedCmd == CMD_NONE ) then</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><code><span style="font-family: courier new,courier,monospace;">CAT_SendCmd(CAT_NO_PARAM, CMD_FreqRd, true)</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><code><span style="font-family: courier new,courier,monospace;">status = false</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><code><span style="font-family: courier new,courier,monospace;">--suspend</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><code><span style="font-family: courier new,courier,monospace;">elsif (_CAT_QueuedCmd == CMD_FreqRd) then</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><code><span style="font-family: courier new,courier,monospace;">if (serial_hw_data_available) then</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">digit = 0 -- get back the frequency</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">bcdfreq[digit]= serial_hw_data</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">for 3 loop</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><code><span style="font-family: courier new,courier,monospace;">digit = digit +1</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><code><span style="font-family: courier new,courier,monospace;">if RigResponds() then</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><code><span style="font-family: courier new,courier,monospace;">bcdfreq[digit]= serial_hw_data</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><code><span style="font-family: courier new,courier,monospace;">else</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><code><span style="font-family: courier new,courier,monospace;">exit loop</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><code><span style="font-family: courier new,courier,monospace;">end if</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">end loop</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">if RigResponds() then -- read the Mode</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><code><span style="font-family: courier new,courier,monospace;">modMode = serial_hw_data</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><code><span style="font-family: courier new,courier,monospace;">status = true</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">end if</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">_CAT_QueuedCmd = CMD_NONE</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><code><span style="font-family: courier new,courier,monospace;">elsif ( _CAT_retryCount &lt; 1) then</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">_CAT_QueuedCmd = CMD_NONE</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><code><span style="font-family: courier new,courier,monospace;">else</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><code><span style="font-family: courier new,courier,monospace;">_CAT_retryCount = _CAT_retryCount -1</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><code><span style="font-family: courier new,courier,monospace;">end if</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><code><span style="font-family: courier new,courier,monospace;">end if</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><code><span style="font-family: courier new,courier,monospace;">return (status)</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code><span style="font-family: courier new,courier,monospace;">end function</span></code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">In this case <font face="Courier New, monospace">( _CAT_QueuedCmd == CMD_NONE ) </font>is testing the shared Mutex /semaphore to see if the resource is free (it&rsquo;s a serial port). The Function has to send 5 bytes via serial and wait up to 350ms for the remote device to return 5 bytes. Once the remote responds, the 5 returned bytes come in a block, but we have tests in case the communication link is lost or remote is turned off in the middle of transmission.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">The <font face="Courier New, monospace">CAT_FreqBCDRd </font>thus could be called many times before it does anything. Since we know there is no point in interrogating the remote device more than 3 or 4 times a second, we have a timer that sends a &ldquo;signal&rdquo; to part of our main loop, so many times this part of main loop (shown below) is skipped:</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">part of main loop</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">&#8211; loop</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace">if CheckRadio &gt; 0 then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">case rigModeNow of</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">RIGMODE_RX: block</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">if !(rigModeNow == rigModeOld) then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">if ! clock_on then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><font face="Courier New, monospace">DrawClockFace(19,35,17, on, off)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><font face="Courier New, monospace">clock_on = true</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><font face="Courier New, monospace">DisplayWait()</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><font face="Courier New, monospace">DrawMeterFace(42, 16, S_METER_HEIGHT,S_METER_SCALE, on)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">pttStatus = off</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">if CAT_PTT(pttStatus) then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><font face="Courier New, monospace">rigModeOld = rigModeNow</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 200px;"><font face="Courier New, monospace">linkFailTime = LINK_RETRIES</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">else</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">RIG_RxPoll()</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">end block</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">CheckRadio</font> is incremented by the Timer ISR.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Then in Rig_RXPoll() we interrogate the Remote Radio :</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">Procedure DisplayFrequency() is</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var volatile byte rigFreq[4]</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var byte rigFreqText[10] = &quot;430.125,00&quot;</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var byte modmodeText[3]</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">var byte newMode</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace">if CAT_FreqBCDRd(newMode, rigfreq) then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">if BCD4toString10 (rigFreq, rigFreqText) then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">timedOut = false</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">if newMode &lt; 15 then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace">modMode = newMode</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">ScreenCharXY(0,0)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">CharStyleDouble = on</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">print_string(ScreenChar,rigFreqText)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">CharStyleDouble = off</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">ScreenCharXY(20,1)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">CharStyleBold = on</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">ScreenChar =&quot;0&quot;</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">CharStyleBold = off</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">ScreenCharXY(15,7)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">if RIG_ModeText(modMode,modmodeText) then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">ScreenChar = &quot;n&quot;</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">else</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">ScreenChar = &quot; &quot;</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">print_string(ScreenChar,modmodeText)</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">linkFailTime = LINK_RETRIES</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace">elsif (linkFailTime &lt; 1) then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">if ! timedOut then</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">DisplayWait()</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace">timedOut = true</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace">else</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace">linkfailtime = linkfailtime -1</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace">end if</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace">end procedure</font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">If after a reasonable time the <font face="Courier New, monospace">CAT_FreqBCDRd </font>doesn&rsquo;t return &ldquo;true&rdquo; we assume the communications link is broken or the Remote unit is turned off.</p>
<p style="margin-bottom: 0cm;">&nbsp;</p>
<p style="margin-bottom: 0cm;">&nbsp;</p>
<p style="margin-bottom: 0cm;"><b>To Be Continued! &#8230;</b></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<h2 class="western" style="page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Appendix</h2>
<h3 class="western" style="page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Complete &ldquo;Blink LEDs&rdquo;</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">for the 18F4550.&nbsp;&nbsp; Always four parts at least:</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">1) RTC ISR</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">2) Low level routines that &quot;multitask&quot;&nbsp; using dataflow sampling</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">3) The Tasks</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">4) The main forever loop calls the tasks.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">include 18f4550</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; even though the external crystal is 20 MHz, the configuration is such that</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; the CPU clock is derived from the 96 Mhz PLL clock (div2), therefore set</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; target frequency to 48 MHz</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target clock 48_000_000</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; fuses</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target PLLDIV P5 &#8212; divide by 5 &#8211; 20MHZ_INPUT</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CPUDIV P2 &#8212; OSC1_OSC2_SRC_1_96MHZ_PLL_SRC_2</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target USBPLL F48MHZ &#8212; CLOCK_SRC_FROM_96MHZ_PLL_2</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target OSC HS_PLL</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target FCMEN DISABLED</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target IESO DISABLED</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target PWRTE ENABLED &#8212; power up timer</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target VREGEN ENABLED &#8212; USB voltage regulator</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target VOLTAGE V20 &#8212; brown out voltage</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target BROWNOUT DISABLED &#8212; no brownout detection</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WDTPS P32K &#8212; watch dog saler setting</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WDT DISABLED &#8212; no watchdog</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CCP2MUX pin_C1 &#8212; CCP2 pin</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target PBADEN DIGITAL &#8212; digital input port&lt;0..4&gt;</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target LPT1OSC LOW_POWER &#8212; low power timer 1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target MCLR EXTERNAL &#8212; master reset on RE3</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target STVR DISABLED &#8212; reset on stack over/under flow</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target LVP DISABLED &#8212; no low-voltage programming</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target XINST ENABLED &#8212; extended instruction set</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target DEBUG DISABLED &#8212; background debugging</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CP0 DISABLED &#8212; code block 0 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CP1 DISABLED &#8212; code block 1 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CP2 DISABLED &#8212; code block 2 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CP3 DISABLED &#8212; code block 3 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CPB DISABLED &#8212; bootblock code not write protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target CPD DISABLED &#8212; eeprom code not write protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRT0 DISABLED &#8212; table writeblock 0 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRT1 DISABLED &#8212; table write block 1 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRT2 DISABLED &#8212; table write block 2 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRT3 DISABLED &#8212; table write block 3 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRTB DISABLED &#8212; bootblock not write protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRTD DISABLED &#8212; eeprom not write protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target WRTC DISABLED &#8212; config not write protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target EBTR0 DISABLED &#8212; table read block 0 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target EBTR1 DISABLED &#8212; table read block 1 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target EBTR2 DISABLED &#8212; table read block 2 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target EBTR3 DISABLED &#8212; table read block 3 not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma target EBTRB DISABLED &#8212; boot block not protected</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">enable_digital_io()</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Main Program &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">alias led1 is pin_b1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pin_b1_direction = output</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">alias led2 is pin_b2</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pin_b2_direction = output</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">alias led3 is pin_b2</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pin_b3_direction = output</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><code>; private variables for the low level procedures<br />
	</code></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">const byte NUM_DELAYS = 3</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">var byte CheckDelay[NUM_DELAYS] = {0, 0, 0} &#8212; semaphores</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">var byte timer[NUM_DELAYS] = {0, 0, 0} &#8211;internal delay timer</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; 1 to 255 x the RTC tick of 1024 usec.</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">function Delay(byte in instance, byte in ms) return bit is</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">var bit timedout = false</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">if instance &lt; Count (CheckDelay) then &#8212; only bother if it exists</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">if CheckDelay[instance] &gt; 0 then</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">if timer[instance] &lt; 1 then &#8212; 1st time ever call</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace"><font size="2">timer[instance] = ms +1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">elsif timer[instance] ==1 then &#8212; timeout</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace"><font size="2">timer[instance] = ms +1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace"><font size="2">timedout = true</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">else</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace"><font size="2">timer[instance] = timer[instance] -1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">CheckDelay[instance] = checkDelay[instance] -1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">return (timedout)</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">end function</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">; the tasks.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">procedure BlinkLed1() is</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">If Delay(0, 100) then&nbsp; &#8212; delay in 1.024ms steps<br />
	</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">led1 = ! Led1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">end procedure</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">procedure BlinkLed2() is</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">If Delay(1,120) then</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">led2 = ! Led2</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">end procedure</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">procedure BlinkLed3() is</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">If Delay(2,200) then</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">led3 = ! Led3</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">end procedure</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; The RTC always increments a Semaphore by 1 if it&#39;s time to do a task</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; The Task always decrements the Semaphore by 1 when it has completed.</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">const TICK_INIT = 48 &#8212; 1024us = 1.024ms</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">var byte ticks = TICK_INIT &#8212; timer</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">procedure RTC() is</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">pragma interrupt</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">var byte instance</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">if INTCON_TMR0IF then</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">INTCON_TMR0IF = off &#8212; clear the timer 0 interrupt flag</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">ticks = ticks -1 &#8212; 256us counter</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">if (ticks &lt; 1) then</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">ticks = TICK_INIT</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">for Count (CheckDelay) using instance loop</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 160px;"><font face="Courier New, monospace"><font size="2">CheckDelay[instance] = CheckDelay[instance] +1</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 120px;"><font face="Courier New, monospace"><font size="2">end loop</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">end if</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">end procedure &#8212; end of ISR</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">&#8211; Main Program</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">block </font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">&#8211;RTC setup</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">T0CON_T0CS =0 &#8212; TMR0 on internal clock</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">T0CON_PSA = 1 &#8212; prescaler</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">&#8211; so no prescaler for TMR0 (= default)</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">INTCON_TMR0IE = on &#8212; if your PIC freezes, move these lines</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">INTCON_GIE = on &#8212; to see if the ISR causes trouble</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">forever loop&nbsp; ;round robin tasks!&nbsp; <br />
	</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">BlinkLed1()</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">BlinkLed2()</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 80px;"><font face="Courier New, monospace"><font size="2">BlinkLed3()</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto; margin-left: 40px;"><font face="Courier New, monospace"><font size="2">end loop</font></font></p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;"><font face="Courier New, monospace"><font size="2">end block</font></font></p>
<h3 class="western" style="page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Choosing a PIC</h3>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">&nbsp;</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">10F, 12F, 16F or 18F?</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">Less than the 18F series has only 1 to 8 entries possible in Stack and only up to 350byte approximately of RAM. The 18F series has up to 31 stack levels (still a fixed Hardware stack, i.e. you can&rsquo;t change the Stack Pointer to relocate it elsewhere in RAM).</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">There are about 10 models each of 6, 8 and 14 pin PIC in the 10F, 12F and 16F series.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">The 18F series is not available in less than an 18 pin package. The lesser 10, 12 and 16 series are available in as little as 6 pins but no 8 bit HW multiply, no PUSH/POP and only 1 to 3 stack levels and less than 350 byte RAM. Most are 2K words to 4K words. The 18F are typically 8K words to 64k words. Because an instruction &ldquo;word&rdquo; is more than 8 bits but less than 16bits the PIC 10, 12, 16 series don&rsquo;t store lookup tables efficiently. Most lookup tables use 8 bit or 16 bit values. The 18F uses a 16bit word so lookup tables are more efficient.&nbsp; There are hundreds of 18F models</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">JAL currently supports over 350 PIC from 10F, 12F, 16F and 18F family, including 18FxxJxx and 18FxxKxx devices</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">We don&rsquo;t consider here the 17F as it&rsquo;s obsolete version of the 18F. Nor do we consider the higher end dspPIC or 24F series as the ARM or PIC32 (really a MIPS core) is a better choice. Some people mistakenly think the 18F is a 16 bit cpu as Microchip refers to it as 16 bit core, but they do group it as an 8bit cpu. It&rsquo;s less 16 bit than an 8bit Z80! The 16 bits is only the instruction size. All the PIC 10, 12, 16, 17 and 18 are 8bit CPU slightly similar to 8051 rather than 8080, Z80 or even 6502/6800 type family.</p>
<p style="margin-bottom: 0cm; page-break-inside: avoid; page-break-before: auto; page-break-after: auto;">
	<a href="http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1004&amp;mid=10&amp;lang=en&amp;pageId=74"><strong>For 18 pins or more only consider the 18F family</strong></a><br />
	<a href="http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1004&amp;mid=10&amp;lang=en&amp;pageId=74" target="_blank">http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1004&amp;mid=10&amp;lang=en&amp;pageId=74</a></p>
<p>
	<a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=2696&amp;param=en537796">Selection and Parametric search of all 8bit PIC</a><br />
	<a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=2696&amp;param=en537796" target="_blank">http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=2696&amp;param=en537796</a></p>
<p>	<strong><br />
	Get JAL</strong>&nbsp; <a href="http://code.google.com/p/jallib/">here</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://code.google.com/p/jallib/" target="_blank">http://code.google.com/p/jallib/</a> &nbsp; (Downloads on Right of page)<br />
	see also<br />
	<a href="http://groups.google.com/group/jallib" target="_blank">http://groups.google.com/group/jallib</a><br />
	<a href="http://tech.groups.yahoo.com/group/jallist/" target="_blank">http://tech.groups.yahoo.com/group/jallist/</a><br />
	<a href="http://www.casadeyork.com/jalv2/" target="_blank">http://www.casadeyork.com/jalv2/</a><br />
	<a href="http://groups.google.com/group/jaledit" target="_blank">http://groups.google.com/group/jaledit</a><br />
	<a href="http://groups.google.com/group/jaluino" target="_blank">http://groups.google.com/group/jaluino</a><br />
	<a href="http://justanotherlanguage.org/" target="_blank">http://justanotherlanguage.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2010/04/multitasking-and-other-fun-on-the-pic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fraud &amp; Chip and PIN</title>
		<link>http://www.wattystuff.net/2010/02/fraud-chip-and-pin/</link>
		<comments>http://www.wattystuff.net/2010/02/fraud-chip-and-pin/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 14:14:53 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[Consumer Issues]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/2010/02/fraud-chip-and-pin/</guid>
		<description><![CDATA[I&#39;ve always said that Chip &#38; PIN was always about reducing the Bank&#39;s liability to Fraud. Not actually really more secure or reducing Fraud. With a signature you can prove it&#39;s not you and get the money back, with Chip &#38; PIN you can&#39;t. Thus Bank &#34;Fraud&#34; drops. But it gets worse. http://www.theregister.co.uk/2010/02/12/chip_pin_security_unpicked/ Of course [...]]]></description>
			<content:encoded><![CDATA[<p>I&#39;ve always said that Chip &amp; PIN was always about reducing the Bank&#39;s liability to Fraud. Not actually really more secure or reducing Fraud. With a signature you can prove it&#39;s not you and get the money back, with Chip &amp; PIN you can&#39;t. Thus Bank &quot;Fraud&quot; drops. But it gets worse. <a href="http://www.theregister.co.uk/2010/02/12/chip_pin_security_unpicked/ ">http://www.theregister.co.uk/2010/02/12/chip_pin_security_unpicked/ </a>Of course RFID for credit/cash cards or Passports is even more stupid. A technology designed to replace Barcodes (which can be photocopied) and RFID is not inherently a technology designed for Secure applications. Because RFID is unique &quot;fingerprint&quot; even if you don&#39;t decode it, an RFID &quot;reader&quot; at each location that your &quot;mark&quot; might use lets you track where the RFID is. If the &quot;mark&quot; realises, you could of course be tracking someone else that had the &quot;tag&quot; dumped on them.</p>
<p>&nbsp;</p>
<p>See also here <a href="http://www.lightbluetouchpaper.org/2010/01/26/how-online-card-security-fails/">http://www.lightbluetouchpaper.org/2010/01/26/how-online-card-security-fails/ </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2010/02/fraud-chip-and-pin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PIC16F8xx and 128&#215;64 GLCD</title>
		<link>http://www.wattystuff.net/2010/01/pic16f8xx-and-128x64-glcd/</link>
		<comments>http://www.wattystuff.net/2010/01/pic16f8xx-and-128x64-glcd/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 23:08:45 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/2010/01/pic16f8xx-and-128x64-glcd/</guid>
		<description><![CDATA[I looked at Microchip &#38; Hitech picc, Mikro C, CCS and others. I went back to JAL, 1/2 a day got graphics library for KS0107 / KS0108 used in JE-AN1286404 Graphics LCD working. Animation, Circle, arbitrary lines, box etc. Also text compatible with Text LCD libraries &#38; programs.
I&#39;ll be using this in a few projects. [...]]]></description>
			<content:encoded><![CDATA[<p>I looked at Microchip &amp; Hitech picc, Mikro C, CCS and others. I went back to JAL, 1/2 a day got graphics library for KS0107 / KS0108 used in JE-AN1286404 Graphics LCD working. Animation, Circle, arbitrary lines, box etc. Also text compatible with Text LCD libraries &amp; programs.</p>
<p>I&#39;ll be using this in a few projects. Pinout is different from usual KS0107 GLCDs:</p>
<p>HQM1286404 / JE-AN 1286404 LCD Pin connections:</p>
<p>1: VDD is connected to +5V</p>
<p>2: VSS is connected to OV /GND</p>
<p>3: V0 &#8211; LCD operating voltage is connected from a 10K or 20k Ohm POT (Between OV and -5V from pin 18)</p>
<p>4 .. 11: Data Bus 0 to 7 is connected to port d</p>
<p>12: Chip Select 1</p>
<p>13: Chip Select 2</p>
<p>14: Reset&nbsp; (hold at +5V for normal operation)</p>
<p>15: R/W &#8211; Read=1 or Write =0</p>
<p>16: D/I aka RS &#8211; Data or Instruction (Registers)</p>
<p>17: EN Enable is connected to B5 18: Negative voltage out to feed 20k Ohm POT for view angle</p>
<p>19: Positive voltage for LED backlight is connected to +5V</p>
<p>20: Negative voltage for LED backlight is connected to GND. On my pre-wired panel this is red wire! (feed LED backlight via 47 Ohms in series with + or &#8211; pin.) </p>
<p>I had to reverse CS1 and CS2 in the JAL library, but the wiring above works with LCDStudio for PC parallel Port (RW = 0V and RESET aka RES = +5V, connect Power first! I used USB for +5V) More details with projects, schematics etc on <a href="http://www.techtir.ie">http://www.techtir.ie</a> soon</p>
<p>Tested on PIC16F877A 20MHz using JAL. Same SW should work on 16F887 (replacement) and others with enough pins.</p>
<p><strong>Other models of GLCD that are compatible may have different pin layout and even +5V and 0V reversed</strong> (even on similar model names of same make!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2010/01/pic16f8xx-and-128x64-glcd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ireland Bottom of Another Bandwidth-Driven Pile.</title>
		<link>http://www.wattystuff.net/2009/11/ireland-bottom/</link>
		<comments>http://www.wattystuff.net/2009/11/ireland-bottom/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 17:33:01 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[About Watty Stuff]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=352</guid>
		<description><![CDATA[A survey released today by Tariff Consultancy1 has revealed that Ireland is now the most expensive country in Europe in which to lease Data Centre capacity. After getting a broadband connection the first reaction of most people and companies is to establish a presence on the internet, usually a web site. However the cost of [...]]]></description>
			<content:encoded><![CDATA[<p>A survey released today by Tariff Consultancy<sup>1 </sup>has revealed that Ireland is now the most expensive country in Europe in which to lease Data Centre capacity. After getting a broadband connection the first reaction of most people and companies is to establish a presence on the internet, usually a web site. However the cost of renting space in a datacentre is prohibitive . </p>
<p>This shocking report is a result of a myriad of policy failings over the medium term since around 2001, not only in the lack of an overall balanced National Broadband policy but also because our only energy policy is to have the most expensive electricity in Europe, by design. Data Centres are the very heart of any functioning knowledge economy, they are where knowledge and data is stored and and from which the kowledge underpinning the economy is distributed. </p>
<p>Pricing Irish business out of these Datacentres may seem smart and green to some but this smart green policy will have disastrous consequences over the medium term out to 2015, not least to our GDP. Ireland Offline calls on Minister Ryan to address these deficiencies as a matter of extreme urgency. Only 2 data centres have opened in Ireland in the past 8 years, one in Cork and one in Dublin. No more are planned.</p>
<p>### ENDS</p>
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash; </p>
<p>1) Tariff Consultancy Website http://www.telecomspricing.com/ 2) </p>
<p>http://www.telecomspricing.com/news_detail.cfm?item=2592 &ldquo;The most expensive average Data Centre countries in our survey are Denmark, Switzerland &amp; Ireland (with rates per rack from 1,300 Euro to 1,050 Euro per month), with cage and 50 KVA pricing being significantly less (in Euro per square metre terms).&rdquo; Ireland led Europe in the quality price and availability of its Data Centres in 2001. We have built only 2 since, one in Cork and one in Dublin. Data centres are huge computer warehouses where ones data is stored, even though we are supposedly a &ldquo;leader&rdquo; in the knowledge economy stakes. </p>
<p>ABOUT IRELANDOFFLINE </p>
<p>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&ndash; </p>
<p>Campaigning For Affordable, Unmetered And Broadband Internet Access In Ireland IrelandOffline is a voluntary organisation consisting of home and business Internet users. Its brief is to campaign for the development of high-speed Internet access services and to promote innovation and competition in the Irish Internet marketplace. For more information on the organisation, please visit the IrelandOffline website at http://www.irelandoffline.org or contact us at info@irelandoffline.org. For urgent media enquiries, contact spokesperson Eamonn Wallace at 086 250 6350.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/11/ireland-bottom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Landlines</title>
		<link>http://www.wattystuff.net/2009/11/landlines/</link>
		<comments>http://www.wattystuff.net/2009/11/landlines/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 12:58:18 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[About Watty Stuff]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=346</guid>
		<description><![CDATA[
&#160;
When eircom was privatised 82% had landlines. Now in 2009 66% have landlines in Ireland and 1/3rd of those are paid for by Social Welfare.
]]></description>
			<content:encoded><![CDATA[<img alt="Landlines vs Mobile Users" class="size-full wp-image-348" height="297" src="http://www.wattystuff.net/wp-content/uploads/2009/11/no_landline.gif" title="Landlines vs Mobile Users" width="466" />
<p>&nbsp;</p>
<p>When eircom was privatised 82% had landlines. Now in <strong>2009</strong> 66% have landlines in Ireland and 1/3rd of those are paid for by Social Welfare.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/11/landlines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is Techtír about?</title>
		<link>http://www.wattystuff.net/2009/10/what-is-techtir-about/</link>
		<comments>http://www.wattystuff.net/2009/10/what-is-techtir-about/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 19:14:02 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[Amateur Radio]]></category>
		<category><![CDATA[Broadband]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=129</guid>
		<description><![CDATA[Most new sites, especially Forums are either hyper focused (iphone or Archos) or as broad as possible. In any case the  aim often is simply Traffic.
Techtír is not just about Forums or Traffic. The idea is a  serious Technology Portal, with serious depth of content.
An important aspect will thus be the Articles.  While post in [...]]]></description>
			<content:encoded><![CDATA[<p>Most new sites, especially Forums are either hyper focused (iphone or Archos) or as broad as possible. In any case the  aim often is simply Traffic.</p>
<p><a href="http://www.techtir.ie/">Techtír</a> is not just about Forums or Traffic. The idea is a  serious Technology Portal, with serious depth of content.</p>
<p>An important aspect will thus be the Articles.  While post in the Forums will help an ordinary user of a  smart phone, Router, Satellite Receiver or MP3 player, the idea is to have a meeting and Tech Info Clearing house for experts and those that want to be Experts.</p>
<p>Subscribers have much more access and control. Yet you can be recognised as providing good content by being given subscriber status.</p>
<p>There are more ideas too.<a href="http://www.techtir.ie/"> Head over</a>, signup to free Member level  and take a look around.</p>
<p><strong>Current Featured Post :</strong> <span style="white-space: nowrap;"> <a style="white-space: nowrap;" title="Go to first unread post in thread 'Which EMC rules apply for PLT?'" href="http://www.techtir.ie/forums/showthread.php?goto=newpost&amp;t=2107"><strong>Which EMC rules apply for PLT?</strong></a></span></p>
<p><span style="white-space: nowrap;">Also see</span></p>
<p><span style="white-space: nowrap;">Gadgets &amp; Phones </span><strong><a style="white-space: nowrap;" title="Go to first unread post in thread 'eBook Readers'" href="http://www.techtir.ie/forums/showthread.php?goto=newpost&amp;t=1762"><strong>eBook Readers</strong></a></strong></p>
<p>RadioAL&#8217;s Wireless History series: <a id="thread_title_1693" href="http://www.techtir.ie/forums/showthread.php?t=1693">Amateur Radio etc Quo vadis?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/10/what-is-techtir-about/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML, RSS, PHP and SimpleXMLElement</title>
		<link>http://www.wattystuff.net/2009/10/xml-rss-php-and-simplexmlelement/</link>
		<comments>http://www.wattystuff.net/2009/10/xml-rss-php-and-simplexmlelement/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 22:22:44 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[About Watty Stuff]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[simplexml]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=55</guid>
		<description><![CDATA[A lot of people have multipage PHP scripts to read &#60;content:encoded&#62; CDATA part of RSS believing that SimpleXML in PHP can&#8217;t do it.
Well it can!
content is referring to  the Namespace used.
viz at the start of the Feed is the clue:
&#60;rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"&#62;
This Guy explains it well Here is another good post
The Techtir.ie portal has the [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of people have multipage PHP scripts to read <strong>&lt;content:encoded&gt; CDATA</strong> part of RSS believing that SimpleXML in PHP can&#8217;t do it.</p>
<p>Well it can!</p>
<p>content is referring to  the Namespace used.</p>
<p>viz at the start of the Feed is the clue:</p>
<pre>&lt;rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"&gt;</pre>
<p><a href="http://blog.stuartherbert.com/php/2007/01/07/using-simplexml-to-parse-rss-feeds/" target="_blank">This Guy explains it well</a> Here is <a href="http://debuggable.com/posts/parsing-xml-using-simplexml:480f4dfe-6a58-4a17-a133-455acbdd56cb">another good post</a><br />
The <a href="http://www.techtir.ie/">Techtir.ie portal</a> has the &#8220;posts&#8221; content filled in from Forum Posts via RSS by including content:encoded and CDATA  parts in the RSS feeds, using only a fragment of PHP in the &#8220;post&#8221; via SimpleXMLElement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/10/xml-rss-php-and-simplexmlelement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Broken Download Window</title>
		<link>http://www.wattystuff.net/2009/10/broken-download-window/</link>
		<comments>http://www.wattystuff.net/2009/10/broken-download-window/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 22:07:55 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[About Watty Stuff]]></category>
		<category><![CDATA[Firefox Download Manager]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=50</guid>
		<description><![CDATA[Firefox 3.5 uses SQLite. I don&#8217;t know when it switched from downloads.rdf
Anyway type About:config in address  bar
put browser.download in the filter
This means items stay in window till you press Clear:
browser.download.manager.retention  1
This stops an automatic virus scan which is buggy:
browser.download.manager.scanWhenDone false
That fixed my Download manager Window
Disable Sites seeing your history?
In address bar About:config
layout.css.visited_links_enabled = False
]]></description>
			<content:encoded><![CDATA[<p>Firefox 3.5 uses SQLite. I don&#8217;t know when it switched from downloads.rdf</p>
<p style="text-align: left;">Anyway type About:config in address  bar</p>
<p style="text-align: left;">put <strong>browser.download</strong> in the filter</p>
<p>This means items stay in window till you press Clear:</p>
<p><strong>browser.download.manager.retention  1</strong></p>
<p style="text-align: left;">This stops an automatic virus scan which is buggy:</p>
<p style="text-align: left;"><strong>browser.download.manager.scanWhenDone false</strong></p>
<p>That fixed my Download manager Window</p>
<p><strong>Disable Sites seeing your history?</strong></p>
<p><em>In address bar </em>About:config</p>
<p>layout.css.visited_links_enabled = False</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/10/broken-download-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to remove PC Sync 2 Synchronisation</title>
		<link>http://www.wattystuff.net/2009/10/how-to-remove-pc-sync-2-synchronisation/</link>
		<comments>http://www.wattystuff.net/2009/10/how-to-remove-pc-sync-2-synchronisation/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 22:00:46 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[About Watty Stuff]]></category>
		<category><![CDATA[Firefox plugin]]></category>
		<category><![CDATA[remove PCSync2]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=48</guid>
		<description><![CDATA[This Plugin  is installed by Nokia PC Suite and isn&#8217;t compatible with Firefox 3.5
use the Registry on Windows.
Start &#124; Run &#124; regedit
Find in HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Firefox\Extensions
Delete bkmrksync@nokia.com
]]></description>
			<content:encoded><![CDATA[<p>This Plugin  is installed by Nokia PC Suite and isn&#8217;t compatible with Firefox 3.5</p>
<p>use the Registry on Windows.</p>
<pre>Start | Run | regedit</pre>
<pre>Find in HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Firefox\Extensions</pre>
<pre>Delete <strong>bkmrksync@nokia.com</strong></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/10/how-to-remove-pc-sync-2-synchronisation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Welcome to Watty Stuff</title>
		<link>http://www.wattystuff.net/2009/10/revamp-of-an-old-site/</link>
		<comments>http://www.wattystuff.net/2009/10/revamp-of-an-old-site/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 12:21:08 +0000</pubDate>
		<dc:creator>Watty</dc:creator>
				<category><![CDATA[About Watty Stuff]]></category>
		<category><![CDATA[Introduction launch]]></category>

		<guid isPermaLink="false">http://www.wattystuff.net/?p=1</guid>
		<description><![CDATA[Well here we are.  Autumn and all, golden leaves soon.

I told &#8220;Regi&#8221; once if I started a Blog, to shoot me.  However I think of this more as a new Portal Interface to my long running website / web presences dating back to 1996.  I&#8217;m gradually upgrading my content to a new look [...]]]></description>
			<content:encoded><![CDATA[<p>Well here we are.  Autumn and all, golden leaves soon.</p>
<p><img class="aligncenter size-full wp-image-7" title="Corbies' tree in Autumn" src="http://www.wattystuff.net/wp-content/uploads/2009/10/blastedtreeatm.jpg" alt="Corbies' tree in Autumn" width="423" height="572" /></p>
<p>I told &#8220;Regi&#8221; once if I started a Blog, to shoot me.  However I think of this more as a new Portal Interface to my long running website / web presences dating back to 1996.  I&#8217;m gradually upgrading my content to a new look and feel suggested by this template. </p>
<p>However so as to not worry too much about backups, most of the content will be built off line and uploaded so that I inherently have a backup of the site content as it&#8217;s published. With the Wordpress Content or &#8220;Cloud Based&#8221; such as Google Docs, you must have a different backup strategy. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.wattystuff.net/2009/10/revamp-of-an-old-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
