<?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>B166ER - Made in Cyberspace &#187; NEC</title>
	<atom:link href="http://www.b166er.com/category/nec/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.b166er.com</link>
	<description>Technology, Science and Money</description>
	<lastBuildDate>Thu, 17 Jun 2010 12:17:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Writing for NEC without CCS&#8217;s shift_left</title>
		<link>http://www.b166er.com/2007/03/writing-for-nec-without-ccss-shift_left/</link>
		<comments>http://www.b166er.com/2007/03/writing-for-nec-without-ccss-shift_left/#comments</comments>
		<pubDate>Thu, 15 Mar 2007 12:57:45 +0000</pubDate>
		<dc:creator>Shohat</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[NEC]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.b166er.com/2007/03/writing-for-nec-without-ccss-shift_left/</guid>
		<description><![CDATA[CCS is a very nice compiler for PIC family of micro-controllers &#8211; the compiler includes a fair amount of built-in functions, many of which deal with bit manipulation &#8211; crucial functions when it comes to communications. Too bad I have to write these manually when porting communication to the NEC 78f9418 . Having a 7 [...]]]></description>
			<content:encoded><![CDATA[<p>CCS is a very nice compiler for PIC family of micro-controllers &#8211; the compiler includes a fair amount of built-in functions, many of which deal with bit manipulation &#8211; crucial functions when it comes to communications. Too bad I have to write these manually when porting communication to the NEC 78f9418 .</p>
<p>Having a 7 byte bitfield and transmitting it via low-speed PWM is not complex, and this is how the original code looked like, for PIC :</p>
<p>for (i = 0; i < 56; i++)  {<br />
shift_bit=shift_left (&#038;<strong>irm</strong>, sizeof(<strong>ir_packet</strong>), <strong>1</strong>);<br />
send_bit(shift_bit);<br />
}</p>
<p>Simple &#8211; 7 bytes are 56 bits, shift_left then accepts the address  of<strong> irm</strong>, which is a structure of type<strong> ir_packet</strong>, shifted<strong> 1 </strong>bit to the left. The bit is then sent on it&#8217;s way.<br />
Writing this code without the shift_left function proved to be somewhat fun though</p>
<p>packetBytePointer=&#038;(BYTE *)&#038;irm+6;<br />
for(o=0;o<7;o++)<br />
{<br />
transmittedByte=*packetBytePointer;<br />
for(z=0;z<8;z++)<br />
{<br />
send_bit(transmittedByte&#038;0x80);<br />
transmittedByte<<=1;<br />
}<br />
packetBytePointer--;</p>
<p>}</p>
<p>The above piece of code first puts an address to the last byte of the structure into a pointer, then assigns the value that is at that address to a temporary parameter of type BYTE (it's just an <strong>unsigned char</strong>) , and then simply iterates through it by shifting left and applying the 10000000 mask to it.<br />
When the iteration is done, the address of the pointer is decreased to the begin the procedure on the next (previous memory-wise) byte.<br />
This implementation was actually better in my case than shift_left of CCS , because it does not alter the original structure, so if you are storing your operational parameters in a structure that fits the transmission packet (common for simple devices such as &#8220;dumb&#8221; thermostats and motors), you don&#8217;t need to make another copy of the structure.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark to:</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;submitHeadline=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;title=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;title=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;title=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left" rel="nofollow" title="Add to&nbsp;DotNetKicks"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/dotnetkicks.png" title="Add to&nbsp;DotNetKicks" alt="Add to&nbsp;DotNetKicks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;title=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left" rel="nofollow" title="Add to&nbsp;LinkedIn"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/linkedin.png" title="Add to&nbsp;LinkedIn" alt="Add to&nbsp;LinkedIn" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;title=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F&amp;title=Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.sphere.com/sphereit/http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F" rel="nofollow" title="Add to&nbsp;SphereIt"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/sphereit.png" title="Add to&nbsp;SphereIt" alt="Add to&nbsp;SphereIt" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Writing+for+NEC+without+CCS%26%238217%3Bs+shift_left+@+http%3A%2F%2Fwww.b166er.com%2F2007%2F03%2Fwriting-for-nec-without-ccss-shift_left%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.b166er.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.b166er.com/2007/03/writing-for-nec-without-ccss-shift_left/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
