C language coding style

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,492
Which type of code should in the main body or outside main body anybody know?
 

Which type of code should in the main body or outside main body anybody know?
Before main loop initializations take place, together with one shot actions during reset time. After that comes the main loop, where tasks are repeated over and over again. If for example you have a program that measures analog port and drives a LED according to the measured ADC value, then you would have a pseudocode as follows:

Code:
void main (void)
{
  unsigned int anValue;
  MakeLedPinOutput();  //initialize LED port pin
  InitializeADC();  //Initialize analog port

  while(1)
  {
    anValue = MeasureAnalogPort();  //get analog value
    ControlLed(anValue);  //drive LED accordingly
  }
}


Hope this helps.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…