<?xml version="1.0" encoding="utf-8" ?>
				<!-- generator="e107" -->
				<!-- content type="Forum / topic" -->
				<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
				<channel rdf:about="http://www.8051projects.net/">
				<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>
				<dc:language>en-gb</dc:language>
				<dc:date>2009-01-07T13:05:22-08:00</dc:date>
				<dc:creator>contact@nospam.com</dc:creator>
				<admin:generatorAgent rdf:resource="http://e107.org" />
				<admin:errorReportsTo rdf:resource="mailto:contact@nospam.com" />
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
				<items>
				<rdf:Seq>
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
						<rdf:li rdf:resource="http://www.8051projects.net/forum-t10431.html" />
				</rdf:Seq>
				</items>
				</channel>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator></dc:creator>
						<dc:subject></dc:subject>
						<description>suppose in an industrial application  we have to controll some events ,which are time dependent, using microcontroller.the problem is like : there are 10 deveces  . and these devices runs for 10 second (say) if it gets an input signal.(note : all these 10 devices gets input signals randomly i.e. some times 2 devices may get input signal ,sometimes 4 or 5 or 8 or all 10 etc.)now suppose  if in first time slot (i.e. 10 second) 5 devices are running  and before the end of first time slot another 2 devices gets input signal  .... and so on ...how would u  controll it using single microcontroller .</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>Would the devices go off after 10s by themselves or does the micro have to switch them off after the time slot elapses?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>hi caze,i don't see where you are having problem, can you be more clearArun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>hi Cazehere  comes the fundamental RTOS functionalities Semaphores mutex and mutual exclusion.by using one or more than one or all of the above techniques we can 1. set priorities to the Tasks2. make other tasks wait for the previous o complete, without missing input signals.3. store the sequence of inputs in page tables (as in your computer)  and then proccess accordingly may be by a. FIFO or Priority basis or both. that is the reason most of the industrial automation tenders  nowadays  necessarily mention RTOS as the main part of the product.i believe using RTOS will solve the problem, still if ur uController doesnt support it..  u can make the necessary routines  yourselves.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>caze</dc:creator>
						<dc:subject></dc:subject>
						<description>hi @  sashijoseph,                          devices has to be stoped by microcontroller itself.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>caze</dc:creator>
						<dc:subject></dc:subject>
						<description>hi shyam,                great idea. but i guess writing routine for 8051 will be too lengthy and tedious work .is it possible to</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>yes it can be written    u will find some keil examples with RTX51.a little effort and u can get the source of the kernel too  ammend it according to ur need and u'll get the solution..here take a look this is a 51 code! CODE:<br />/******************************************************************************/<br />/* &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;*/<br />/* &nbsp; TRAFFIC.C: &nbsp;Traffic Light Controller using the C-51 COMPILER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />/* &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;*/<br />/******************************************************************************/<br /><br />char code menu&#91;&#93; =<br />&nbsp; &nbsp;"\n"<br />&nbsp; &nbsp;"+***** TRAFFIC LIGHT CONTROLLER using C51 and RTX-51 tiny *****+\n"<br />&nbsp; &nbsp;"| This program is a simple Traffic Light Controller. &nbsp;Between &nbsp;|\n"<br />&nbsp; &nbsp;"| start time and end time the system controls a traffic light &nbsp;|\n"<br />&nbsp; &nbsp;"| with pedestrian self-service. &nbsp;Outside of this time range &nbsp; &nbsp;|\n"<br />&nbsp; &nbsp;"| the yellow caution lamp is blinking. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |\n"<br />&nbsp; &nbsp;"+ command -+ syntax -----+ function ---------------------------+\n"<br />&nbsp; &nbsp;"| Display &nbsp;| D &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | display times &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |\n"<br />&nbsp; &nbsp;"| Time &nbsp; &nbsp; | T hh:mm:ss &nbsp;| set clock time &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|\n"<br />&nbsp; &nbsp;"| Start &nbsp; &nbsp;| S hh:mm:ss &nbsp;| set start time &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|\n"<br />&nbsp; &nbsp;"| End &nbsp; &nbsp; &nbsp;| E hh:mm:ss &nbsp;| set end time &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|\n"<br />&nbsp; &nbsp;"+----------+-------------+-------------------------------------+\n";<br /><br /><br />#include &lt;reg52.h> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* special function registers 8052 &nbsp; &nbsp; &nbsp;*/<br />#include &lt;rtx51tny.h> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* RTX-51 tiny functions &amp; defines &nbsp; &nbsp; &nbsp;*/<br />#include &lt;stdio.h> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* standard I/O .h-file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />#include &lt;ctype.h> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* character functions &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />#include &lt;string.h> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* string and memory functions &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br /><br /><br />extern getline &#40;char idata *, char&#41;; &nbsp;/* external function: &nbsp;input line &nbsp; &nbsp; &nbsp; */<br />extern serial_init &#40;&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* external function: &nbsp;init serial UART */<br /><br />#define INIT &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />#define COMMAND &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;command &nbsp; &nbsp; &nbsp; &nbsp;*/<br />#define CLOCK &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;clock &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />#define BLINKING &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;blinking &nbsp; &nbsp; &nbsp; */<br />#define LIGHTS &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;signal &nbsp; &nbsp; &nbsp; &nbsp; */<br />#define KEYREAD &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;keyread &nbsp; &nbsp; &nbsp; &nbsp;*/<br />#define GET_ESC &nbsp; 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* task number of task: &nbsp;get_escape &nbsp; &nbsp; */<br /><br />struct time &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* structure of the time record &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; unsigned char hour; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* hour &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; unsigned char min; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* minute &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; unsigned char sec; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* second &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&#125;;<br /><br />struct time ctime = &#123; 12, &nbsp;0, &nbsp;0 &#125;; &nbsp; /* storage for clock time values &nbsp; &nbsp; &nbsp; &nbsp;*/<br />struct time start = &#123; &nbsp;7, 30, &nbsp;0 &#125;; &nbsp; /* storage for start time values &nbsp; &nbsp; &nbsp; &nbsp;*/<br />struct time end &nbsp; = &#123; 18, 30, &nbsp;0 &#125;; &nbsp; /* storage for end &nbsp; time values &nbsp; &nbsp; &nbsp; &nbsp;*/<br /><br />sbit &nbsp;red &nbsp; &nbsp;= P1^2; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* I/O Pin: &nbsp;red &nbsp; &nbsp;lamp output &nbsp; &nbsp; &nbsp; &nbsp; */<br />sbit &nbsp;yellow = P1^1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* I/O Pin: &nbsp;yellow lamp output &nbsp; &nbsp; &nbsp; &nbsp; */<br />sbit &nbsp;green &nbsp;= P1^0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* I/O Pin: &nbsp;green &nbsp;lamp output &nbsp; &nbsp; &nbsp; &nbsp; */<br />sbit &nbsp;stop &nbsp; = P1^3; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* I/O Pin: &nbsp;stop &nbsp; lamp output &nbsp; &nbsp; &nbsp; &nbsp; */<br />sbit &nbsp;walk &nbsp; = P1^4; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* I/O Pin: &nbsp;walk &nbsp; lamp output &nbsp; &nbsp; &nbsp; &nbsp; */<br />sbit &nbsp;key &nbsp; &nbsp;= P1^5; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* I/O Pin: &nbsp;self-service key input &nbsp; &nbsp; */<br /><br />char idata inline&#91;16&#93;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* storage for command input line &nbsp; &nbsp; &nbsp; */<br /><br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;Task 0 'init': Initialize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />/******************************************************************************/<br />void init &#40;void&#41; _task_ INIT &nbsp;&#123; &nbsp; &nbsp; &nbsp; /* program execution starts here &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; serial_init &#40;&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* initialize the serial interface &nbsp; &nbsp; &nbsp;*/<br />&nbsp; os_create_task &#40;CLOCK&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* start clock task &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; os_create_task &#40;COMMAND&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* start command task &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; os_create_task &#40;LIGHTS&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* start lights task &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; os_create_task &#40;KEYREAD&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* start keyread task &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; os_delete_task &#40;INIT&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* stop init task (no longer needed) &nbsp; &nbsp;*/<br />&#125;<br /><br /><br />bit display_time = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* flag: &nbsp;signal cmd state display_time */<br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;Task 2 'clock' &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;*/<br />/******************************************************************************/<br />void clock &#40;void&#41; &nbsp;_task_ CLOCK &nbsp;&#123;<br />&nbsp; while &#40;1&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* clock is an endless loop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; if &#40;++ctime.sec == 60&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; /* calculate the second &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; ctime.sec = 0;<br />&nbsp; &nbsp; &nbsp; if &#40;++ctime.min == 60&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; /* calculate the minute &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; ctime.min = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; if &#40;++ctime.hour == 24&#41; &nbsp;&#123; &nbsp; &nbsp;/* calculate the hour &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctime.hour = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; if &#40;display_time&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* if command_status == display_time &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; os_send_signal &#40;COMMAND&#41;; &nbsp; &nbsp; &nbsp; /* signal to task command: time changed */<br />&nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; os_wait &#40;K_IVL, 100, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* wait interval: &nbsp;1 second &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &#125;<br />&#125;<br /><br /><br />struct time rtime; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* temporary storage for entry time &nbsp; &nbsp; */<br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;readtime: convert line input to time values &amp; store in rtime &nbsp; &nbsp; &nbsp; &nbsp;*/<br />/******************************************************************************/<br />bit readtime &#40;char idata *buffer&#41; &nbsp;&#123;<br />&nbsp; unsigned char args; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* number of arguments &nbsp; &nbsp; &nbsp; &nbsp; */<br /><br />&nbsp; rtime.sec = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* preset second &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; args = sscanf &#40;buffer, "%bd:%bd:%bd", &nbsp; &nbsp; &nbsp; &nbsp;/* scan input line for &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&rtime.hour, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* hour, minute and second &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&rtime.min,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&rtime.sec&#41;;<br />&nbsp;<br />&nbsp; if &#40;rtime.hour > 23 &nbsp;|| &nbsp;rtime.min > 59 &nbsp;|| &nbsp;/* check for valid inputs &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; rtime.sec > 59 &nbsp; || &nbsp;args &lt; 2 &nbsp; &nbsp; &nbsp; &nbsp;|| &nbsp;args == EOF&#41; &nbsp;&#123;<br />&nbsp; &nbsp; printf &#40;"\n*** ERROR: INVALID TIME FORMAT\n"&#41;;<br />&nbsp; &nbsp; return &#40;0&#41;;<br />&nbsp; &#125;<br />&nbsp; return &#40;1&#41;;<br />&#125;<br /><br /><br /><br />#define ESC &nbsp;0x1B &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* ESCAPE character code &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br /><br />bit &nbsp; escape; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* flag: mark ESCAPE character entered &nbsp;*/<br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;Task 6 'get_escape': check if ESC (escape character) was entered &nbsp; &nbsp;*/<br />/******************************************************************************/<br />void get_escape &#40;void&#41; _task_ GET_ESC &nbsp;&#123;<br />&nbsp; while &#40;1&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* endless loop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; if &#40;_getkey &#40;&#41; == ESC&#41; &nbsp;escape = 1; &nbsp; &nbsp; &nbsp; &nbsp;/* set flag if ESC entered &nbsp; &nbsp; */<br />&nbsp; &nbsp; if &#40;escape&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* if escape flag send signal &nbsp;*/<br />&nbsp; &nbsp; &nbsp; os_send_signal &#40;COMMAND&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* to task 'command' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &#125;<br />&nbsp; &#125;<br />&#125;<br /><br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;Task 1 'command': command processor */<br />/******************************************************************************/<br />void command &#40;void&#41; _task_ COMMAND &nbsp;&#123;<br />&nbsp; unsigned char i;<br /><br />&nbsp; printf &#40;menu&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* display command menu &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; while &#40;1&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* endless loop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; printf &#40;"\nCommand: "&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* display prompt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; getline &#40;&inline, sizeof &#40;inline&#41;&#41;; &nbsp; &nbsp; &nbsp; &nbsp;/* get command line input &nbsp; &nbsp; &nbsp;*/<br /><br />&nbsp; &nbsp; for &#40;i = 0; inline&#91;i&#93; != 0; i++&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp;/* convert to uppercase &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; inline&#91;i&#93; = toupper&#40;inline&#91;i&#93;&#41;;<br />&nbsp; &nbsp; &#125;<br /><br />&nbsp; &nbsp; for &#40;i = 0; inline&#91;i&#93; == ' '; i++&#41;; &nbsp; &nbsp; &nbsp; &nbsp;/* skip blanks &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br /><br />&nbsp; &nbsp; switch &#40;inline&#91;i&#93;&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* proceed to command function */<br />&nbsp; &nbsp; &nbsp; case 'D': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Display Time Command &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; printf &#40;"Start Time: %02bd:%02bd:%02bd &nbsp; &nbsp;"<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "End Time: %02bd:%02bd:%02bd\n",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;start.hour, start.min, start.sec,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end.hour, &nbsp; end.min, &nbsp; end.sec&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; printf &#40;" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type ESC to abort\r"&#41;;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; os_create_task &#40;GET_ESC&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* ESC check in display loop &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; escape = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* clear escape flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; display_time = 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* set display time flag &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; os_clear_signal &#40;COMMAND&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* clear pending signals &nbsp; &nbsp; &nbsp; */<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; while &#40;!escape&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* while no ESC entered &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf &#40;"Clock Time: %02bd:%02bd:%02bd\r", &nbsp; &nbsp; &nbsp;/* display time &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ctime.hour, ctime.min, ctime.sec&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os_wait &#40;K_SIG, 0, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for time change or ESC */<br />&nbsp; &nbsp; &nbsp; &nbsp; &#125;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; os_delete_task &#40;GET_ESC&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* ESC check not longer needed */<br />&nbsp; &nbsp; &nbsp; &nbsp; display_time = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* clear display time flag &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; printf &#40;"\n\n"&#41;;<br />&nbsp; &nbsp; &nbsp; &nbsp; break;<br /><br />&nbsp; &nbsp; &nbsp; case 'T': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Set Time Command &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; if &#40;readtime &#40;&inline&#91;i+1&#93;&#41;&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp;/* read time input and &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctime.hour = rtime.hour; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* store in 'ctime' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctime.min &nbsp;= rtime.min;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctime.sec &nbsp;= rtime.sec;<br />&nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; &nbsp; &nbsp; break;<br /><br />&nbsp; &nbsp; &nbsp; case 'E': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Set End Time Command &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; if &#40;readtime &#40;&inline&#91;i+1&#93;&#41;&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp;/* read time input and &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end.hour = rtime.hour; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* store in 'end' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end.min &nbsp;= rtime.min;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end.sec &nbsp;= rtime.sec;<br />&nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; &nbsp; &nbsp; break;<br /><br />&nbsp; &nbsp; &nbsp; case 'S': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Set Start Time Command */<br />&nbsp; &nbsp; &nbsp; &nbsp; if &#40;readtime &#40;&inline&#91;i+1&#93;&#41;&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp;/* read time input and &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; start.hour = rtime.hour; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* store in 'start' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; start.min &nbsp;= rtime.min;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; start.sec &nbsp;= rtime.sec;<br />&nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; &nbsp; &nbsp; break;<br /><br />&nbsp; &nbsp; &nbsp; default: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Error Handling &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; printf &#40;menu&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* display command menu &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &#125; &nbsp;<br />&nbsp; &#125;<br />&#125;<br /><br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;signalon: check if clock time is between start and end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />/******************************************************************************/<br />bit signalon &#40;void&#41; &nbsp; &#123;<br />&nbsp; if &#40;memcmp &#40;&start, &end, sizeof &#40;struct time&#41;&#41; &lt; 0&#41; &nbsp;&#123;<br />&nbsp; &nbsp; if &#40;memcmp &#40;&start, &ctime, sizeof &#40;struct time&#41;&#41; &lt; 0 &nbsp;&&<br />&nbsp; &nbsp; &nbsp; &nbsp; memcmp &#40;&ctime, &end, &nbsp; sizeof &#40;struct time&#41;&#41; &lt; 0&#41; &nbsp;return &#40;1&#41;;<br />&nbsp; &#125;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; else &nbsp;&#123;<br />&nbsp; &nbsp; if &#40;memcmp &#40;&end, &nbsp; &ctime, sizeof &#40;start&#41;&#41; > 0 &nbsp;&&<br />&nbsp; &nbsp; &nbsp; &nbsp; memcmp &#40;&ctime, &start, sizeof &#40;start&#41;&#41; > 0&#41; &nbsp;return &#40;1&#41;;<br />&nbsp; &#125;<br />&nbsp; return &#40;0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* signal off, blinking on &nbsp; &nbsp; */<br />&#125;<br /><br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;Task 3 'blinking': runs if current time is outside start &amp; end time */<br />/******************************************************************************/<br />void blinking &#40;void&#41; _task_ BLINKING &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp;/* blink yellow light &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; red &nbsp; &nbsp;= 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* all lights off &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; yellow = 0;<br />&nbsp; green &nbsp;= 0;<br />&nbsp; stop &nbsp; = 0;<br />&nbsp; walk &nbsp; = 0;<br /><br />&nbsp; while &#40;1&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* endless loop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; yellow = 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* yellow light on &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 150, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 150 ticks &nbsp;*/<br />&nbsp; &nbsp; yellow = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* yellow light off &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 150, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 150 ticks &nbsp;*/<br />&nbsp; &nbsp; if &#40;signalon &#40;&#41;&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* if blinking time over &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &nbsp; os_create_task &#40;LIGHTS&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* start lights &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; os_delete_task &#40;BLINKING&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* and stop blinking &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &#125;<br />&nbsp; &#125;<br />&#125;<br /><br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp;Task 4 'lights': executes if current time is between start &amp; end time */<br />/******************************************************************************/<br />void lights &#40;void&#41; _task_ LIGHTS &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* traffic light operation &nbsp; &nbsp; */<br />&nbsp; red &nbsp; &nbsp;= 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* red &amp; stop lights on &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; yellow = 0;<br />&nbsp; green &nbsp;= 0;<br />&nbsp; stop &nbsp; = 1;<br />&nbsp; walk &nbsp; = 0;<br />&nbsp; while &#40;1&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* endless loop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 150, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 150 ticks */<br />&nbsp; &nbsp; if &#40;!signalon &#40;&#41;&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* if traffic signal time over */<br />&nbsp; &nbsp; &nbsp; os_create_task &#40;BLINKING&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* start blinking &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; os_delete_task &#40;LIGHTS&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* stop lights &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />&nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; yellow = 1;<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 150, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 150 ticks */<br />&nbsp; &nbsp; red &nbsp; &nbsp;= 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* green light for cars &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; yellow = 0;<br />&nbsp; &nbsp; green &nbsp;= 1;<br />&nbsp; &nbsp; os_clear_signal &#40;LIGHTS&#41;;<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 200, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 200 ticks */<br />&nbsp; &nbsp; os_wait &#40;K_TMO + K_SIG, 250, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout &amp; signal &nbsp; */<br />&nbsp; &nbsp; yellow = 1;<br />&nbsp; &nbsp; green &nbsp;= 0;<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 150, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 150 ticks */<br />&nbsp; &nbsp; red &nbsp; &nbsp;= 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* red light for cars &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; yellow = 0;<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 150, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 150 ticks */<br />&nbsp; &nbsp; stop &nbsp; = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* green light for walkers &nbsp; &nbsp; */ &nbsp; &nbsp;<br />&nbsp; &nbsp; walk &nbsp; = 1;<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 250, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 250 ticks */<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 250, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 250 ticks */<br />&nbsp; &nbsp; stop &nbsp; = 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* red light for walkers &nbsp; &nbsp; &nbsp; */ &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; walk &nbsp; = 0;<br />&nbsp; &#125;<br />&#125;<br /><br /><br />/******************************************************************************/<br />/* &nbsp; &nbsp; &nbsp; &nbsp;Task 5 'keyread': process key stroke from pedestrian push button &nbsp; &nbsp;*/<br />/******************************************************************************/<br />void keyread &#40;void&#41; _task_ KEYREAD &nbsp;&#123;<br />&nbsp; while &#40;1&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* endless loop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; if &#40;key&#41; &nbsp;&#123; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* if key pressed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />&nbsp; &nbsp; &nbsp; os_send_signal &#40;LIGHTS&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* send signal to task lights &nbsp;*/<br />&nbsp; &nbsp; &#125;<br />&nbsp; &nbsp; os_wait &#40;K_TMO, 2, 0&#41;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* wait for timeout: 2 ticks &nbsp; */<br />&nbsp; &#125;<br />&#125;<br />&nbsp;</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>@CazeShyam's method is elegant and the correct way to go.But you could also use the 8051's 2 timers and 8 external timers(2xLM558) to control all 10 devices.The micro would poll 10 input pins continuously and trigger the timers whenever it detects an input.Would,by any chance, a device already triggered and yet to complete it's 10s,get another input signal?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>i feel its no more a challenge if we used external analog timers, in such case we don't need the micro at all because the input signals can trigger the timers which are hard wired (RC network) for 10 sec delay.  the Job can be done without using external timers and using only one internal timer of 8051. after a lot of thought process i have come up with the following approach:1) wire 10 pins on micro as inputs 2) load timer0 with 50 milliSec values and start timer03) wire  External interrupt(EX0) pin to all the 10 inputs with help of diodes in such a way that when any of the 10 inputs are received the EX0 pin along with the input pin/s is brought low( logic 0).4) in the External Int. ISR check which pin/s are grounded and set a flag/s for that particular input pin/s and give output/s (start the device/s)5) in the timer0 ISR  declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s  and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s6) even when some devices are running and some other new device/s is triggered the counter for that particular new device is also incremented along with the old running ones7) all the checking and control is done in ISRs of External int.0 and timer int.08) time required for overhead instructions may cause slight delay and therefore normal 12 cycle 8051 clocked @ 12Mhz or 24 Mhz should be avoided for tasks like theses one should use the world's fastest 8051 " DS89C450" clocked at 24Mhz which is 10 times faster than normal 8051 and each instruction takes 40-45 nanosecs and task can be completed with near accuracy.9) if both the Ex0 interrupt and 50mSec timer int. occur at the same time,by default  first the EX0 is serviced followed by timer int.10) the tick time of 50 msec can be reduced  to say 20msec but to get 10 sec delay we would require to count 500 interrupts but the 8 bit counter can count max upto 255Dif interested i can write the code in asm and post it here.Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>Arun Kumar V wrote ...3) wire External interrupt(EX0) pin to all the 10 inputs with help of diodes in such a way that when any of the 10 inputs are received the EX0 pin along with the input pin/s is brought low( logic 0).ORing the inputs will be better</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>sashijoseph</dc:creator>
						<dc:subject></dc:subject>
						<description>^^but then which of the 10 inputs caused the interrupt wouldn't be traceable.I think that's why Arun has ORed the inputs to the INT pin(with diodes) and simultaneously used parallel IO for tracing the source of the interrupt.Very thoughtful Arun.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>pdi33</dc:creator>
						<dc:subject></dc:subject>
						<description>I think that is a near perfect solution for the problem i woud say by arun.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>caze</dc:creator>
						<dc:subject></dc:subject>
						<description>hi @ arun ,                   thanks a lot .......                  and ill be so thankful to u if u can post asm program here .</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>Sorry for late reply, was on a short trip.Thank you SJ and Pdi33 !caze -  i'll post the asm code and schematic  today Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>hello caze,as promised here's my code and schematic, i have written for 8 I/Os your task is to further increase it to 10 I/Os (its easy after you go thru the code)  -  Enjoy !: code deleted by Aruni have simulated and tested the code using Ds89C430 and it works well !Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>wow!  how bout starting programming competetions?I am not sure how good it will be.. but its gonna be fun..</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>Sure, Why not ?............... Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>pdi33</dc:creator>
						<dc:subject></dc:subject>
						<description>nice idea ajay,   would really tickle our old grey cells..   and help a few newcomers in many ways.when do we start?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>shyam</dc:creator>
						<dc:subject></dc:subject>
						<description>every competition needs a judge...i believe we can help each other out.. for sure...but to judge who is better wud not be that easy</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>pdi33</dc:creator>
						<dc:subject></dc:subject>
						<description>wisely said shyam.    hmmm, too many offtopic posts here i think.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Ajay</dc:creator>
						<dc:subject></dc:subject>
						<description>Well..I have answer to that too  Competitions will go like this..1. Problem will be post on forum and entries will be accepted till a fixed date2. After entries are received, A new thread will be created3. all entries will be displayed and we will have voting on the basis of logic/code efficiency4. After voting date is over. We will have our winner  >> We have to promise ourself to vote for the best</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>pdi33</dc:creator>
						<dc:subject></dc:subject>
						<description>that would be nice. but will it cover all possible forum topics ? AVR/8051/PIC/VB. i.e. will there be individual probems posted for each forum heading?.anyways, looks very promising and attractive.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>ijatorzaty</dc:creator>
						<dc:subject></dc:subject>
						<description>Arun Kumar V wrote ...hello caze,as promised here's my code and schematic, i have written for 8 I/Os your task is to further increase it to 10 I/Os (its easy after you go thru the code)  -  Enjoy !: code deleted by Aruni have simulated and tested the code using Ds89C430 and it works well !Arun stated at the above of the diagram, u've posted code, but where is it? could u repost it, once again...so, it could be my reference for my assignment, i hope u'll consider my request...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>pdi33</dc:creator>
						<dc:subject></dc:subject>
						<description>@izator..,as u can see, arun has posted the most important part of ur assignment which is the principle of operation and hardware which is more than half of ur assignment done. i would assume that writing the code for the above hardware should be quite simple for u if u have really understood the principle explained in the previous posts of this thread.I am in perfect acceptance of aruns decision to delete the code as the same assignment seems to have been given to most of the members of this forum from ur place and it would be unfair (especially to ur faculty who gave u people this assignment)  if most of ur collegues  just download the code and complete the assignment without really understanding the concept( which is why u were given the assignemnt in the first place, right?).So i would advice u on starting on something and then we can always suggest/comment on it.good luck</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>10) the tick time of 50 msec can be reduced to say 20msec but to get 10 sec delay we would require to count 500 interrupts but the 8 bit counter can count max upto 255Di need 30 seconds delay which is 600D but the max is 255Dso how do i get 30 secs? by setting tick time higher than 50msec? Biggest is 60+msec?but still cannot get a total of 30seconds.pls teach me how to get 30 secs...Edit: Just think of an idea of making 2 loops, but the exact coding still not sure about it...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>pdi33</dc:creator>
						<dc:subject></dc:subject>
						<description>well u thought of it right. but to generate a 30seconds tick (that is a very long time ), u may have to change the timer mode to 16 bits ( two bytes)  and further add a two byte counter in the overflow interrupt. 30 seconds = 30,000,000 uS. == total 4 byte counter.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>Arun Kumar V wrote ...hello caze,as promised here's my code and schematic, i have written for 8 I/Os your task is to further increase it to 10 I/Os (its easy after you go thru the code)  -  Enjoy !: code deleted by Aruni have simulated and tested the code using Ds89C430 and it works well !Arunanother noob question here, hope u all dun mind...by comparing Arun's schematic n Junied's schematic (http://rapidshare.de/files/40330614/imp_scheme.pdf.html)Arun's connect those buttons to P3.2(INT0) which Junied did not.I know it is for interrupt purpose, but i not really clear about tis part.Is it we must use interrupts to implemented tis functions? Is there any others way?For example, below is a sample code i search thru the internet, it can poll between 2 inputs and countdown 10 secs but it does not uses interrupts. Is tis code correct?(If you pressed switch A, and your program goes into a delay loop to give you the 10 sec delay, then switch B will not be polled, and therefore has no effect while the system is waiting for this 10 sec delay to complete.The program below should give you some idea. It is not debugged, but the idea is there.The two switches have to be polled regularly. Let the timer runs freely and overflow every 50 ms. If switch A is pressed, initialise the value of R1 to 200. Decrement R1 everytime the timer overflow. After 200 overflow (200 x 50ms = 10 s), R1 becomes zero, and the program turn off LED A. LED B is separately controlled by the value in R2.MOV TMOD,#10H ; CONFIGURE TIMER 1MOV TH1,#3CH ; ASSUME 12 MHZ CRYSTALMOV TL1,#B0H ; TIMER TAKES 50MS TO OVERFLOWSETB TR1 ; START TIMER 1POLL: ; POLL FOR THE SWITCHESJNB P1.0,AA1 ; JUMP IF SWITCH A IS PRESSEDJNB P1.1,BB1 ; JUMP IF SWITCH B IS PRESSEDPOLL2:JNB TF1,POLL ; TIMER NOT OVERFLOW YET, CONTINUE TO POLLCLR TF1MOV TH1,#3CHMOV TL1,#B0HCJNE R1,#0,CNTDOWN_ASETB P3.0 ; OFF LED ACJNE R2,#0,CNTDOWN_BSETB P3.1 ; OFF LED BSJMP POLLAA1:MOV R1,#200D ; START TIMINGCLR P3.0 ; ON LED ASJMP POLL2BB1:MOV R2,#200DCLR P3.1 ; ON LED BSJMP POLL2CNTDOWN_A:DEC R1SJMP POLLCNTDOWN_B:DEC R2SJMP POLL)</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>pdi33 wrote ...well u thought of it right. but to generate a 30seconds tick (that is a very long time ), u may have to change the timer mode to 16 bits ( two bytes)  and further add a two byte counter in the overflow interrupt. 30 seconds = 30,000,000 uS. == total 4 byte counter.I do not understand "and further add a two byte counter in the overflow interrupt. 30 seconds = 30,000,000 uS. == total 4 byte counter." Wat u mean by overflow interrupt? add 2 byte counter?By setting timer mode to 16bits(TMOD,#10H) blah blah blah i get 50mS each cycle.den i MOV R1,#200 to get 10secs. I cant MOV R1,#600 to get 30secs becoz the max is 255 only.Can i do like tis? Like creating delay for multiplexing?LOOP1: MOV R1,#200LOOP2: MOV R2,#3    ;200*3=600 =) LOOP3: DJNZ R1,$             DJNZ R2,LOOP2p/s: becoz on the other thread Arun said tis "3) once Key is detected, particular LED is Lit and timer1 is loaded for 30sec delay( 50mS X 20d = 1000mS or 1 Sec, for 30 sec increment a Register 30 times) after the delay the led is switched off."</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/show to do tis part?already confuse between timer n counter, somore declare counters in timer0 ISR.totally blur...</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>Hello   Mr.shabiul,i feel you are trying to do too many things at the same time, pl. follow a step by step approach. the solution i offered here is for this particular Challenge, so the connecting of Int0 pin with other input port pins works in this context and you don't have to connect it this way always in your other circuits.now about the timer delay.You have to use timer ISR ( interrupt Service Rotuine). in Data seg ( i,e RAM) define variables by some name like count_1......count_10 and also 10 flags by name like Flag_1.....Flag_10  and now read the algorithm carefully (point no.5):5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s and now for 30 sec delay question.first make a delay for 1 Sec and then use this 1 sec delay as basic tick  to get multiple seconds/mins/hrs/days delay, here's a code snippet :CODE:MAIN:<br />MOV TMOD,#01H &nbsp;; TIMER 0 MODE 1<br />MOV &nbsp;TL0,#0B0H&nbsp; &nbsp;;Lower Byte &nbsp; ; 50 mS DELAY VALUES ( 12 Mhz XTAL)<br />MOV &nbsp;TH0,#03CH&nbsp; ;Upper Byte<br />MOV R1,#20D &nbsp; &nbsp; &nbsp; ; COUNTER FOR 1 SEC<br />MOV R2,#30D &nbsp; &nbsp; &nbsp; ; COUNTER FOR 30 SECS<br />SET &nbsp; TR0&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ;Run timer<br /><br />CLR LED &nbsp; &nbsp; &nbsp; &nbsp;; LED IS ON<br />SJMP $<br /><br /><br />;TIMER0 ISR<br /><br />CLR TR0<br />DJNZ R1,CONTINUE<br />MOV R1,#20D &nbsp; ; RELOAD COUNTERS FOR NEXT CYCLE<br />DJNZ R2,CONTINUE<br />SETB &nbsp;LED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; AFTER COMPLETION OF &nbsp;30 SEC DELAY OFF THE LED<br />MOV R2,#30D &nbsp; ; RELOAD COUNTERS FOR NEXT CYCLE<br />&nbsp;<br />CONTINUE:<br />MOV &nbsp;TL0,#0B0H&nbsp; &nbsp;;Lower Byte &nbsp; ; 50 mS DELAY VALUES ( 12 Mhz XTAL)<br />MOV &nbsp;TH0,#03CH&nbsp; ;Upper Byte<br />SETB TR0<br /><br />RETIArun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>Arun Kumar V wrote ...Hello   Mr.shabiul,i feel you are trying to do too many things at the same time, pl. follow a step by step approach. the solution i offered here is for this particular Challenge, so the connecting of Int0 pin with other input port pins works in this context and you don't have to connect it this way always in your other circuits.now about the timer delay. you have to use timer ISR ( interrupt Service Rotuine). in Data seg ( i,e RAM) define variables by some name like count_1......count_10 and also 10 flags by name like Flag_1.....Flag_10  and now read the algorithm carefully (point no.5):5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/sArunit is because my project also require 4 inputs which your solution offer 10 inputs, i guess it is the same thing right? So do I need to connect those 4 inputs to INT0?by the way, i had read ur algorithm very carefully,but i m still not quite clear about it.(well, i m just a new learner to assembly coding)5) in the timer0 ISR declare 10 counters (use registers/variables) check[/color] which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti May you explain tis part further?Hope to hear from u soon</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>How to define others variables rather than R0-R7 in register banks 0and without using register banks 1becoz changing register banks looks complicated...and my R0-R7 in register banks 0 is fully occupied...For exampleFLAG1: DS 1den in main program MOV FLAG1,#01H tis giv segment type mismatch in my complilerwat is the problem?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>Shabiul, may be you are forgetting the 256 bytes RAM on board 8052, declare Variables in RAM and In Assembly this is how it can be done: DSEG    ORG 0020HCOUNTER_1: DS 1COUNTER_2: DS 1and for FLAGSFLAG_1 BIT 1FLAG_2 BIT 1...................................Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>why is FLAG_1 BIT 1 while COUNTER_1: DS 1?by the way, there is alot questions in the previous posts tat you din answer me...regarding checking the flag, THE FLAG is just normal variable or interrupt FLAG?</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>shabiul, you have  edited your previous post after my reply ( see the time stamp, i replied at 11.15 pm and you modified your last reply after reading my answer at 11.21pm)don't repeat this sought of thing.now about your problem, bit and DS, before i clear your doubt can you tell me the difference between Port1 and Port pin 1.0i can proceed only when you answer my above question Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>i edit my post just because i got new question and i dun wan to double post.about ur question, Port1 means the whole port1.0-1.7, port pin 1.0 means only the pin.correct me if wrong.by the way i mean u did not answer my previous 2-3 posts but not the last post.</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Arun Kumar V</dc:creator>
						<dc:subject></dc:subject>
						<description>about ur question, Port1 means the whole port1.0-1.7, port pin 1.0 means only the pin.correct me if wrong.other way of putting it would be, port1.0 is a bit of port1 and port1 is a 8bit port. so port1 (or any 8 bit port ) can be called as a register which is both Bit &amp; byte addressable (i,e you can write or read a single port bit or full 8 bit register).why is FLAG_1 BIT 1 while COUNTER_1: DS 1?when you declare  a variable in RAM area, you have to specify to compiler the size of that variable,for eg:COUNTER_1: DS 1   ; means the variable counter_1 is one byte wide ( like a  8 bit register)and  now declaring a flag,FLAG_1 BIT 1   ;   flag_1 is a single bit  and not whole 8 bit Register.now data moves with byte wide Variable and bit flag:to write/read a 8 bit variable:MOV COUNTER_1,#0FFH   ;  move value 255d to counter_1MOV A,COUNTER_1            ; read value of Counter_1 to AccuFLAG1: DS 1den in main programMOV FLAG1,#01Htis giv segment type mismatch in my complilerwat is the problem? now with Bit :how would you turn On or Turn Off a port bit ?SETB P1.1CLR P1.1same way you can Set or clear a bit Flag:SETB FLAG_1CLR FLAG_1but cannot use byte instructions with single bit variable/flagMOV FLAG_1,#0FFH   ; is wrong and gives Error it is like writing :MOV P1.1,#0FFH    ; which is like writing 8 bit value to a single port pin (bit), this is called " illegal syntax " by the compiler/assemblerFlag/s are used to indicate only two states  i,e  1 or 0  ( a light is ON or OFF)Variable is used to store data/value which often changes or varies  ( Seconds Variable of a Clock) Arun</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>nischay kumar</dc:creator>
						<dc:subject></dc:subject>
						<description>@ Mr.shabiul,I Bet even your College Professor wouldn't have explained the whole concept with such clarity as Arun did.so the least you can do is " Thank "  Arun and other moderators who are taking pain in explaining the concepts from root level.the college professors are "paid "to solve your problems but they do not do that ( if they did, you wouldn't be asking for help in forums)on the other hand Moderators here are doing Free social service by sharing their knowledge. i should say you folks (your fellow country men) are Lucky to be members of this forum, because other forums Like popular 8052.com would not entertain assignments and home works ( they straight away lock/delete your posts) so thank God and thank the Mods by pressing the "Thanks button"</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>Ya, i know moderators here are very nice and willing to help, tats why i stick to here.I keep refresh the page to see if they had replied me or not, becoz i m desperate &amp; my project is running out of time. Maybe i had ask too much question and i did not speak in proper manner, but i really appreciate their help. the college professors are "paid "to solve your problems but they do not do that ( if they did, you wouldn't be asking for help in forums) maybe they did,maybe they did not,its not for me to comment about it. Well maybe the problem is with myself... i m just not good in programming.and the text book has too little example to refer</description>
						</item>
						<item rdf:about="http://www.8051projects.net/forum-t10431.html">
						<title>Re: IO PORT PROGRAMING CHALANGE</title>
						<link>http://www.8051projects.net/forum-t10431.html</link>
						<dc:date>2009-01-07T13:05:22-08:00</dc:date>
						<dc:creator>Mr.Shabiul</dc:creator>
						<dc:subject></dc:subject>
						<description>@Arunthanks, u explained very well n clear. I wonder why i just dun understand such a simple thing be4....anyway,I m still stuck in tis part 5) n 6)5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s6) even when some devices are running and some other new device/s is triggered the counter for that particular new device is also incremented along with the old running oneHow to fullfill part6 conditions? just by doing the code in part5 will do?can i do like tis for part 5?below is sample timer ISR for 2 switches &amp; flag1 flag2 already SETB in external INT.T1_ISR:	PUSH ACC	PUSH PSW	MOV A,FLAG1	CJNE A,#01H,COUNTER1	CLR TR1	DJNZ R5,CONTINUE	MOV R5,#20D   		DJNZ R6,CONTINUE	SETB  LED1      	MOV R6,#30D   	 	CLR FLAG1	;	COUNTER1:	MOV A,FLAG2	CJNE A,#01H,RETURN	CLR TR1	DJNZ R5,CONTINUE	MOV R5,#20D   	 	DJNZ R6,CONTINUE	SETB  LED2       	MOV R6,#30D   	  	CLR FLAG2RETURN:       POP PSW       POP ACCCONTINUE:        MOV  TL1,#0B0H  ;Lower Byte   ; 50 mS DELAY VALUES ( 12 Mhz XTAL)	MOV  TH1,#03CH  ;Upper Byte	SETB TR1	RETIINT0_ISR:...RETI</description>
						</item>
				</rdf:RDF>