switch ?


Closed Thread
Results 1 to 6 of 6

Thread: switch ?

  1. #1
    Join Date
    Jul 2011
    Posts
    29

    Default switch ?

    Hello,

    I'm trying to play with my pic and active some outputs with a switch, but it does not work... I do not see what I am doing wrnog here... can someone help me to figure it out ? it must be something silly ?! (using a pic18F4331)

    Code:
    TRISA  = %00000001
    TRISB  = %00000000
    TRISC  = %00000000
    TRISD  = %00000000
    TRISE  = %00000000 
    
    
    '-> I/O Symbols
    
    Symbol switch       PORTA.0 'IN
    Symbol led1         PORTB.5 'OUT  
    Symbol led2         PORTB.4 'OUT  
    Symbol led3         PORTB.3 'OUT  
    Symbol led4         PORTB.2 'OUT  
    Symbol led5         PORTB.1 'OUT  
    Symbol led6         PORTB.0 'OUT  
    
    Symbol led7         PORTD.7 'OUT 
    Symbol led8         PORTD.6 'OUT 
    Symbol led9         PORTD.5 'OUT 
    Symbol led10        PORTD.4 'OUT 
    Symbol led11        PORTC.7 'OUT 
    Symbol led12        PORTC.6 'OUT 
    
    Low led1
    Low led2
    Low led3
    Low led4
    Low led5
    Low led6
    Low led7
    Low led8
    Low led9
    Low led10
    Low led11
    Low led12
    
    GoTo Main
    
    Main: 
    If switch = 1 Then
        High led7
        Else
        Low led7
    EndIf 
     
    GoTo Main

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    645


    Did you find this post helpful? Yes | No

    Default Re: switch ?

    Can you show your schematics?
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: switch ?

    i'm sorry I am at university, and can't scan my schematics right now. But just to let you know I can successfully run this program on an 16F877...
    I really don't know where is the problem. I do the PWM on the 18F but it seems it's not taking the instruction "IF" ??...
    Thank you anyway...
    If anyone else has a hint or something ?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: switch ?

    Problem #1: RA0 (and more pins) are anlog inputs by default at power-up, and all pins configured as analog inputs will read 0 when used for digital I/O.

    Solution = ANSEL0 = 0

    Problem #2: This can cause read-modify-write issues since you have all pin aliases pointing to port pins VS port LATches;

    Low led1
    Low led2
    Low led3
    Low led4
    Low led5
    Low led6
    Low led7
    Low led8
    Low led9
    Low led10
    Low led11
    Low led12

    Change your pin aliases to LAT like this and include the = sign;

    Symbol led1 = LATB.5 'OUT, etc.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: switch ?

    Thank you very much for your answer ! it works now !
    If I need help again about another thing should I start another thread ? (gonna need to change duty cycle of pwm with potentiometer)
    however, I do not want to be invasive.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: switch ?

    You're welcome. For your other question, just continue on in the previous thread you started here http://www.picbasic.co.uk/forum/showthread.php?t=15149

    This isn't exactly what you asked for, but here's a link to another thread for using the A/D on this PIC http://www.picbasic.co.uk/forum/showthread.php?t=6768
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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