getting problem in code on hardware

Discussion in 'Embedded Systems and Microcontrollers' started by ect_09, Sep 28, 2014.

  1. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    am working with 18f452 and i right this code


    Code (Text):
    1. #include<htc.h>
    2.  
    3.  
    4. // PIC 18F452 fuse configuration:
    5. // Config word 1 (Oscillator configuration)
    6. // 40Mhz crystal input
    7. __CONFIG(1, OSCSDIS & HSPLL);
    8. // Config word 2
    9. __CONFIG(2, BORDIS & PWRTDIS & WDTDIS);
    10. // Config word 3
    11. __CONFIG(3, CCP2RC1);
    12. // Config word 4
    13. __CONFIG(4, LVPDIS & STVREN);
    14. // Config word 5, 6 and 7 (protection configuration)
    15. __CONFIG(5, UNPROTECT);
    16. __CONFIG(6, WRTEN);
    17. __CONFIG(7, TRU);
    18.  
    19. #define _XTAL_FREQ 40000000   //MHz
    20.  
    21.  
    22.  
    23. void delay_sec(unsigned char seconds)    // This function provides delay in terms of seconds
    24. {
    25.     unsigned char i,j;
    26.  
    27.     for(i=0;i<seconds;i++)
    28.     {
    29.        for(j=0;j<100;j++)
    30.         __delay_ms(10);
    31.     }    
    32. }
    33.  
    34. void main()
    35. {
    36.      
    37.     TRISB = 0;  
    38.     while(1)
    39.     {
    40.         LATB = 0xFF;   // ->  0101 0101
    41.         delay_sec(1);   // delay of one second
    42.         LATB = 0x00;    // ->  1010 1010  
    43.         delay_sec(1);    // delay of one second
    44.     }
    45. }
    first am not getting output exactly for which i wrote this code.
    when i burn this code and supply power , then i get the portB all pins were active but its not going to zero ..
    but after some time when i remove power and again connect the voltage then its blink but not for 1 sec. its about 4 sec. and some time it take 1sec, some time 2 sec.
    but when i try any other data like

    LATB=0x55;
    LATB=0xAA;
    its work fine with exactly the same delay.

    please guide me
     
Loading...