Newbie: PIC18F Code Generation Error

  • William Gebers

    William Gebers - 2008-07-13


    I am new to using the SDCC, but have done some programming in Assembler before, mostly Atmel based stuff.

    I have succeeded in getting an LED to flash on my PIC18F, but if I try and get two LED's to flash alternately it doesn't work.

    I have discovered that the Test.asm file that is generated contains 1 error.  The second BCF should be a BSF.

    Anyone have an idea what I am doing wrong?

    Here are the relevant portions of my c code:

    // configuration
    #define LED_TRIS  TRISBbits.TRISB1
    #define LED_PIN   PORTBbits.RB1
    #define LED_PIN2  PORTBbits.RB3
    #define LED_TRIS2 TRISBbits.TRISB3

    void main()

        // set pin to output
        LED_TRIS = 0;
        LED_TRIS2 = 0;
        // sit in an endless loop blinking the led
        for (;;)
            LED_PIN = 1;
        LED_PIN2 = 0;
            LED_PIN = 0;
        LED_PIN2 = 1;

    And the corresponding ASM code:

    .line    47; Test.c    LED_TRIS = 0;
        BCF    _TRISBbits, 1
        .line    48; Test.c    LED_TRIS2 = 0;
        BCF    _TRISBbits, 3
        .line    52; Test.c    LED_PIN = 1;
        BSF    _PORTBbits, 1
        .line    54; Test.c    LED_PIN2 = 0;
        BCF    _PORTBbits, 3
        .line    55; Test.c    delay_ms(120);

    • Frieder Ferlemann

      > The second BCF should be a BSF.

      the two BCF generated here seem plausible to me:

      .line 47; Test.c LED_TRIS = 0;
      BCF _TRISBbits, 1
      .line 48; Test.c LED_TRIS2 = 0;
      BCF _TRISBbits, 3

      the code generated for lines 56 and 58 should contain the
      BCF, BSF pair you are looking for?

    • William Gebers

      William Gebers - 2008-07-13

      Hi Frieder.

      Thanks for clearing that up for me!  I was not thinking clearly!


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks