Simple LED driving issue - setup?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171

    Default Simple LED driving issue - setup?

    I'm trying to drive six LEDs as an indicator, but cannot figure out quite what I'm doing wrong. If I use this as my code:

    portb = %1
    pause 100
    portb = %10
    pause 100
    portb = %100
    pause 100
    portb = %1000
    pause 100
    portb = %10000
    pause 100
    portb = %100000
    pause 100
    portb = 0

    Leds on PORTB.1 & B.2 do not light, all the others light as they should, however if I use the following as my code B.1 & B.2 light up as they should

    portb = %1
    pause 100
    portb = %11
    pause 100
    portb = %111
    pause 100
    portb = %1111
    pause 100
    portb = %11111
    pause 100
    portb = %111111
    pause 100
    portb = 0

    Any thoughts - I have come across this issue before and never managed to get it sorted so clearing it up would be great. Any help greatly appreciated. The PIC is a PIC16F722 and my setup is as follows:

    @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _CP_OFF & _MCLRE_OFF & _BOR_OFF

    define osc 4

    '****************
    ' Hardware Setup
    '****************
    ADCON0 = 0
    ANSELA = 0
    ANSELB = 0
    OSCCON = %00010000 '4MHz
    CPSCON0 = 0 'Capacitive sensing off
    PORTA = %10000000
    TRISA = %01000001
    PORTB = %00000000
    TRISB = %11000000
    PORTC = %10000100
    TRISC = %10000000

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Simple LED driving issue - setup?

    It is probably a read-modify-write issue.

    Try -

    TRISB = $FF
    PORTB= $FF

    TRISB.0 = %11111110
    Pause 100
    TRISB.0 = %11111101
    Pause 100
    TRISB.0 = %11111011
    Pause 100
    TRISB.0 = %11110111


    ...
    Charles Linquist

  3. #3
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default Re: Simple LED driving issue - setup?

    Thanks Charles, My bad sorry - one of those pesky solder bridges your code helped me find the problem tho.

    Sorry for posting this when it was a silly wiring fault on my part

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts