erfan.khalilian69
Member level 4
- Joined
- Feb 7, 2011
- Messages
- 71
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,288
- Location
- Kualalampur
- Activity points
- 1,916
Hi everyone Im so confuse why the simple syntax gives me error . while I use __delay_ms(); it gives me error and i dun know the reason, is anyone can help me plz ?
here is my program once i deleted the __delay_ms() then it builds successful)
#include <pic.h>
#include <htc.h>
__CONFIG ( 0x3F32 ); //configuration for the microcontroller
// define
//==========================================================================
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 20000000
#endif
#define BUTTON RB0 //bit 1 of PORTC
#define BUTTON1 RB1
#define BUTTON2 RB2
main(void)
{
TRISB = 0b00000111; /* all bits output */
//int x;
while(1)
{
if (BUTTON != 0)
{
PORTB = 0x80;
__delay_ms(1); // delay for 2 milliseconds
CLRWDT();
PORTB = 0x00;
__delay_ms(19); // delay for 2 milliseconds
CLRWDT();
}
if (BUTTON1 != 0)
{
PORTB = 0x40;
__delay_ms(1.5); // delay for 2 milliseconds
CLRWDT();
PORTB = 0x00;
__delay_ms(18.5); // delay for 2 milliseconds
CLRWDT();
}
if (BUTTON2 != 0)
{
PORTB = 0x20;
__delay_ms(2); // delay for 2 milliseconds
CLRWDT();
PORTB = 0x00;
__delay_ms(18); // delay for 2 milliseconds
CLRWDT();
} //else PORTB = 0x00;
}
}
here is my program once i deleted the __delay_ms() then it builds successful)
#include <pic.h>
#include <htc.h>
__CONFIG ( 0x3F32 ); //configuration for the microcontroller
// define
//==========================================================================
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 20000000
#endif
#define BUTTON RB0 //bit 1 of PORTC
#define BUTTON1 RB1
#define BUTTON2 RB2
main(void)
{
TRISB = 0b00000111; /* all bits output */
//int x;
while(1)
{
if (BUTTON != 0)
{
PORTB = 0x80;
__delay_ms(1); // delay for 2 milliseconds
CLRWDT();
PORTB = 0x00;
__delay_ms(19); // delay for 2 milliseconds
CLRWDT();
}
if (BUTTON1 != 0)
{
PORTB = 0x40;
__delay_ms(1.5); // delay for 2 milliseconds
CLRWDT();
PORTB = 0x00;
__delay_ms(18.5); // delay for 2 milliseconds
CLRWDT();
}
if (BUTTON2 != 0)
{
PORTB = 0x20;
__delay_ms(2); // delay for 2 milliseconds
CLRWDT();
PORTB = 0x00;
__delay_ms(18); // delay for 2 milliseconds
CLRWDT();
} //else PORTB = 0x00;
}
}