getting error in MPLAB (p1.exe stopped working)

Thread Starter

ect_09

Joined May 6, 2012
180
when i compile the code am getiing this error
"p1.exe stopped working"
am using MPLAB and Hi-Tech compiler ..
what is its reason.. i attached image.

i was running the following code
Code:
#include<htc.h>

__CONFIG(1,OSCSDIS & HSPLL);
__CONFIG(2,BORDIS & PWRTDIS &WDTDIS);
__CONFIG(3,CCP2RC1);
__CONFIG(4,LVPDIS & STVREN);
__CONFIG(5,UNPROTECT);
__CONFIG(6,WRTEN);
__CONFIG(7,TRU);

#define _XTAL_FREQ   20000000


void led_display(char a)
{
switch(char a)

{
case 0: PORTB=0x01; break;
case 1: PORTB=0x02; break;
case 2: PORTB=0x04; break;
case 3: PORTB=0x08; break;
}

void main()
{
PORTB=0x00;
char a;

while(1)
{
led_display(a);
__delay_ms(1000);
//for(a=0;a<5;a++);
a=(++a)%10;
}

}
g.png
 

tshuck

Joined Oct 18, 2012
3,534
It's a program used by the compiler. It failing usually means you need to check your input file for syntax errors...

Edit: You never closed 'led_display'.
 

adam555

Joined Aug 17, 2013
858
You're missing the closing bracket on your led_display function. Add '}' before "void main()".

I also noticed this yesterday in your previous thread: is there any reason why you are not using LATx instead if PORTx to output?
 

Thread Starter

ect_09

Joined May 6, 2012
180
because am getting output with PORT too instead of using LAT.
i als0 define TRISB as output.

what about P1.exe not working properly????
 

Thread Starter

ect_09

Joined May 6, 2012
180
__delay_ms(1000);
getting error delay argument too long..
what should i do..
if i divide them 250+250+250+250 with 4 delays am not getting delay of 1 sec..
 

adam555

Joined Aug 17, 2013
858
You already dealt with that problem the other day: you need to lower ms and put it into a loop.

I was telling you about LATx because with the PIC18 is more reliable. When you begin to read from ports you will find that some times the values you wrote with PORTx will be different when you read them.
 

tshuck

Joined Oct 18, 2012
3,534
__delay_ms(1000);
getting error delay argument too long..
what should i do..
if i divide them 250+250+250+250 with 4 delays am not getting delay of 1 sec..
Look at where I addressed this in your other threads. You need to define your oscillator...
_XTAL_FREQ only tells the compiler what it should assume it is set at...
 

Thread Starter

ect_09

Joined May 6, 2012
180
tshuck , am not clear from that problem ,
check my code in this thread . i already defined _XTAL_FREQ..
but still hanged on this problem. please help me.
 

tshuck

Joined Oct 18, 2012
3,534
. i already defined _XTAL_FREQ..
This doesn't set your oscillator. This is used to tell the compiler to calculate the number of cycles to count in order to get the desired delay, assuming your oscillator is running at the frequency defined in
_XTAL_FREQ. Again, this doesn't set your oscillator frequency, this is the number used to calculate a delay should you use an oscillator of that frequency.

Edit: This thread should help clarify things for you...
 
Last edited:

tshuck

Joined Oct 18, 2012
3,534
sir am not clear with your point , can you explain please???
Your oscillator is set with a combination of OSCCON and the configuration bits, as I've been telling you in your other threads.

_XTAL_FREQ is used in a macro. It doesn't set or change any aspect of the device. It is only used to calculate the delay in _delay_ms(). You will not get a 1 sec delay while using a mismatched _XTAL_FREQ from what your PIC is actually running at (FOSC).
 
Top