News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Cannot get 2 LED's to flash

Started by RGV250, Oct 17, 2022, 03:51 PM

Previous topic - Next topic

RGV250

Hi,
I am having a bit of difficulty flashing a couple of LED's.
In the code below I cannot get both to flash, if I move one above the other it changes which one flashes???
I tried with LAT as well but still no good, not tried on real hardware, only a sim.

    Device = 18F25K20
    Declare Xtal = 64

'-------------------------------------------------------------
' Setup the fuses for the 4xPLL
'
Config_Start
    FOSC = HSPLL        ' HS oscillator, PLL enabled and under software control
    Debug = Off         ' Background debugger disabled' RB6 and RB7 configured as general purpose I/O pins
    XINST = Off         ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    STVREN = Off        ' Reset on stack overflow/underflow disabled
 '   WDTEN = Off         ' WDT disabled (control is placed on SWDTEN bit)
    FCMEN = Off         ' Fail-Safe Clock Monitor disabled
    IESO = Off          ' Two-Speed Start-up disabled
    WDTPS = 128         ' Watchdog is 1:128
    BOREN = Off         ' Brown-out Reset disabled in hardware and software
    BORV = 18           ' VBOR set to 1.8 V nominal
    MCLRE = On          ' MCLR pin enabled, RE3 input pin disabled
    HFOFST = Off        ' The system clock is held Off until the HF-INTOSC is stable.
    LPT1OSC = Off       ' T1 operates in standard power mode
    PBADEN = Off        ' PORTB<4:0> pins are configured as digital I/O on Reset
    CCP2MX = PORTC      ' CCP2 input/output is multiplexed with RC1
    LVP = Off           ' Single-Supply ICSP disabled
    Cp0 = Off           ' Block 0 (000800-001FFFh) not code-protected
    CP1 = Off           ' Block 1 (002000-003FFFh) not code-protected
    CPB = Off           ' Boot block (000000-0007FFh) not code-protected
    CPD = Off           ' Data eeprom not code-protected
    WRT0 = Off          ' Block 0 (000800-001FFFh) not write-protected
    WRT1 = Off          ' Block 1 (002000-003FFFh) not write-protected
    WRTB = Off          ' Boot block (000000-0007FFh) not write-protected
    WRTC = Off          ' Configuration registers (300000-3000FFh) not write-protected
    WRTD = Off          ' Data eeprom not write-protected
    EBTR0 = Off         ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
    EBTR1 = Off         ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
    EBTRB = Off         ' Boot block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

    Declare Watchdog = On
   
    Symbol BLUE_LED = PORTC.5           ' Red LED
    Symbol RED_LED = PORTC.6            ' Blue LED
   
'------------------------------------------------------------------------
' The main program loop starts here
'
    PORTC.5=0                           ' Set LED pin to output
    PORTC.6=0                           ' Set LED pin to output
       
    Do
   
    Toggle BLUE_LED                     ' Toggle Blue LED
' This does not work in this position but the red one does       
   
    Toggle RED_LED                      ' Toggle Red LED
 '   Toggle BLUE_LED                     ' Toggle Blue LED 
' If I comment out the top blue one and move it here it flashes but the red one does not.
                     
 '   Sleep 1                             ' Sleep for approx 1 Seconds
     DelayMS 500
    Loop                                ' Forever

Bob

joesaliba

Bob,

With: -

PORTC.5=0                           ' Set LED pin to output
    PORTC.6=0                           ' Set LED pin to output

you are not setting LED to output; you are making both pins low.

Set pins to output by using the TRIS register: -

TRISC.5 = 0
TRISC.6 = 0

I did not try it as I have my dev board in use!

Joe

RGV250

 :-[  :-[  :-[  :-[
Oops, that was a bad copy and paste error, with TRIS it still only flashes the last one it the order, I tried with 3 and the same.

Bob

John Lawton

PORTC.5 and PORTC.6 I/O ports are shared with the MSSP and EUSART peripherals, so make sure those are disabled.

John

Gamboa

Bob,

Try following:

Ports outputs:
TRISC.5 = 0
TRISC.6 = 0

Led definition:
    Symbol BLUE_LED = LATC.5           ' Red LED
    Symbol RED_LED = LATC.6            ' Blue LED

Regards,
Gamboa



Long live for you

RGV250

Hi Gamboa,
More embarrassment, when I originally changed to LAT I did it in the wrong place.

Bob