why open two LED ....PIC16f877a..

Discussion in 'Embedded Systems and Microcontrollers' started by micro1, Mar 9, 2015.

  1. micro1

    Thread Starter Member

    Feb 22, 2015
    52
    0
    hello all

    use PIC16f877a in this problem , the language is hi-tech , I did this problem in MPLAN and the simulation in proteus 8, why open two LED and next time two LED ,I write in programing 8 LEDs ,where the problem in program or in proteus?

    20150309_172608.jpg 1.PNG 2.PNG

    please see my program same the question?

    Code (Text):
    1. #include<htc.h>
    2.  
    3. __CONFIG (FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF );
    4.  
    5. #define _XTAL_FREQ 20000000
    6.  
    7. #define sw1 RB0
    8.  
    9.  
    10. void main(void)
    11. {
    12. unsigned char i;
    13.  
    14. unsigned char j;
    15.  
    16.  
    17. TRISD=0b00000000;
    18.  
    19. PORTD=0b00000000;
    20.  
    21. TRISB0=1;
    22.  
    23.  
    24.  
    25.  
    26. if (sw1=0){
    27.  
    28. while(1){
    29. for(i=0 ;i<2 ;i++)
    30.     {
    31.     PORTD=0b11111111;
    32.  
    33.     __delay_ms(250);
    34.  
    35.     PORTD=0b00000000;
    36.     }
    37.  
    38.  
    39.     __delay_ms(250);
    40.  
    41.  
    42.  
    43. for(i=0 ;i<2 ;i++)
    44.     {
    45.     PORTD=0b11111111;
    46.  
    47.     __delay_ms(250);
    48.  
    49.     PORTD=0b00000000;
    50.     }
    51.   }
    52. }
    53.  
    54. }
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You're program does not include an infinite loop if the switch input =1 when it gets to the if statement.

    What happens after your simulated PIC steps beyond the program space is undefined.

    I'd suggest you put everything in an infinite loop, and add a pullup on your switch input (it's current states are grounded and floating).
     
    micro1 likes this.
Loading...