getting error in MPLAB (p1.exe stopped working)

Discussion in 'Embedded Systems and Microcontrollers' started by ect_09, Oct 29, 2014.

  1. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    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 (Text):
    1. #include<htc.h>
    2.  
    3. __CONFIG(1,OSCSDIS & HSPLL);
    4. __CONFIG(2,BORDIS & PWRTDIS &WDTDIS);
    5. __CONFIG(3,CCP2RC1);
    6. __CONFIG(4,LVPDIS & STVREN);
    7. __CONFIG(5,UNPROTECT);
    8. __CONFIG(6,WRTEN);
    9. __CONFIG(7,TRU);
    10.  
    11. #define _XTAL_FREQ   20000000
    12.  
    13.  
    14. void led_display(char a)
    15. {
    16. switch(char a)
    17.  
    18. {
    19. case 0: PORTB=0x01; break;
    20. case 1: PORTB=0x02; break;
    21. case 2: PORTB=0x04; break;
    22. case 3: PORTB=0x08; break;
    23. }
    24.  
    25. void main()
    26. {
    27. PORTB=0x00;
    28. char a;
    29.  
    30. while(1)
    31. {
    32. led_display(a);
    33. __delay_ms(1000);
    34. //for(a=0;a<5;a++);
    35. a=(++a)%10;
    36. }
    37.  
    38. }
    g.png
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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'.
     
  3. adam555

    Active Member

    Aug 17, 2013
    858
    39
    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?
     
    ect_09 likes this.
  4. adam555

    Active Member

    Aug 17, 2013
    858
    39
    You also forgot to define port B as output with TRISx.
     
    ect_09 likes this.
  5. ect_09

    Thread Starter Member

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

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

    Active Member

    Aug 17, 2013
    858
    39
    That's a Windows error provoked by the Hi-Tech compiler. If you don't get that error with any other code, try fixing the errors I mentioned above and try to compile it again.
     
  7. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    i tried the } befre void main ( ), but getting the same error.
    can you correct this code???
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You can't switch on "char a". You should just have "switch(a)".
     
    ect_09 likes this.
  9. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    __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..
     
  10. adam555

    Active Member

    Aug 17, 2013
    858
    39
    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.
     
    ect_09 likes this.
  11. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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...
     
    ect_09 likes this.
  12. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    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.
     
  13. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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: Oct 29, 2014
    ect_09 likes this.
  14. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    sir am not clear with your point , can you explain please???
     
  15. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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).
     
    ect_09 likes this.
Loading...