# Defining a delay

Status
Not open for further replies.

#### Kryten

##### New Member
Is it possible to define a delay if i shall use it several times

I mean I can define ports as names for easy programming and give low or high output short names like

Code:
#define LED_OFF output_low

Can I do the same with a delay?

I looking to turn off (or on) several outputs for a short period of time (250ms)
will it make sense to do it like this?

Code:
#define LED_blink output_low delay(250ms) output_high

#### Wp100

##### Well-Known Member
Hi,

Is it possible to define a delay if i shall use it several times

Yes, you create a subroutine for the delay_loop.

You then CALL delay_loop or GOTO delay_loop when ever you need it.

The value currently held in W can be carried into the subroutine if needed.

A Macro can be also used to do similar things.

#### Kryten

##### New Member
Ok I might have been a bit vague. Im programming in C because im trying to control via USB

#### mramos1

##### Active Member
Mark Crosbie's Homepage

What C compiler are you using? What processor/controller? Do you want the I/O in the routine as well, or just a delay? Some compilers have libraries that have msec_delay included.

#### Kryten

##### New Member
Im using (i belive its called) Hi Tech pic c compiler (the one that comes with mplab) and 18F4550 (PIC that is).

Im going to use 12MHz crystall and running it a 4x (48MHz)

Last edited:
Status
Not open for further replies.

Replies
19
Views
7K
Replies
3
Views
1K
Replies
10
Views
2K
Replies
9
Views
1K
Replies
11
Views
8K