Reputation: 11
I'm working with a PIC16F628A but the IDE won't accept the _delay_ms
command and doesn't build/compile, I don't know what to do... here is my code:
#include <xc.h> // STANDARD INCLUDE FILE FOR MICROCHIP PRODUCTS
// uc CONFIG (START)
#pragma config FOSC = HS // 4MHz EXTERNAL CLOCK
#pragma config WTDE = ON
#pragma config PWRTE = OFF
#pragma config MCLRE = ON
#pragma config BOREN = ON
#pragma config LVP = ON
#pragma config CPD = OFF
#pragma config CP = OFF
// uC CONFIG (END)
#define _XTAL_FREQ 4000000
#define BT1 PORTA.RA0 // Button with number 1
#define BT2 PORTA.RA1 // Button with number 2
#define BT3 PORTA.RA2 // Button with number 3
#define BT4 PORTA.RA3 // Button with number 4
#define a PORTB.RB0 // "a" segment from 7-segment display
#define b PORTB.RB1 // "b" segment from 7-segment display
#define c PORTB.RB2 // "c" segment from 7-segment display
#define d PORTB.RB3 // "d" segment from 7-segment display
#define e PORTB.RB4 // "e" segment from 7-segment display
#define f PORTB.RB5 // "f" segment from 7-segment display
#define g PORTB.RB6 // "g" segment from 7-segment display
void main ()
{
TRISA = 0x01;
TRISB = 0x00;
PORTA = 0x00;
PORTB = 0x00;
while(1)
{
if (BT1 == 1)
{
a = 0x00;
b = 0x01;
c = 0x01;
d = 0x00;
e = 0x00;
f = 0x00;
g = 0x00;
_delay_ms(5000);
a = 0x00;
b = 0x00;
c = 0x00;
d = 0x00;
e = 0x00;
f = 0x00;
g = 0x00;
_delay_ms(1000);
}
}
}
Do I need to add libraries? This code worked fine in MikroC but I'm trying to learn MPLAB since it's free and seems to be an industry standard tool for embedded systems.
Upvotes: 1
Views: 2244
Reputation: 4288
You don't need an extra library, but in xc8 the name of the function is__delay_ms(...)
with two _
.
Please remember, these functions are actually in line macros and they have maximum delay values that depend on part type and clock frequency. To get longer delays using these macros put them in a for loop. I guess __delay_ms(5000)
is a little bit to much.
Upvotes: 1