Blinking Led on pic18f4550

2010-09-19
2013-03-12
  • Jean-Loup Defaisse

    Hello,

    I'm trying to make two led blink, i use this simple code:

    #include <pic18f4550.h>
    #include <delay.h>
    static __code char __at(__CONFIG1H) conf1H = _OSC_HS__HS_PLL__USB_HS_1H;
    static __code char __at(__CONFIG1L) conf1L = _PLLDIV_DIVIDE_BY_5__20MHZ_INPUT__1L & _CPUDIV__OSC1_OSC2_SRC___4__96MHZ_PLL_SRC___6__1L;
    static __code char __at(__CONFIG2H) conf2H = _WDT_DISABLED_CONTROLLED_2H;
    static __code char __at(__CONFIG4L) conf4 = _LVP_OFF_4L & _ENHCPU_OFF_4L;// & _BACKBUG_OFF_4L & _STVR_OFF_4L;
    #define LED_AFF1   PORTBbits.RB4
    #define LED_AFF2   PORTBbits.RB5
    
    void main(void) {
     PORTB = 0x00;        
     TRISB = 0x00;
    while(1) {
        delay10ktcy(200);
            LED_AFF1 = 1;
            LED_AFF2 = 0;
        delay10ktcy(200);
        LED_AFF2 = 1;
            LED_AFF1 = 0;
      }
    }
    

    This is supposed to make the led connected to RB4 and RB5 blink each one after the other, but the led on RB4 just stay off.
    It seems that when i set LED_AFF2 (RB5) to 0, it also put RB4 to 0. Inverting LED_AFF1 = 1 and LED_AFF2=0 makes it work.

    Any idea why?

     
  • Zenon Bolino

    Zenon Bolino - 2010-09-25

    I think your problem is because you are using PORT instead of LAT .
    Change your definition for  #define LED_AFF1   LATBbits.RB4

    Regards,

    Martin

     
  • Jean-Loup Defaisse

    thank you, it works ! (except it's LATB4 instead of RB4).

     
  • Anonymous - 2011-01-16

    And thank you for posting the program!  It's the first one I ever got to work on an 18f2550…  One config register's bad enough, let alone eight, I couldn't think up a working combination from scratch, now I have something to work from.

     

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

Sign up for the SourceForge newsletter:





No, thanks