• AVR Freaks

Hot!_delay(500) not working in mplab x xc8

Author
buildlab
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2019/06/26 11:50:03
  • Location: 0
  • Status: offline
2019/06/26 23:21:29 (permalink)
0

_delay(500) not working in mplab x xc8

Hi, 
     I am new to PIC programming. i been trying to upload blink program to PIC12F675  
the code is below.


#include <xc.h>
//#define __XTAL_FREQ 4000000
#pragma config FOSC=INTRCIO,WDTE=OFF,MCLRE=OFF,BOREN=OFF

void main(void)
{
TRISIO2 = 0; // Make pin GP5 a digital output

while(1)
{
GP2 = 1;
// Set pin GP5 high
_delay(500); // 0.5 second delay
GP2 = 0;
// Set pin GP5 low
_delay(500); // 0.5 second delay
}
}
 
The problem i am facing is that the Led i connected to the pin GP2 is not blinking,instead it turns ON whole time.
The programmer i am using is k150 ICSP. is it no working because i have erased the internal crystal calibration ?.
any help would be appreciated.
#1

3 Replies Related Threads

    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11241
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: _delay(500) not working in mplab x xc8 2019/06/27 08:15:02 (permalink)
    +3 (3)
    _XTAL_FREQ, not __XTAL_FREQ
    #2
    pcbbc
    Super Member
    • Total Posts : 1187
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: _delay(500) not working in mplab x xc8 2019/06/27 08:54:54 (permalink)
    +3 (3)
    And obviously you will need to un-comment it.
    #define _XTAL_FREQ 4000000

     
    You could do with learning how to use [​code]code tags[/​code] in your posts as well...
    #3
    mbrowning
    Just a Member
    • Total Posts : 1454
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: _delay(500) not working in mplab x xc8 2019/06/27 09:10:36 (permalink)
    +7 (7)
    _delay(500); // 0.5 second delay

    This is not 0.5 seconds, this is 500 instructions. At 4MHz, that 500us. Your LED is turning on and off so fast it just looks always on.
     
    Use
    #define _XTAL_FREQ 4000000

    Then you can use
    __delay_ms(x) // request a delay in milliseconds
    __delay_us(x) // request a delay in microseconds

    for real timed delays. So
    __delay_ms(500);
    would be 500ms or 0.5seconds

    Oh well - there's always next year
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5