C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 6th, 2013, 11:37 PM
swapan swapan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 5 swapan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 52 sec
Reputation Power: 0
A very novice question from newbie

Friends,

I am a new member in this forum. I am an electronics hobbyist and presently working with hobby projects based on microcontroller. I have already completed some projects for which source code has been developed through assembly language. Now I am trying to enter into the world of higher language like C. A sample source code is given below. in the code two "while" loops are there. Please let me know if condition of first "while" loop is satisfied / not satisfied, where control will pass to. So far I know "while (1)" is an infinite loop. In this code which portion will be repeated indefinitely?

regards

swapan


Code:
void main() { 
SET_FREQ = 410; TBL_POINTER_SHIFT = 0; TBL_POINTER_NEW = 0; 
TBL_POINTER_OLD = 0; 
DUTY_CYCLE = 0; ANSEL = 0; //Disable ADC 
CMCON0 = 7; //Disable Comparator 
TRISC = 0x3F; 
CCP1CON = 0x4C; 
TMR2IF_bit = 0; 
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1 
while (TMR2IF_bit == 0); // This is the first loop.
TMR2IF_bit = 0; 
TRISC = 0; 
TMR2IE_bit = 1; 
GIE_bit = 1; 
PEIE_bit = 1; 
while(1); 
}

Reply With Quote
  #2  
Old March 7th, 2013, 07:40 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,814 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 7 h 54 m 5 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
In this case, both loop will be infinite. In the first loop, you have the variable already set to 0, so as long as that's true, the loop will run. If the value changes, then control will pass to the next line.

Reply With Quote
  #3  
Old March 7th, 2013, 08:37 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
If you declared variables in the most straightforward way to have the code compile, it would iterate forever at

while (TMR2IF_bit == 0); // This is the first loop.

because the statement body is empty.

I suppose TMR2IF_bit could have extern linkage and volatile quality. As such an external event would let the program continue through to the second loop which runs forever. I'd write the last loop as
while(1) sleep(9999);
to conserve electrons. If you can't save electrons, no one can.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > A very novice question from newbie

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap