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.

Time delay in PIC16f876-A

Status
Not open for further replies.

amitdandyan

Newbie level 6
Newbie level 6
Joined
May 8, 2009
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,396
pic16f876

I have developed the following program to glow an led connected to first pin of PORT B using Mikro C...now the problem is how can i give delay value, eg 250us etc...????


unsigned short i;

void main()
{
TRISB = 0;
PORTB = 0X00;
USART_init(9600); // initialize USART module
// (8 bit, 19200 baud rate, no parity bit...)
while (1)
{
if (USART_Data_Ready()) // if data is received
{
i = USART_Read(); // read the received data
USART_Write(i); // send data via USART
PORTB = 0x01;
Delay_ms('i');
PORTB = 0x00;
}
}
}
 

pic16f876 timer

u have done this much that means u know programming, its a very simple thing

either use a simple for loop delay
or use timer
 
pic16f876 delay

Thanx Sir, but what i want to ask is that how can i physically give a value for 'i' eg. 250 or 100 etc. For example, i connect a LED to port B and i want to change the time of glow of that LED...So i need to give different values of 'i'....how can i give these values using Keyboard ????

If you have used Mikro C, then please let me know how to use its USART terminal for Communication....

Waiting for your reply........
 

72 hour time delay modules

I would like to clarify your questions. Are you asking how to compute for the Constant OFF time of the clock... ?
 

delay_ms(x)

Delay_ms('i'); ???????

maybe Delay_ms(i);

or maybe declare it???

void main(void){
int i;
...

i=250;
...
Delay_ms(i);
...


or just Delay_ms(250);

maybe mikroC has something like Delay_us(250); for microseconds??? (Delay_ms should be in miliseconds)
 

usart_init() usart_write()

char y;
int x;
void main()
{trisa=0;porta=0;


usart_init(9600);
for(;;)
{if(usart_data_ready())
{y = USART_Read();
usart_write(y);
PORTa.f0= 1;
x=y-48;
x=x*1000;
vdelay_ms(x);
porta.f0=0;

}
}
}

this code will work
but the output is porta.f0
and the time will be variable
from
1 to 9 sec

you can change x=x*1000 to
x=x*10000;
and the time will be variable
from
10 to 90 sec
 

baut rate 9600 pic 16f876

thanx loin....bt i have one question...why we cann't use Delay_ms() instead of vdelay_ms(x)?????
 

delay pic16f876a c

because that delay_ms(); is used only with
a constant value but vdelay_ms(); can be used
with variables
but you can use delay_ms();to have a variable delay
but not in a direct way
 

timer pic16f876

thanx man.....plz also explain the indirect way to use delay_ms(x);
 

usart_read

char y;
int x,n;
void main()
{trisa=0;porta=0;


usart_init(9600);
for(;;)
{if(usart_data_ready())
{y = USART_Read();
usart_write(y);
PORTa.f0= 1;
x=y-48;

for(n=0;n<x;n++)
{delay_ms(1000);}
porta.f0=0;

}
}
}
this code shows how you can use delay_ms();
to make a variable delay

regards
 

pic16f876 a

I once had the same problem before I used a good compiler which has a built-in delay function ( delay_ms(x) )

use a program like this

while(1)
{
for(a=0;a<255;a++) // int a;
for(b=0;b<255;b++); // int b;
LED=1; // Just to check the logic
for(a=0;a<255;a++)
for(b=0;b<255;b++);
LED=0;
}

Its simply a nested loop to waste the clock cycles

Use a simulator like Proteus ISIS and put a oscilloscope on the LED pin..and measure the time. In this way you can find out the time period of the loop

NOTE: this will not produce same delay for any crystal oscillator. Its just to check how much the delay is for the specific crystal osc and the loop variable
 

delay in c for pic16f876

@the loin....

char y;
int x;
void main()
{trisb=0;
portb=0;
usart_init(9600);
for(;;)
{if(usart_data_ready())
{y = USART_Read();
usart_write(y);
PORTb.f0= 1;
x=y-48;
vdelay_ms(x);
portb.f0=0;

}
}
}

i hv burned this code in PIC16F876-A and it is working fine to give a delay from 1ms to 5ms.....but for higher values it fails to give an exact delay....!!!!!!!!!!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top