why this program is not running

Discussion in 'Embedded Systems and Microcontrollers' started by abeychandran, Mar 1, 2012.

  1. abeychandran

    Thread Starter New Member

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

    Code ( (Unknown Language)):
    1.  
    2. #include<pic.h>
    3. void main()
    4.         {
    5.         TRISB = 0 ;     // set PORTB as OUTPUT
    6.  
    7.         for(;;)         // forever
    8.                 {
    9.                 PORTB = 0xff ;          // turn all LEDs ON
    10.                 Delay_ms(500) ;         // wait 500 ms
    11.                 PORTB = 0 ;             // turn all LEDs OFF
    12.                 Delay_ms(500) ;         // wait 500 ms
    13.                 }
    14.         }
    15.  
     
    Last edited by a moderator: Mar 1, 2012
  2. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    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?
     
  3. captainshahid

    New Member

    Feb 29, 2012
    7
    0
    i think you have should check your for loop..
     
  4. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    Error [499] ; 0. undefined symbol:
    _Delay_ms(new.obj)
     
  5. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Then you need something like:

    Code ( (Unknown Language)):
    1.  
    2. #include "delays.h" // not sure about this, and in must be in your project folder
    3.  
    4. #define _XTAL_FREQ 4000000 // 4MHz Osc freq
    5.  
    ... and to start it is wise to use the internal oscillator.

    How is this wired? Shematic / Picture ?
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  7. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    16f877a and hitech c v9.80 free version
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It was some problem using HI-Tech and long delays. But they are fixed in the version you use. Did you find out about the delay functions used in Hi-Tech C?
     
  9. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Have you tried:

    Code ( (Unknown Language)):
    1.  
    2. __delay_ms(500);
    3.  
     
  10. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    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()
     
  11. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    As a note it is often more convenient to use __delay_us() or __delay_ms
     
  12. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    #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
     
  13. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Make it a habit of always setting the configuration bits in the code;)
     
Loading...