+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21
  1. #1
    Advanced Member level 3
    Points: 5,300, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    vinodstanur's Avatar
    Join Date
    Oct 2009
    Location
    Kerala (INDIA)
    Posts
    749
    Helped
    117 / 117
    Points
    5,300
    Level
    17
    Blog Entries
    3

    HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Hi all, i just started PIC programming few days ago . I prefer HIGH TECH C compiler for programming (in MPLAB). For making delay, i use

    void delay(unsigned int z)
    {
    int j;
    for(j=0;j<=z;j++)
    }

    but i dont know how to make exact delay like 1ms,1 sec, 1 minute , etc...
    pls help me.......


    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 1
    Points: 8,577, Level: 22
    klug's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Helped
    13 / 13
    Points
    8,577
    Level
    22

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Try to use routines available on the microchip site. They are made for HIGH TECH C compiler.

    http://www.microchipc.com/sourcecode...6xxxx_v7-1.zip



  3. #3
    Full Member level 3
    Points: 2,032, Level: 10

    Join Date
    May 2009
    Location
    Serbia
    Posts
    178
    Helped
    20 / 20
    Points
    2,032
    Level
    10

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    https://www.edaboard.com/thread35213.html

    A little bit of search.... :)



  4. #4
    Advanced Member level 3
    Points: 5,300, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    vinodstanur's Avatar
    Join Date
    Oct 2009
    Location
    Kerala (INDIA)
    Posts
    749
    Helped
    117 / 117
    Points
    5,300
    Level
    17
    Blog Entries
    3

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    actually am new in pic programming.......i downloaded the file posted above. BUT there are many files like
    always.h
    delay.c
    delay.h
    delay.pjt
    main.c etc
    .
    .
    Actually am confused , what to du with those files.....pls explain



  5. #5
    Advanced Member level 3
    Points: 5,367, Level: 17

    Join Date
    Jul 2009
    Posts
    734
    Helped
    82 / 87
    Points
    5,367
    Level
    17

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    depending on your definition of "exact", the right answer ranges from "impossible" to "too easy".



  6. #6
    Advanced Member level 1
    Points: 8,577, Level: 22
    klug's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Helped
    13 / 13
    Points
    8,577
    Level
    22

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    vinodstanur,

    you can find "readme.txt" file there. It has an explanation.

    Also, you will find "main.c" file. It is an example program that using these routines.



  7. #7
    Full Member level 5
    Points: 3,185, Level: 13

    Join Date
    Feb 2007
    Location
    USA
    Posts
    260
    Helped
    35 / 35
    Points
    3,185
    Level
    13

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    See if you find something useful here:

    NerdKits - Crystal Real Time Clock

    David.



    •   AltAdvertisement

        
       

  8. #8
    Advanced Member level 3
    Points: 5,367, Level: 17

    Join Date
    Jul 2009
    Posts
    734
    Helped
    82 / 87
    Points
    5,367
    Level
    17

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    NerdKits
    Wow, one super-expensive kit.

    how does it compare to Atmel's AT90USBKey2?



  9. #9
    Member level 5
    Points: 4,098, Level: 15

    Join Date
    May 2001
    Posts
    93
    Helped
    33 / 33
    Points
    4,098
    Level
    15

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    A new built-in inline function '_delay' (request a delay in instruction cycles)
    had been offered by HI-TECH C for PIC10/12/16 v9.60+ PRO mode.
    EX:
    Code:
    #include 
    #define _XTAL_FREQ 4e6 // 4MHz 
    void main( void )
    {
       _delay( 1 ); // 1 instruction cycle delay
       __delay_us( 2 ); // 2 us delay
       __delay_ms( 3 ); // 3 ms delay
    }
    To read the manual for details.


    2 members found this post helpful.

  10. #10
    Super Moderator
    Points: 259,183, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,250
    Helped
    13766 / 13766
    Points
    259,183
    Level
    100

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    A new built-in inline function '_delay' had been offered by HI-TECH C for PIC10/12/16 v9.60+ PRO mode
    Impressive, how they finally catch up with the competition



    •   AltAdvertisement

        
       

  11. #11
    Full Member level 1
    Points: 2,314, Level: 11
    Achievements:
    7 years registered
    spiralbrain's Avatar
    Join Date
    Jun 2006
    Posts
    113
    Helped
    24 / 24
    Points
    2,314
    Level
    11

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    It has been in HiTech for a long long time, people just failed to find it or were too busy looking for a free delay routine. so has been the inline option.



  12. #12
    Advanced Member level 3
    Points: 5,367, Level: 17

    Join Date
    Jul 2009
    Posts
    734
    Helped
    82 / 87
    Points
    5,367
    Level
    17

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    you can easily defeat that delay routine, or pretty much any delay routine in a mcu.

    the "appropriate" solution really depends on how "exact" you want it to be.



  13. #13
    Advanced Member level 3
    Points: 5,300, Level: 17
    Achievements:
    Created Blog entry 7 years registered
    vinodstanur's Avatar
    Join Date
    Oct 2009
    Location
    Kerala (INDIA)
    Posts
    749
    Helped
    117 / 117
    Points
    5,300
    Level
    17
    Blog Entries
    3

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    thanks YAGER.........its working.



  14. #14
    Junior Member level 2
    Points: 121, Level: 1

    Join Date
    Jun 2014
    Posts
    20
    Helped
    0 / 0
    Points
    121
    Level
    1

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Code:

    #include
    #define _XTAL_FREQ 4e6 // 4MHz
    void main( void )
    {
    _delay( 1 ); // 1 instruction cycle delay
    __delay_us( 2 ); // 2 us delay
    __delay_ms( 3 ); // 3 ms delay
    }
    These routines are not working ...please help!



  15. #15
    Full Member level 4
    Points: 2,943, Level: 12
    Achievements:
    7 years registered
    nagkiller's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    226
    Helped
    37 / 37
    Points
    2,943
    Level
    12

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Works fine for me!!!

    Code:
    // hi-tech c compiler for PIC12F629
    #include 	// Required to interface with delay routines
    #ifndef _XTAL_FREQ
     // Unless already defined assume 4MHz system frequency
     // This definition is required to calibrate __delay_us() and __delay_ms()
     #define _XTAL_FREQ 4000000
    #endif
    __CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & BOREN_OFF & CP_OFF & CPD_OFF);
    void main(void){
    	while(1)
    	{
    		GPIO=0;
    		__delay_ms(500);
    		GPIO=0xFF;
    		__delay_ms(500);
    	}
    }



  16. #16
    Advanced Member level 4
    Points: 8,157, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,317
    Helped
    268 / 268
    Points
    8,157
    Level
    21

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Quote Originally Posted by renuka gurmeet singh View Post
    These routines are not working ...please help!
    maybe the compiler doesn't like this notation #define _XTAL_FREQ 4e6 // 4MHz
    and prefere #define _XTAL_FREQ 4000000 // 4MHz



  17. #17
    Junior Member level 2
    Points: 121, Level: 1

    Join Date
    Jun 2014
    Posts
    20
    Helped
    0 / 0
    Points
    121
    Level
    1

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Code:
    #include
    #define _16F877
    __CONFIG( HS & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT );
    
    #define	XTAL_FREQ	12MHZ
    void main()
    {
    TRISB=0x00;
    TRISD=0x00;
    while(1)
    {
    PORTB=0xff;
    PORTD=0xff;
    __delay_ms( 3 );
    PORTB=0x00;
    PORTD=0x00;
    __delay_ms( 3 );
    }
    }
    This my code and am using MPLAB IDE v8.60 with HI-TECH compiler 9.60.
    I have type the delay routines as you said but the compiler gave the following errors
    Error [192] E:\led.c; 14.29 undefined identifier "_XTAL_FREQ"

    ********** Build failed! **********
    please help...



  18. #18
    Full Member level 4
    Points: 2,943, Level: 12
    Achievements:
    7 years registered
    nagkiller's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    226
    Helped
    37 / 37
    Points
    2,943
    Level
    12

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Try use like my example:

    #include
    #define xtal
    Fuses...

    Open the examples folder from your hitech compiler... Search for delay.c...



  19. #19
    Advanced Member level 4
    Points: 8,157, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,317
    Helped
    268 / 268
    Points
    8,157
    Level
    21

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    try this

    Code:
    #define    XTAL_FREQ 12000000  // 12 MHZ
    
    or 
    #define    XTAL_FREQ 12
    or
    #define PIC_CLK 12



  20. #20
    Full Member level 1
    Points: 2,553, Level: 11
    Achievements:
    7 years registered
    Allen6502's Avatar
    Join Date
    Nov 2008
    Location
    Borneo Island
    Posts
    119
    Helped
    32 / 32
    Points
    2,553
    Level
    11

    Re: HOW TO CREATE exact 1ms delay using High tech C (HTC) compiler?(PIC16F84A,4MHz)

    Quote Originally Posted by renuka gurmeet singh View Post
    Code:
    #define	XTAL_FREQ	12MHZ
    This my code and am using MPLAB IDE v8.60 with HI-TECH compiler 9.60.
    I have type the delay routines as you said but the compiler gave the following errors

    Error [192] E:\led.c; 14.29 undefined identifier "_XTAL_FREQ"

    ********** Build failed! **********
    I think the problem is quite obvious.

    The error mess says "_XTAL_FREQ" not defined.

    But in your program you defined "XTAL_FREQ"

    You left out "_" before XTAL.

    And I don't think the compiler would accept 12MHZ too. Try 12000000 instead.

    Allen



    •   AltAdvertisement

        
       

--[[ ]]--