<?xml version="1.0" encoding="utf-8"?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rss  version="2.0">
				<channel>
				<title>8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes : Forum / topic</title>
				<link>http://www.8051projects.net/</link>
				<description>Learn to make simple microcontroller projects, pic, 8051, avr and arm projects. download 8051 projects, tutorials, libraries, sample codes. join the microcontroller discussion forum and ask doubts regarding electronics. the best source for 8051 over internet.</description>

<language>en-gb</language>
				<copyright><a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/in/" target="_blank"><img alt="Creative Commons License" width="80" height="15" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/2.5/in/80x15.png" target="_blank" /></a>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/in/" target="_blank">Creative Commons Attribution-Noncommercial 2.5 India License</a>.<a href='http://www.8051projects.net/disclaimer.htm' target='_blank' />Rickey's World Disclaimer</a></copyright>
				<managingEditor>Ajay Bhargav - contact@nospam.com</managingEditor>
				<webMaster>contact@nospam.com</webMaster>
				<pubDate>Mon, 01 Dec 2008 12:18:43 -0800</pubDate>
				<lastBuildDate>Mon, 01 Dec 2008 12:18:43 -0800</lastBuildDate>
				<docs>http://backend.userland.com/rss</docs>
				<generator>e107 (http://e107.org)</generator>
				<ttl>60</ttl>
				<textInput>
				<title>Search</title>
				<description>Search 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes</description>
				<name>query</name>
				<link>http://www.8051projects.net/search.php</link>
				</textInput>
						<item>
						<title>code help needed for my lazy friend</title>
<link>http://www.8051projects.net/forum-t9121.html</link>
<description><![CDATA[hi bros,<br /><br />i have a very lazy friend.he has been given a project ( to complete in class) which is based on ARM.Now the problem is that he has copied a project from internet,but he dont know what the code is doing actually..or what code can do.now its my headache to help him...but i dont know much about ARM.<br />Can anyone help me understanding that code?? so that i can help him. <img src='http://www.8051projects.net/e107_images/emotes/yahoo/17.gif' alt='' style='vertical-align:middle; border:0' />  <br /><br /><span class='bbcode underline' style='text-decoration:underline'>Code:</span><br /> <div class=''>CODE:</div><div class='code_highlight' style='unicode-bidi: embed; direction: ltr'><div class="c" style="font-family: monospace;"><br /><span style="color: #808080; font-style: italic;">//=====================================================================</span><br /><span style="color: #808080; font-style: italic;">// Sean Finn, FYP 2006</span><br /><span style="color: #808080; font-style: italic;">// Embedded C control program for the ARM microcroller used</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp;as core of the ETU</span><br /><span style="color: #808080; font-style: italic;">//</span><br /><span style="color: #808080; font-style: italic;">//---------------------------------------------------------------------</span><br /><span style="color: #808080; font-style: italic;">// Operation:</span><br /><span style="color: #808080; font-style: italic;">// Samples EKG &amp; stethoscope signals (attached to ADC channels 0 &amp; 1,</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp;respectively), at 2.5 kHz &amp; 500 Hz &nbsp; &nbsp; &nbsp;(respectively).</span><br /><span style="color: #808080; font-style: italic;">// These 12 bit samples are then sent, a nibble at a time, to</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp;Server PC thorough UART at 115200 baud (no parity, 2 stop bits)</span><br /><span style="color: #808080; font-style: italic;">//=====================================================================</span><br /><br /><span style="color: #339933;">#include &lt;ADuC7024.h&gt; &nbsp;//include definitions specific to eval board used</span><br /><br /><span style="color: #808080; font-style: italic;">// function prototypes: definintions in seperate source file</span><br /><span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">int</span> write <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> file, <span style="color: #993333;">char</span> * ptr, <span style="color: #993333;">int</span> len<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// outputs a string on UART (for debug) &nbsp; &nbsp; </span><br /><span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">int</span> put_byte<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// outputs a byte via UART </span><br /><span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> send_pak<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span>* buffer, <span style="color: #993333;">int</span> buff_size<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//sends the entrire Tx buffer</span><br /><span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> initialise<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// performs ARM initialisation (peripherals etc)</span><br /><span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> IRQ_func<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// ADC interrupt servive routine</span><br /><br /><span style="color: #808080; font-style: italic;">//global variables</span><br /><br /><span style="color: #808080; font-style: italic;">// variables associated with ADC conversions</span><br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> xn = <span style="color: #cc66cc;">0</span>;<br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> xn2 =<span style="color: #cc66cc;">0</span>;<br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> samp_ctr = <span style="color: #cc66cc;">0</span>;<br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> pak_ctr = <span style="color: #cc66cc;">0</span>;<br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> dwnsmpl_ctr = <span style="color: #cc66cc;">0</span>;<br /><span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> dwnsmpl_ratio = <span style="color: #cc66cc;">5</span>; <span style="color: #808080; font-style: italic;">// 500 Hz EKG sampling frequency</span><br /><br /><span style="color: #808080; font-style: italic;">// buffer variables</span><br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> buffer_size = <span style="color: #cc66cc;">6012</span>;<br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> send_buff1<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">6012</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span>; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// circular transmitt buffer</span><br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buffer_full = <span style="color: #cc66cc;">0</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// buffer full flag</span><br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buff_send_margin = <span style="color: #cc66cc;">99</span>; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// send margin, to avoid buffer overrun (must be multiple of 3)</span><br /><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span>* UART_ptr; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// pointer to address the transmit buffer</span><br /><br /><span style="color: #808080; font-style: italic;">//filtering variables, redundant here (see note below)</span><br /><span style="color: #808080; font-style: italic;">// filter co-efficients</span><br /><span style="color: #808080; font-style: italic;">//unsigned short co_efs&#091;21] = {46637,49888,52926,55711,58208,60382,62202,63644,64689,</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;65322,65535,65322,64689,63644,62202,60382,58208,55711,52926,</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;49888,46637}; &nbsp;//20th order LPF &nbsp; </span><br /><span style="color: #808080; font-style: italic;">//static unsigned char FILT_ORD = 20; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //order of the digital LPF implemented</span><br /><span style="color: #808080; font-style: italic;">//unsigned short mem&#091;20] = {0}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //filters memory elements, of size FILT_ORD</span><br /><span style="color: #808080; font-style: italic;">//unsigned short filtered_smpl;</span><br /><br /><span style="color: #993333;">int</span> main <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//char output1&#091;13] = &quot;Hello World!\n&quot;; &nbsp; &nbsp; &nbsp;// debugging UART test</span><br /><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// pefore ADC is enabled, set up buffer, point pointer to first element of buffer array</span><br />&nbsp; &nbsp; UART_ptr = &amp;send_buff1<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br /><br />&nbsp; &nbsp; initialise<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//initialise peripherals: UART, ADC, etc</span><br /><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set up the IRQ</span><br />&nbsp; &nbsp; FIQ = IRQ_func; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;Specify (Fast) Interrupt Service Rountine</span><br />&nbsp; &nbsp; FIQEN = 0x8; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// enable timer 1 IRQ mask</span><br />&nbsp; &nbsp; GP4DAT ^= 0x00040000; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Complement P4.2 (LED), to indicate program is started</span><br /><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Main functionality handled by ADC ISR</span><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Infinite loop, poll for full buffer flag, calling send_pak function when detected</span><br />&nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> buffer_full == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GP4DAT ^= 0x00040000; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Complement P4.2 (LED)</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; send_pak<span style="color: #66cc66;">&#40;</span>UART_ptr, buffer_size<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// send the packet</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UART_ptr = &amp;send_buff1<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// reset send pointer</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer_full = <span style="color: #cc66cc;">0</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// reset eand flag</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #808080; font-style: italic;">//=============ADC interrupt servive routine=========================</span><br /><span style="color: #808080; font-style: italic;">// Medodology: Timer 1 triggers a conversions at 2.5 kHz, and a</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;sthethoscope &nbsp;sample is read &amp; stored in buffer.</span><br /><span style="color: #808080; font-style: italic;">// &nbsp;Upon every 5th such conversion (ie at 500 Hz), a software</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;triggeredconversion of EKG channel is performed.</span><br /><span style="color: #808080; font-style: italic;">//</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;In prevoius versions, both were sampled at higher rate, and the</span><br /><span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;EKG was low pass filtered, and then downsampled. In this version</span><br /><span style="color: #808080; font-style: italic;">// &nbsp;filtering code is commented (no downsampling =&gt; no filtering required).</span><br /><span style="color: #808080; font-style: italic;">//====================================================================</span><br /><br /><br /><span style="color: #993333;">void</span> IRQ_func<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//unsigned short j; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// local counter declaration (filtering)</span><br />&nbsp; &nbsp; GP1DAT ^= 0x00800000; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Complement P1.7 &nbsp; &nbsp; (debug - ADC freq probing)</span><br />&nbsp; &nbsp; &nbsp; &nbsp;T1CLRI = <span style="color: #cc66cc;">0</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// clear timer 1 interrupt flag</span><br />&nbsp; &nbsp; xn = <span style="color: #66cc66;">&#40;</span>ADCDAT &gt;&gt; <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> &amp; 0xFFF; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// read ADC sample</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// nibble by nibble sample stroage. MS nibble of each byte is a counter,</span><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// used for decoding data stream at PC server &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//store steth sample in byte-wide buffer: MSNibble, MiddleNibble LSNibble</span><br />&nbsp; &nbsp; send_buff1<span style="color: #66cc66;">&#91;</span>samp_ctr<span style="color: #66cc66;">&#93;</span> = 0x40 | <span style="color: #66cc66;">&#40;</span>xn &gt;&gt; <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; samp_ctr++;<br />&nbsp; &nbsp; send_buff1<span style="color: #66cc66;">&#91;</span>samp_ctr<span style="color: #66cc66;">&#93;</span> = 0x20 | &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xn &gt;&gt; <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> &amp; 0xF<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; samp_ctr++;<br />&nbsp; &nbsp; send_buff1<span style="color: #66cc66;">&#91;</span>samp_ctr<span style="color: #66cc66;">&#93;</span> = 0x10 | <span style="color: #66cc66;">&#40;</span>xn &amp; 0xF<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; samp_ctr++;<br /><br />&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>dwnsmpl_ctr == dwnsmpl_ratio <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// every 5th sample</span><br />&nbsp; &nbsp; &nbsp; &nbsp; GP1DAT ^= 0x00010000; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Complement P1.0 &nbsp; &nbsp;(debug - ADC freq probing) &nbsp; &nbsp; &nbsp; &nbsp;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//perform a signle sofware driven ADC conversion from chan 1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; ADCCP = 0x01; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//switch ADC channel</span><br />&nbsp; &nbsp; &nbsp; &nbsp; ADCCON = 0xE3; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// config for a software conversion &nbsp; &nbsp; &nbsp; </span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>!ADCSTA<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// wait for end of conversion</span><br />&nbsp; &nbsp; &nbsp; &nbsp; xn = <span style="color: #66cc66;">&#40;</span>ADCDAT &gt;&gt; <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// read ADC sample</span><br />&nbsp; &nbsp; &nbsp; &nbsp; ADCCP = 0x07; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// select steth channel (1) again</span><br />&nbsp; &nbsp; &nbsp; &nbsp; ADCCON=0xE1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//return ADC config to timer 1 driven conversions</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Digital filtering, now redundant.</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//--------EKG sample now read, perform filtering------------//</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//filtered_smpl = co_efs&#091;0]*xn;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//for(j=1;j&lt;FILT_ORD;j++) {</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;filtered_smpl += co_efs&#091;j]*mem&#091;j-1];</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//}</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//update memory elements</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//for(j=FILT_ORD;j&gt;0;j--){</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// &nbsp; &nbsp;mem&#091;j] = mem&#091;j-1];</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//}</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//mem&#091;0] = xn;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//------Digital Filtering Complete-----------------------//</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//store the sample, samp method as for steth samples</span><br />&nbsp; &nbsp; &nbsp; &nbsp; xn = <span style="color: #66cc66;">&#40;</span>ADCDAT &gt;&gt; <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>&amp; 0xFFF;<br />&nbsp; &nbsp; &nbsp; &nbsp; send_buff1<span style="color: #66cc66;">&#91;</span>samp_ctr<span style="color: #66cc66;">&#93;</span> = 0xC0 | <span style="color: #66cc66;">&#40;</span>xn &gt;&gt; <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; samp_ctr++;<br />&nbsp; &nbsp; &nbsp; &nbsp; send_buff1<span style="color: #66cc66;">&#91;</span>samp_ctr<span style="color: #66cc66;">&#93;</span> = 0xB0 | &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xn &gt;&gt; <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> &amp; 0xF<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; samp_ctr++;<br />&nbsp; &nbsp; &nbsp; &nbsp; send_buff1<span style="color: #66cc66;">&#91;</span>samp_ctr<span style="color: #66cc66;">&#93;</span> = 0xA0 | <span style="color: #66cc66;">&#40;</span>xn &amp; 0xF<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; samp_ctr++;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; dwnsmpl_ctr = <span style="color: #cc66cc;">0</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//reset counter</span><br />&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwnsmpl_ctr++; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//increment counter</span><br />&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// watch for buffer almost full</span><br />&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>samp_ctr == buffer_size - buff_send_margin<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer_full = <span style="color: #cc66cc;">1</span>; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// set the buffer full flag, main() will begin transmission</span><br />&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>samp_ctr == buffer_size<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//at the end of buffer, start filling from start again</span><br />&nbsp; &nbsp; &nbsp; &nbsp; samp_ctr = <span style="color: #cc66cc;">0</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//reset sample counter</span><br />&nbsp; &nbsp; &nbsp; &nbsp; pak_ctr++;<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /><span style="color: #66cc66;">&#125;</span><br /><span style="color: #808080; font-style: italic;">//=====================================================================</span><br /><span style="color: #808080; font-style: italic;">// Final Year Project ARM functions</span><br /><span style="color: #808080; font-style: italic;">// Sean Finn, 2006</span><br /><span style="color: #808080; font-style: italic;">//=====================================================================</span><br /><span style="color: #339933;">#include &lt;aduc7024.H&gt; &nbsp; &nbsp; &nbsp;//include definitions specific to eval board used &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br /><br /><span style="color: #339933;">#define CR &nbsp; &nbsp; 0x0D &nbsp; &nbsp; &nbsp;//define ASCII code for carrige return, for string Tx</span><br /><br /><span style="color: #808080; font-style: italic;">// standard delay routine</span><br /><span style="color: #993333;">void</span> delay<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> length<span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>length &gt;=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; length--;<br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #808080; font-style: italic;">// outputs a byte via UART</span><br /><span style="color: #993333;">int</span> put_byte<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> ch<span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /><br />&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ch == <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// handle sending of newline</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #66cc66;">&#40;</span>0x020==<span style="color: #66cc66;">&#40;</span>COMSTA0 &amp; 0x020<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//wait for UART not busy</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; COMTX = CR; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #66cc66;">&#40;</span>0x020==<span style="color: #66cc66;">&#40;</span>COMSTA0 &amp; 0x020<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//wait for UART not busy</span><br />&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>COMTX = ch<span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #808080; font-style: italic;">//sends the entrire Tx buffer</span><br /><span style="color: #993333;">void</span> send_pak<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span>* buffer, <span style="color: #993333;">int</span> buff_size<span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> i;<br />&nbsp; &nbsp; &nbsp; &nbsp; delay<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>i=<span style="color: #cc66cc;">0</span>;i&lt;buff_size;i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// loop through Tx buffer</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; put_byte<span style="color: #66cc66;">&#40;</span>*<span style="color: #66cc66;">&#40;</span>buffer+i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// send current byte using pointer arithmetic</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #808080; font-style: italic;">// outputs a string on UART (for debug)</span><br /><span style="color: #993333;">int</span> write <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> file, <span style="color: #993333;">char</span> * ptr, <span style="color: #993333;">int</span> len<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />&nbsp; <span style="color: #993333;">int</span> i;<br /><br />&nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>i = <span style="color: #cc66cc;">0</span>; i &lt; len; i++<span style="color: #66cc66;">&#41;</span> put_byte <span style="color: #66cc66;">&#40;</span>*ptr++<span style="color: #66cc66;">&#41;</span>;<br />&nbsp; <span style="color: #b1b100;">return</span> len;<br /><span style="color: #66cc66;">&#125;</span><br /><br /><span style="color: #808080; font-style: italic;">// performs ARM initialisation (peripherals etc)</span><br /><span style="color: #993333;">void</span> initialise<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp;<br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// UART configuration for 115200 baud</span><br />&nbsp; &nbsp; GP1CON = 0x011; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Setup tx &amp; rx pins on P1.0 and P1.1</span><br />&nbsp; &nbsp; COMCON0 = 0x80; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Setting DLAB</span><br />&nbsp; &nbsp; &nbsp; &nbsp;COMDIV0 = 0x0C; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Setting DIV0 and DIV1 to DL calculated</span><br />&nbsp; &nbsp; &nbsp; &nbsp;COMDIV1 = 0x00;<br />&nbsp; &nbsp; &nbsp; &nbsp;COMCON0 = 0x07; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Clearing DLAB</span><br />&nbsp; &nbsp; COMDIV2 = 0x884F;<br /><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//ADC configuration</span><br />&nbsp; &nbsp; ADCCON=0x20; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//power-on the ADC</span><br />&nbsp; &nbsp; delay<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">80000</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//wait for ADC poweron time</span><br />&nbsp; &nbsp; ADCCP=0x00; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//Select ADC channel 0 by default</span><br />&nbsp; &nbsp; ADCCON=0xE1; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//single-ended, start conversion on timer1</span><br />&nbsp; &nbsp; REFCON=0x01; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//connect internal 2.5V reference to VREFpin</span><br /><br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// timer1 configuration &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />&nbsp; &nbsp; T1LD = 0x467; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Counter Value (for 2.5 kHz)</span><br />&nbsp; &nbsp; T1CON = 0xC4; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Enabled,Periodic,Binary</span><br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// IO ports initialisation</span><br />&nbsp; &nbsp; GP1DAT = 0xFF000000; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; GP3DAT = 0xFFFF0000;<br />&nbsp; &nbsp; GP4DAT = 0x04000000; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// P4.2 configured as an output. LED is turned on </span><br /><span style="color: #66cc66;">&#125;</span><br />&nbsp;</div></div>]]></description>
<pubDate>Tue, 29 Apr 2008 03:08:03 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t9121.html</guid>
</item>
						<item>
						<title>Re: code help needed for my lazy friend</title>
<link>http://www.8051projects.net/forum-t9121.html</link>
<description><![CDATA[shyam bhai,<br />can you help me regarding this ?:(]]></description>
<author>abbas1707&lt;abbas@nospam.com&gt;</author>
<pubDate>Thu, 01 May 2008 03:29:34 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t9121.html</guid>
</item>
						<item>
						<title>Re: code help needed for my lazy friend</title>
<link>http://www.8051projects.net/forum-t9121.html</link>
<description><![CDATA[hi abbas hope i am not late   <img src='http://www.8051projects.net/e107_images/emotes/yahoo/2.gif' alt='' style='vertical-align:middle; border:0' /> <br /><br /><div class='indent'>Samples EKG &amp; stethoscope signals (attached to ADC channels 0 &amp; 1,<br />        respectively), at 2.5 kHz &amp; 500 Hz      (respectively).<br /> These 12 bit samples are then sent, a nibble at a time, to<br />        Server PC thorough UART at 115200 baud (no parity, 2 stop bits)</div><br /><br />lets see how the code works..<br /><br /><br />lets first collect what devices we shall be requiring<br />1. 2 ADC channels<br />2. 1 UART port (Tx Rx)<br />3. Timer to set the interrupt (to read the adc)<br />4. GPIOs to connect LEDs (to show the response /result)<br /><br />we have to initialise all these devices first..<br /><div class='indent'>void initialise(void)</div><br /><br />the above function does it..  the comments are self axplainatory.. still we can discuss each of the statements.<br /><br />the main  part is to scan the two ADC pins for data..<br />ARM has several interrupt sources one of them is IRQ the other is FIQ<br />dont really know y ur frnd used FIQ here..   still FIQ is faster than IRQ.<br /><br />so we need to  write an IRQ ISR<br /><br /><div class='indent'>void IRQ_func(void) {</div><br /><br />the above function does it. The ISR collects the adc values and stores it in a buffer <br />send_buff1<br /><br />now the stored data is needed to send thru UART and the leds needed to be controlled<br /><br />so in main()<br />step1.  call the initialisation<br />step2. point the FIQ to the fun PTR of your ISR<br />step3. enable the interrupt source  i.e timer in FIQ mode<br />step4. start an never ending loop  to transmit collected data and toggle the respective pins.<br /><br /><br />actually been busy these few days so cud not reply on time  <img src='http://www.8051projects.net/e107_images/emotes/yahoo/10.gif' alt='' style='vertical-align:middle; border:0' />]]></description>
<author>shyam&lt;shyam@nospam.com&gt;</author>
<pubDate>Thu, 01 May 2008 04:14:57 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t9121.html</guid>
</item>
						<item>
						<title>Re: code help needed for my lazy friend</title>
<link>http://www.8051projects.net/forum-t9121.html</link>
<description><![CDATA[Thanks a ton bhai <img src='http://www.8051projects.net/e107_images/emotes/yahoo/1.gif' alt='' style='vertical-align:middle; border:0' />]]></description>
<author>abbas1707&lt;abbas@nospam.com&gt;</author>
<pubDate>Thu, 01 May 2008 16:30:35 -0700</pubDate>
<guid isPermaLink="true">http://www.8051projects.net/forum-t9121.html</guid>
</item>
				</channel>
				</rss>