<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>problem with loop counter</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/19295/problem-with-loop-counter</link><description> I have just switched to KEIL from SDCC (it just wouldn&amp;#39;t do what I needed!). I have a startup loop that allows some sleep time while some outboard sensors warm up. While they are doing this, I&amp;#39;m in a loop, printing &amp;quot;.&amp;quot;&amp;#39;s to the uart: 
 
 
Byte i = 0;</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/144086?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2005 04:56:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d3d12aa2-d07e-4021-8dff-2424c4c1e4f3</guid><dc:creator>Ulf Sa&amp;#195;Ÿ</dc:creator><description>&lt;p&gt;You stated that you use timer0 interrupt for your delay. Are you sure, that your program is waiting inside delay() and continues &lt;b&gt;after&lt;/b&gt; the interrupt occures?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/144087?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2005 04:43:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ee5dca70-ba04-422d-b4e1-592dabc7eac0</guid><dc:creator>John Donaldson</dc:creator><description>&lt;p&gt;&amp;quot;I&amp;#39;ll be glad to post the .lst files if it helps.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Yes, I&amp;#39;d be interested. If you&amp;#39;re using the LX51 linker you can generate a .cod file which would be even more useful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/141560?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 11:21:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b1e1e248-13c8-42ad-94c8-9c02155db8cc</guid><dc:creator>Nik Martin</dc:creator><description>&lt;p&gt;Is there something I could post that would clear up what problem I was having?  My ASM skills are extremely limited, so I made an assumption based on what I saw, and moving the uart interrupt routine over to register bank 2 fixed it.&lt;br /&gt;
&lt;br /&gt;
I&amp;#39;ll be glad to post the .lst files if it helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/138116?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 11:07:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:655cd7f0-f26b-4071-88db-0adc36be2204</guid><dc:creator>John Donaldson</dc:creator><description>&lt;p&gt;&amp;quot;No, no routines had using in the declaration, but I assumed that because of that, they all automatically used bank 0.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Yes, they do, but an ISR that uses bank zero by default will restore the content of any registers it trashes. I&amp;#39;m trying to understand why specifying &amp;#39;using 2&amp;#39; has fixed your problem, or rather, I&amp;#39;m trying to understand why you had the problem in the first place.&lt;br /&gt;
&lt;br /&gt;
The &amp;#39;using&amp;#39; directive tells a function not only to use a specific register bank but also that it doesn&amp;#39;t need to preserve the contents of the registers in that bank.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/134665?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 10:24:03 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3bb3069f-3d03-4845-834b-b270f3b168f6</guid><dc:creator>Nik Martin</dc:creator><description>&lt;p&gt;No, no routines had &lt;i&gt;using&lt;/i&gt; in the declaration, but I assumed that because of that, they all automatically used bank 0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/122978?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 10:12:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7cb46e47-5a6c-48a3-9bf6-22ac4ef61a0a</guid><dc:creator>John Donaldson</dc:creator><description>&lt;p&gt;&amp;quot;Moving the UART&amp;#39;s ISR to register bank 2 solved the problem.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Did you originally declare the ISR with &amp;#39;using 0&amp;#39;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/138115?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 09:26:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:664ad5fe-b310-4388-824c-4790d937e89d</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;a general statement on register banks:&lt;br /&gt;
My method (that works) is&lt;br /&gt;
main at RB0&lt;br /&gt;
low IP priority interrupts at RB1&lt;br /&gt;
high IP priority interrupts at RB2&lt;br /&gt;
on derivatives with more than 2 IP priorities (e.g. Philips Rx2), I only use one more which is the highest and uses RB3.&lt;br /&gt;
also NO subroutine is used at more than one level.&lt;br /&gt;
&lt;br /&gt;
There is no reason, whatsoever, to use different RBs for interrupts at the same IP priority.&lt;br /&gt;
&lt;br /&gt;
Erik&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;IP priority:&lt;/b&gt; priority as define by the IP (and extensions) SFR(s).  NOT the priority of concurrent ints, that is irrelevant in this respect.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/134664?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 08:48:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6b4ffb60-d897-446e-a1cc-8c9908ccefd8</guid><dc:creator>Nik Martin</dc:creator><description>&lt;p&gt;Yeah, my terminology is probably off, but i is pushed onto some register r(something or other), and then something else is put there in the uart_isr, overwriting the loop counter&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/122977?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 08:41:47 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:177c6aa6-61ec-46cd-9a3a-99e62c9a43ef</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;i&gt;No, the problem was with the UART ISR overwriting the &lt;b&gt;accumulator&lt;/b&gt;, which is where th eloop counter is. Moving the UART&amp;#39;s ISR to &lt;b&gt;register bank&lt;/b&gt; 2 solved the problem&lt;/i&gt;&lt;br /&gt;
HUH?&lt;br /&gt;
there is no accumulator in the register banks.&lt;br /&gt;
&lt;br /&gt;
Erik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/111709?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 08:28:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:079bd382-3140-4f0d-ad57-8846262c1617</guid><dc:creator>Nik Martin</dc:creator><description>&lt;p&gt;No, the problem was with the UART ISR overwriting the accumulator, which is where th eloop counter is.  Moving the UART&amp;#39;s ISR to register bank 2 solved the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/97532?ContentTypeID=1</link><pubDate>Wed, 05 Oct 2005 01:02:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0a4d2abf-7787-4bbd-ad68-d46f41cd7d82</guid><dc:creator>Ulf Sa&amp;#195;Ÿ</dc:creator><description>&lt;p&gt;As I understand you should better poll the timer interrupt flag.&lt;br /&gt;
In your code the delay() probably enables the interrupt but the program continues immediatly and the loop is running.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/73529?ContentTypeID=1</link><pubDate>Tue, 04 Oct 2005 12:38:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:31f443eb-43ac-4c81-b9c8-ce482adad4f1</guid><dc:creator>Nik Martin</dc:creator><description>&lt;p&gt;Well, I use a uart, but was not using specific register banks to store stuff in.  The printf(&amp;quot;.&amp;quot;) was mashing up my variable in the register.  Adding &amp;#39;using 2&amp;#39; to my uart_isr routine fixed me right up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with loop counter</title><link>https://community.arm.com/thread/44786?ContentTypeID=1</link><pubDate>Tue, 04 Oct 2005 12:15:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:80cb11ca-b59d-46e3-83c6-df6a9447cb06</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;i&gt;Any reason why i is 231 (vs. 2) when &lt;b&gt;delay()&lt;/b&gt; returns the first time through the loop?&lt;/i&gt;&lt;br /&gt;
sounds like you check a local variable outside its scope.&lt;br /&gt;
&lt;br /&gt;
Erik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>