Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] can any understand this code

Status
Not open for further replies.

Mohamed Slama

Member level 4
Member level 4
Joined
Nov 8, 2013
Messages
72
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
443
hello everybody

this code is a part of frequency counter code but i cant under stand these

lines (if (--tmr0_cnt==0)) and tmr0_cnt==0 initialized by 100

Code:
void interrupt()
{

 if(intcon.f2==1) //if timer0 is overlfowed
 {
   if(--tmr0_cnt==100) //decrement and check tmr0_cnt until zer0 which means a second
   {
     intcon.f7=0; t1con.f0=0;  //stop counting and global interrupts
     flag=1;  //set flag
   }
   intcon.f2=0; //reset timer0 flag
   tmr0=98;  //Timer0 starts counting from 98 again
 }

 if(pir1.f0==1) //if timer1 is overlfowed
 {
   OverNumb++;  //increment number of overflow
   pir1.f0=0; //reset timer1 flag
 }

}
 

It means pre decrement the value of tmr0_cnt whenever a timer0 interrupt occurs and check if it is equal to value 100. The initial value of tmr0_cnt should be > 100 so that on first interrupt it gets decremented to 100 if it was 101 previously and then the if() condition becomes true.
 

but when i write :

if (--tmr0_cnt==14) as example

compiler (microC) will equal tmr0 by 14 from the first time ??

- - - Updated - - -

corrected code is
Code:
void interrupt()
{
 
 if(intcon.f2==1) //if timer0 is overlfowed
 {
   if(--tmr0_cnt==0) //decrement and check tmr0_cnt until zer0 which means a second
   {
     intcon.f7=0; t1con.f0=0;  //stop counting and global interrupts
     flag=1;  //set flag
   }
   intcon.f2=0; //reset timer0 flag
   tmr0=98;  //Timer0 starts counting from 98 again
 }
 
 if(pir1.f0==1) //if timer1 is overlfowed
 {
   OverNumb++;  //increment number of overflow
   pir1.f0=0; //reset timer1 flag
 }
 
}
 

If the initial value of tmr0_cnt is greater than 14 then at each interrupt it is decremented and then compared with 14 and when a match occurs then the if() condition block is executed. == is not the assignment operator but comparison operator.
 
If the initial value of tmr0_cnt is greater than 14 then at each interrupt it is decremented and then compared with 14 and when a match occurs then the if() condition block is executed. == is not the assignment operator but comparison operator.

firstly : thank u for ur answering

secondly : i know that == is not the assignment operator but comparison operator.
but if wrote this line in MicroC

(if --x==14)
{
code
}

the code will be excuted without comparison , realy i dont know why ?

- - - Updated - - -

jayanth.devarayanadurga can i talk u through facebook account ?
 

jayanth.devarayanadurga

thank u very much
i have found problems in my version of MicroC

and reinstalled it , the program run in correct way , send me ur facebook account
 

you are right , about post #5 i wrote (if --x==14) in wrong way but i have written in correct way in microC compiler , problem is solved thank u very much
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top