why this program is not running

Thread Starter

abeychandran

Joined Feb 7, 2012
17
why this program is not running

Rich (BB code):
#include<pic.h>
void main()
        {
        TRISB = 0 ;     // set PORTB as OUTPUT

        for(;;)         // forever
                {
                PORTB = 0xff ;          // turn all LEDs ON
                Delay_ms(500) ;         // wait 500 ms
                PORTB = 0 ;             // turn all LEDs OFF
                Delay_ms(500) ;         // wait 500 ms
                }
        }
 
Last edited by a moderator:

nerdegutta

Joined Dec 15, 2009
2,689
Do you get an error message?

It is a good habit to include the configuration bits in you code.

To you have a schematic/picture?
 

nerdegutta

Joined Dec 15, 2009
2,689
Then you need something like:

Rich (BB code):
#include "delays.h" // not sure about this, and in must be in your project folder

#define _XTAL_FREQ 4000000 // 4MHz Osc freq
... and to start it is wise to use the internal oscillator.

How is this wired? Shematic / Picture ?
 

t06afre

Joined May 11, 2009
5,934
It is no function in HI-Tech C named Delay_ms(). In the HI-Tech C install directory you will find a folder named docs. Here I will strongly recommend both quickstart.pdf and manual.pdf. I am sure if you the search function in your PDF reader and search for delay. You will find a lot of info. By the way wich version of HI-Tech C are you using
Also which PIC are you using
 

Thread Starter

abeychandran

Joined Feb 7, 2012
17
ya



#include <htc.h>
void _delay(unsigned long cycles);
Description
This is an inline function that is expanded by the code generator. When called, this routine
expands to an inline assembly delay sequence. The sequence will consist of code
that delays for the number of cycles that is specified as argument. The argument must
be a literal constant.
An error will result if the delay period requested is too large. For very large delays, call
this function multiple times.
Example
#include <htc.h>
void
main (void)
{
control |= 0x80;
_delay(10); // delay for 10 cycles
control &= 0x7F;
}
See Also
__delay_us(), __delay_ms()
 

t06afre

Joined May 11, 2009
5,934
ya



#include <htc.h>
void _delay(unsigned long cycles);
Description
This is an inline function that is expanded by the code generator. When called, this routine
expands to an inline assembly delay sequence. The sequence will consist of code
that delays for the number of cycles that is specified as argument. The argument must
be a literal constant.
An error will result if the delay period requested is too large. For very large delays, call
this function multiple times.
Example
#include <htc.h>
void
main (void)
{
control |= 0x80;
_delay(10); // delay for 10 cycles
control &= 0x7F;
}
See Also
__delay_us(), __delay_ms()
As a note it is often more convenient to use __delay_us() or __delay_ms
 

Thread Starter

abeychandran

Joined Feb 7, 2012
17
#include<htc.h>
#define _XTAL_FREQ 4000000 // 4MHz Osc freq
void main()
{
TRISB = 0 ; // set PORTB as OUTPUT

for(;;) // forever
{
PORTB = 0xff ; // turn all LEDs ON
__delay_ms(200);
PORTB = 0 ; // turn all LEDs OFF
__delay_ms(200);
}
}




this pro build succfly but led blinking
 

t06afre

Joined May 11, 2009
5,934
#include<htc.h>
#define _XTAL_FREQ 4000000 // 4MHz Osc freq
void main()
{
TRISB = 0 ; // set PORTB as OUTPUT

for(;;) // forever
{
PORTB = 0xff ; // turn all LEDs ON
__delay_ms(200);
PORTB = 0 ; // turn all LEDs OFF
__delay_ms(200);
}
}
this pro build succfly but led blinking
Make it a habit of always setting the configuration bits in the code;)
 
Top