coding porblem~~~~~~~

Discussion in 'The Projects Forum' started by Jackerq1, Nov 9, 2011.

  1. Jackerq1

    Thread Starter New Member

    Nov 1, 2011
    4
    0
    i use MBLAB PIC 16f628A
    here the coding below ~~~~~~~~~~~~~~~
    i wan work as normal traffic light , then my coding all can work but why the else if (RA2) cannot work ? is that i set the I\O pin wrondly ?

    #include<pic.h>


    __CONFIG(0x3F38);
    unsigned long int i;
    delay1s()
    {
    for(i=0;i<30000;i++)
    {
    NOP();
    }
    }

    void main()
    {
    CMCON=7;
    TRISA=0x00001111;
    TRISB=0b00000000;
    PORTB=0b00000000;
    PORTA=0b00000000;

    while(RA0)
    {
    while(1)
    {
    if(RA1)
    {
    PORTB=0b01001011;
    delay1s();
    delay1s();
    delay1s();
    PORTB=0b10100001;
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    goto s3;
    }




    else if(RA2)
    {
    PORTA=0b00001000;
    delay1s();
    PORTA=0b00000000;
    delay1s();
    break;
    }
    s0:
    PORTB=0b01001100;
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    goto s1;

    s1:
    PORTB=0b01001011;
    delay1s();
    delay1s();
    delay1s();
    goto s2;

    s2:
    PORTB=0b01100001;
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    delay1s();
    goto s3;

    s3:
    PORTB=0b01011001;
    delay1s();
    delay1s();
    delay1s();




    }
    }
    }
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hi Jackerq1. Have you tried to do some debugging with the MPLAB simulator? Read the first post here for more info.
    http://forum.allaboutcircuits.com/showthread.php?t=44852
    As far as I can see you use HI-Tech C. You know that HI-Tech C have the macros __delay_ms(x) and __delay_us(x) provided. The manual are also included in the install.
     
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I am simply re-indenting your code and using the CODE tags to preserve your formatting.

    Code ( (Unknown Language)):
    1.  
    2. #include<pic.h>
    3.  
    4.  
    5. __CONFIG(0x3F38);
    6. unsigned long int i;
    7. delay1s()
    8. {
    9.     for(i=0;i<30000;i++)
    10.     {
    11.         NOP();
    12.     }
    13. }  
    14.  
    15. void main()
    16. {
    17.     CMCON=7;
    18.     TRISA=0x00001111;
    19.     TRISB=0b00000000;
    20.     PORTB=0b00000000;
    21.     PORTA=0b00000000;
    22.  
    23.     while(RA0)
    24.     {
    25.         while(1)
    26.         {
    27.             if(RA1)
    28.             {
    29.                 PORTB=0b01001011;
    30.                 delay1s();
    31.                 delay1s();
    32.                 delay1s();
    33.                 PORTB=0b10100001;
    34.                 delay1s();
    35.                 delay1s();
    36.                 delay1s();
    37.                 delay1s();
    38.                 delay1s();
    39.                 delay1s();
    40.                 delay1s();
    41.                 delay1s();
    42.                 delay1s();
    43.                 delay1s();
    44.                 goto s3;
    45.             }
    46.  
    47.  
    48.  
    49.  
    50.             else if(RA2)
    51.             {
    52.                 PORTA=0b00001000;
    53.                 delay1s();
    54.                 PORTA=0b00000000;
    55.                 delay1s();
    56.                 break;
    57.             }
    58. s0:
    59.             PORTB=0b01001100;
    60.             delay1s();
    61.             delay1s();
    62.             delay1s();
    63.             delay1s();
    64.             delay1s();
    65.             delay1s();
    66.             delay1s();
    67.             delay1s();
    68.             delay1s();
    69.             delay1s();
    70.             goto s1;
    71.  
    72. s1:
    73.             PORTB=0b01001011;
    74.             delay1s();
    75.             delay1s();
    76.             delay1s();
    77.             goto s2;
    78.  
    79. s2:
    80.             PORTB=0b01100001;
    81.             delay1s();
    82.             delay1s();
    83.             delay1s();
    84.             delay1s();
    85.             delay1s();
    86.             delay1s();
    87.             delay1s();
    88.             delay1s();
    89.             delay1s();
    90.             delay1s();
    91.             goto s3;
    92.  
    93. s3:
    94.             PORTB=0b01011001;
    95.             delay1s();
    96.             delay1s();
    97.             delay1s();
    98.  
    99.         }
    100.     }
    101. }
     
  4. DigitalReaper

    Member

    Aug 7, 2010
    70
    2
    Code ( (Unknown Language)):
    1.  
    2. void main()
    3. {
    4.     CMCON=7;
    5.     TRISA=0x00001111; //should this not be 0[B]b[/B]00001111?
    6.     TRISB=0b00000000;
    7.     PORTB=0b00000000;
    8.     PORTA=0b00000000;
    9. *SNIP*
    10.  
     
Loading...