Delay Using Pic Microcontroller
Delay Using Pic Microcontroller
* File: DLY1.c
*
*/
void main(void) //
{ //
{ //
DLY: { //
while (!T0IF); // Stays here upto 256 and then T0IF =
1
T0IF = 0; // Resetting the T0IF over flow flag
COUNT ++; // Increments the counter
if (COUNT == 137) // When Count reaches 137, execute the
next instruction //
{ //
COUNT = 0; //
TMR0 = 0; // Timer starts from 0
while (TMR0 < 137); // do nothing while the TMR0 counts up
to 137. Execute the next instruction when it exceeds 137
} //
} //
PORTD, RD0 = 0; //
while (PORTC,RC0 == 0); // Do nothing while RC0 = low and stay
here. Executes the next instruction When RC0 = 1
goto DLY; //
PORTD, RD0 = 1; //
} //
} //
/*
RC1 = 1, RC0 = 0 LED OFF
RC0 = 0, RC1 = 0 LED OFF
*
There are two methods of writing program which I have got from an authorized
text book
But both are wrong. The MPLAB XC8 ver.5. will not identify those statements in
brackets.
while(PORTD,RD0 == 0)
*
Also a statement like PORTD,RD0 = 0 is same as (PORTD,RD0 = 0)
Also a statement like while (PORTC == 0x00); denotes the whole bits are zero and
while (PORTC,RC0 == 0) refers a particular bit which is RC0 of PORTC.
Also a statement like PORTD = 0x01; is same as PORTD,RD0 = 0
*/