<?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>Electronic Products Development &#187; Embedded Programming</title>
	<atom:link href="http://www.electronic-products-development.com/category/embedded-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.electronic-products-development.com</link>
	<description>Electronic Products Development Resources</description>
	<lastBuildDate>Fri, 06 Jan 2012 10:27:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Typedef Union</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/typedef/typedef-union</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/typedef/typedef-union#comments</comments>
		<pubDate>Fri, 14 Oct 2011 12:07:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Typedef]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=59</guid>
		<description><![CDATA[typedef union _WORD_VAL { WORD val; struct { BYTE LSB; BYTE MSB; } byte; BYTE v[2]; } WORD_VAL; # = ((DWORD_VAL) address).v[1])]]></description>
			<content:encoded><![CDATA[<pre><code>
typedef union _WORD_VAL
{
    WORD val;
    struct
    {
        BYTE LSB;
        BYTE MSB;
    } byte;
    BYTE v[2];
} WORD_VAL;

<span id="more-59"></span>

# = ((DWORD_VAL) address).v[1])
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/typedef/typedef-union/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typedef For Text Based Values &amp; State Machines</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/typedef/typedef-for-text-based-values-state-machines</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/typedef/typedef-for-text-based-values-state-machines#comments</comments>
		<pubDate>Fri, 14 Oct 2011 12:05:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Typedef]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=56</guid>
		<description><![CDATA[typedef enum _SM_USER_MODE { SM_POWERUP, SM_ONLINE, SM_OFFLINE, SM_IDENTIFY } SM_USER_MODE;]]></description>
			<content:encoded><![CDATA[<pre><code>
typedef enum _SM_USER_MODE
{
    SM_POWERUP,
    SM_ONLINE,
    SM_OFFLINE,
    SM_IDENTIFY
} SM_USER_MODE;
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/typedef/typedef-for-text-based-values-state-machines/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Include</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/include</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/include#comments</comments>
		<pubDate>Fri, 14 Oct 2011 12:02:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General C Things]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=51</guid>
		<description><![CDATA[#include "..\ap-main"]]></description>
			<content:encoded><![CDATA[<pre><code>#include "..\ap-main"</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/include/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constants</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/constants</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/constants#comments</comments>
		<pubDate>Fri, 14 Oct 2011 12:00:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General C Things]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=48</guid>
		<description><![CDATA[&#8216;u&#8217; or &#8216;U&#8217; to indicate an unsigned constant, like 33u &#8216;ul&#8217; or &#8216;UL&#8217; to indicate an unsigned long constant, like 32767ul]]></description>
			<content:encoded><![CDATA[<p>&#8216;u&#8217; or &#8216;U&#8217; to indicate an unsigned constant, like 33u<br />
&#8216;ul&#8217; or &#8216;UL&#8217; to indicate an unsigned long constant, like 32767ul</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/constants/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AtoD conversion</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/atod/atod-conversion</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/atod/atod-conversion#comments</comments>
		<pubDate>Fri, 14 Oct 2011 11:51:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AtoD]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=45</guid>
		<description><![CDATA[Converting Direct Voltage Value //GET VOLTAGE //Vref = 3.3V //12bit AtoD = 0 to 4095 //4095 = 3.3V double d_temp; d_temp = (((double)3.3 / 4095) * atod_buffer_0); WORD voltage_x100; voltage_x100 = (WORD)((((double)3.3 / 4095) * atod_buffer_0) * 100); Converting Voltage Value After Potential Divider Resistors //Vref = 3.3V //12bit AtoD = 0 to 4095 //4095 [...]]]></description>
			<content:encoded><![CDATA[<h4>Converting Direct Voltage Value</h4>
<pre><code>
	//GET VOLTAGE
	//Vref = 3.3V
	//12bit AtoD = 0 to 4095
	//4095 = 3.3V

<span id="more-45"></span>

	double d_temp;
	d_temp = (((double)3.3 / 4095) * atod_buffer_0);

	WORD voltage_x100;
	voltage_x100 = (WORD)((((double)3.3 / 4095) * atod_buffer_0) * 100);
</code></pre>
<h4>Converting Voltage Value After Potential Divider Resistors</h4>
<pre><code>
	//Vref = 3.3V
	//12bit AtoD = 0 to 4095
	//4095 = 3.3V

	//Potential divider input:- Vin -&gt; 39K -&gt; AtoD -&gt; 100K -&gt; Gnd
	//Total resistance = 139
	//To Gnd resistance = 100

	double d_temp;
	d_temp = ((((double)3.3 * ((double)139 / 100)) / 4095) * atod_buffer_0);

	WORD voltage_x100;
	voltage_x100 = (WORD)(((((double)3.3 * ((double)139 / 100)) / 4095) * atod_buffer_0) * 100);
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/atod/atod-conversion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rint() Round to nearest integer</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/maths/rint-round-to-nearest-integer</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/maths/rint-round-to-nearest-integer#comments</comments>
		<pubDate>Thu, 10 Jun 2010 12:00:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Maths]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=34</guid>
		<description><![CDATA[The rint() function rounds a double to the nearest integer.  It&#8217;s output is still a double; For instance if double d = 5.83 x = (WORD)d; Would produce x=5 x = (WORD)rint(d); Would produce x=6]]></description>
			<content:encoded><![CDATA[<p>The rint() function rounds a double to the nearest integer.  It&#8217;s output is still a double;</p>
<p>For instance if double d = 5.83<br />
<span id="more-34"></span></p>
<pre><code>x = (WORD)d;</code></pre>
<p>Would produce x=5</p>
<pre><code>x = (WORD)rint(d);</code></pre>
<p>Would produce x=6</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/maths/rint-round-to-nearest-integer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exponent</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/maths/exponent</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/maths/exponent#comments</comments>
		<pubDate>Wed, 09 Jun 2010 08:57:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Maths]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=32</guid>
		<description><![CDATA[^ is the character for Exponent (EXP on a calculator) In C you use pow() pow(base, exponent) In C you can use exponents in two places. Firstly, where numbers are so large or so small that decimal point notation is not human-readable. For instance 100,000,000,000 is best written as 1 * 10 ^11. Secondly where [...]]]></description>
			<content:encoded><![CDATA[<p>^ is the character for Exponent (EXP on a calculator)</p>
<p>In C you use pow()</p>
<pre><code>	pow(base, exponent)</code></pre>
<p><span id="more-32"></span></p>
<p>In C you can use exponents in two places. Firstly, where numbers are so large or so small that decimal point notation is not human-readable. For instance 100,000,000,000 is best written as 1 * 10 ^11. Secondly where the program logic calls for a value to be raised to the power of another value.</p>
<p>For instance, say you have a virus multiplying in a large population, and each infected person infects another five on average before dying. How many people will be infected after N rounds? The answer is 5^N, or, in C, pow(5.0, N).</p>
<p>For mathematical reasons which are too involved to go into here the expression e^x has special characteristics, so it has its own function, exp(). The expression x^0.5, or sqrt(x) is also special and has its own function &#8211; here it is easy for a non-mathematician to see the value of this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/maths/exponent/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typedef, struct union</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/memory/typedef-struct-union</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/memory/typedef-struct-union#comments</comments>
		<pubDate>Wed, 09 Jun 2010 08:54:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Memory]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=30</guid>
		<description><![CDATA[Typedef Union For Different Definitions Of The Same Memory Locations typedef union _SYSTEM_CONFIGURATION_TYPEDEF { DWORD dw[25]; WORD w[50]; BYTE b[100]; } SYSTEM_CONFIGURATION_TYPEDEF; SYSTEM_CONFIGURATION_TYPEDEF system_config_buffer; system_config_buffer.b[0] = 1; system_config_buffer.b[1] = 2; system_config_buffer.b[2] = 3; system_config_buffer.b[3] = 4; system_config_buffer.b[4] = 5; //Will give: //system_config_buffer.w = 0x0201 //system_config_buffer.dw = 0x04030201 Typedef Struct For A Buffer Of Different Registers [...]]]></description>
			<content:encoded><![CDATA[<h4>Typedef Union For Different Definitions Of The Same Memory Locations</h4>
<pre><code>
typedef union _SYSTEM_CONFIGURATION_TYPEDEF
{
    DWORD dw[25];
    WORD w[50];
    BYTE b[100];
} SYSTEM_CONFIGURATION_TYPEDEF;

<span id="more-30"></span>

SYSTEM_CONFIGURATION_TYPEDEF system_config_buffer;

	system_config_buffer.b[0] = 1;
	system_config_buffer.b[1] = 2;
	system_config_buffer.b[2] = 3;
	system_config_buffer.b[3] = 4;
	system_config_buffer.b[4] = 5;
	//Will give:
	//system_config_buffer.w = 0x0201
	//system_config_buffer.dw = 0x04030201
</code></pre>
<h4>Typedef Struct For A Buffer Of Different Registers In An Buffer</h4>
<pre><code>
typedef struct _TEST_HEADER
{
	WORD source_port;
	DWORD sequence_number;

	union		//<<< You can also have unions inside a struct
	{
		struct
		{
			BYTE flag_fin	:1;
			BYTE flag_syn	:1;
			BYTE flag_rst	:1;
			BYTE flag_psh	:1;
			BYTE flag_ack	:1;
			BYTE flag_urg	:1;
			BYTE reserved	:2;
		} bits;
		BYTE byte;
	} flags;

	WORD window;
} TEST_HEADER;
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/memory/typedef-struct-union/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>State ? ( ) : ( )</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/state</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/state#comments</comments>
		<pubDate>Wed, 09 Jun 2010 08:53:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General C Things]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=28</guid>
		<description><![CDATA[Usage Examples #define USART_DIR_TX(state) (state ? ([true]) : ([false])) (state ? true : false) //1:0 #define OUTPUT_PIN(state) (state ? LATAbis.LATA1 = 1 : LATAbis.LATA1 = 0) //1:0 bytesThisSector = (bytesLeftToWrite &#62; 512) ? 512 : bytesLeftToWrite;]]></description>
			<content:encoded><![CDATA[<h4>Usage Examples</h4>
<pre><code>
#define	USART_DIR_TX(state)	(state ? ([true]) : ([false]))

(state ? true : false)  //1:0

<span id="more-28"></span>

#define OUTPUT_PIN(state) (state ? LATAbis.LATA1 = 1 : LATAbis.LATA1 = 0)  //1:0

	bytesThisSector = (bytesLeftToWrite &gt; 512) ? 512 : bytesLeftToWrite;

</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/general-c-things/state/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sizeof</title>
		<link>http://www.electronic-products-development.com/embedded-programming/c-programming/memory/sizeof</link>
		<comments>http://www.electronic-products-development.com/embedded-programming/c-programming/memory/sizeof#comments</comments>
		<pubDate>Wed, 09 Jun 2010 08:52:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Memory]]></category>

		<guid isPermaLink="false">http://www.electronic-products-development.com/?p=26</guid>
		<description><![CDATA[The sizeof operator yeilds the number of bytes required to store an object of the type of its operand. sizeof(char) // = 1 sizeof(my_array) // = size of the array in bytes sizeof(my_structure) // = size of the structure in bytes sizeof(my_union) // = size of the union in bytes for count = 0; count [...]]]></description>
			<content:encoded><![CDATA[<p>The sizeof operator yeilds the number of bytes required to store an object of the type of its operand.<span id="more-26"></span></p>
<pre><code>
	sizeof(char) 		// = 1
	sizeof(my_array) 		// = size of the array in bytes
	sizeof(my_structure) 	// = size of the structure in bytes
	sizeof(my_union) 		// = size of the union in bytes

	for count = 0; count < (sizeof(my_array) / sizeof(my_array_tye)); count++)
	{
		//Do each entry in the array of a not necessarily known object size
</code></pre>
<p>Note that 16 and 32bit compilers may add padd bytes and these will be included in the sizeof - this can be a source of bugs!</p>
<h4>Avoiding Padding</h4>
<p>You can used the packed variable attribute. For example in the following code, type c_t will have a size of 3 bytes and there will be no wasted space between a and b:</p>
<pre><code>
typedef struct
{
  unsigned char a[1];
} __attribute__ ((packed)) a_t;

typedef struct
{
  unsigned char b[2];
} __attribute__ ((packed)) b_t;

typedef struct
{
  a_t a;
  b_t b;
} __attribute__ ((packed)) c_t;
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.electronic-products-development.com/embedded-programming/c-programming/memory/sizeof/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

