#include <htc.h>
//device configuration bit
__CONFIG(0x3F3A);
//define
#define LED1 RB7
#define LED2 RB6
//function prototype
void blink_LED1(unsigned char n);
void blink_LED2(unsigned char n);
//main function
//================================================================
void main(void)
{
//device peripheral configuration
TRISB7=0; //set RB7 as output
TRISB6=0; //set RB6 as output
//infinity loop
while(1)
{
//blink LED1 for 3 times
blink_LED1(3);
//blink LED2 for 3 times
blink_LED2(3);
}
}
//function to blink LED1 for n times
void blink_LED1(unsigned char n)
{
//loop for n times
for(n+=1;n>0;n-=1)
{
//set LED1 to 1
LED1=1;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
//set LED1 to 1
LED1=0;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
}
}
//function to blink LED2 for n times
void blink_LED2(unsigned char n)
{
//loop for n times
for(n+=1;n>0;n-=1)
{
//set LED2 to 1
LED2=1;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
//set LED2 to 1
LED2=0;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
}
}
how to calculate the delay time?i mean if i want a 1 second delay how should i program in the for condition.
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
how can i know the above command max value is 65535?
//device configuration bit
__CONFIG(0x3F3A);
//define
#define LED1 RB7
#define LED2 RB6
//function prototype
void blink_LED1(unsigned char n);
void blink_LED2(unsigned char n);
//main function
//================================================================
void main(void)
{
//device peripheral configuration
TRISB7=0; //set RB7 as output
TRISB6=0; //set RB6 as output
//infinity loop
while(1)
{
//blink LED1 for 3 times
blink_LED1(3);
//blink LED2 for 3 times
blink_LED2(3);
}
}
//function to blink LED1 for n times
void blink_LED1(unsigned char n)
{
//loop for n times
for(n+=1;n>0;n-=1)
{
//set LED1 to 1
LED1=1;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
//set LED1 to 1
LED1=0;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
}
}
//function to blink LED2 for n times
void blink_LED2(unsigned char n)
{
//loop for n times
for(n+=1;n>0;n-=1)
{
//set LED2 to 1
LED2=1;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
//set LED2 to 1
LED2=0;
//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
}
}
how to calculate the delay time?i mean if i want a 1 second delay how should i program in the for condition.
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
how can i know the above command max value is 65535?