how to make other command using C, for PIC 16f84a

Discussion in 'Programmer's Corner' started by fiezzshah, Feb 3, 2010.

  1. fiezzshah

    Thread Starter New Member

    Feb 2, 2010
    6
    0
    my supervisor ask me to use other looping command but i dont know what else to do(this job is not my field actually)..i need ur help to use other command(looping) for this code :

    #include <16F84A.h>
    #USE DELAY( CLOCK=4000000 ) /* Using a 4 Mhz clock */
    #FUSES XT,NOWDT,NOPROTECT,NOPUT
    /* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */
    #byte port_a=5/* define the location of register port_a */
    #byte port_b=6 /* define the location of register port_b */

    main(){
    int cnt, value, Junc;
    set_tris_a(0); /* set port_a to be outputs */
    set_tris_b(0); /* set port_b to be outputs */
    port_a = 0; /* initialize All port_b outp/uts to be zero */
    port_b = 0; /* initialize All port_b outp/uts to be zero */
    value = 0x01;
    while( TRUE )
    { /* forever loop using WHILE construct */
    cnt = 1;
    value = 0x01;
    while ( cnt<9 )
    {

    for (;Junc; )
    {

    port_b = 0x10;
    port_a =0x0E;
    Delay_MS(8000);

    port_b = 0x01;
    port_a =0x0E;
    Delay_MS(2000);

    port_b = 0x00;
    port_a =0xFF;
    Delay_MS(2000);

    port_b = 0x20;
    port_a = 0x0D;
    Delay_MS(8000);

    port_b = 0x02;
    port_a = 0x0D;
    Delay_MS(2000);

    port_b = 0x00;
    port_a =0x0F;
    Delay_MS(2000);

    port_b = 0x40;
    port_a = 0x0B;
    Delay_MS(8000);

    port_b = 0x04;
    port_a = 0x0B;
    Delay_MS(2000);

    port_b = 0x00;
    port_a =0x0F;
    Delay_MS(2000);

    port_b = 0x80;
    port_a = 0x07;
    Delay_MS(8000);

    port_b = 0x08;
    port_a = 0x07;
    Delay_MS(2000);

    port_b = 0x00;
    port_a = 0xFF;
    Delay_MS(8000);

    }
    Delay_MS(2000);
    value = value << 1; /* shift left will put 0x01, 0x02, 0x04, 0x08, 0x10 */
    cnt++; /* 0x20, 0x40, 0x80 to port_a */
    }
    }
    }

    need ur help.....
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,017
    You are going to have to post a LOT more details than that if you want help. You might start with what you are trying to do.
     
  3. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    You'll have troubles right here:
    Code ( (Unknown Language)):
    1.  
    2. main(){
    3. int cnt, value, Junc;
    4. set_tris_a(0); /* set port_a to be outputs */
    5. set_tris_b(0); /* set port_b to be outputs */
    6. port_a = 0; /* initialize All port_b outp/uts to be zero */
    7. port_b = 0; /* initialize All port_b outp/uts to be zero */
    8. value = 0x01;
    9. while( TRUE )
    10. { /* forever loop using WHILE construct */
    11. cnt = 1;
    12. value = 0x01;
    13. while ( cnt<9 )
    14. {
    15.  
    16. for (;Junc; )
    17.  
    in that Junc is not given a start value. It WILL be JUNK.

    And, for( ; Junc; ) is silly -- you are not initializing Junc, nor are you changing it. So why use a FOR loop?

    --Rich
    :confused:
     
Loading...