PORTB vs PORTB.0


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2007
    Posts
    4

    Default PORTB vs PORTB.0

    Can some one tell me why this code works

    Code:
    OSCCON = %01100010
    ADCON1 = %01111111
    
        TRISB = 0
            
        loop:   
            Pause 500       ' Wait .5 second
            PORTB.3 = 1
            Pause 500       ' Wait .5 second
            PORTB.3 = 0
        Goto loop
        
    END
    And this code works as well ...

    Code:
    OSCCON = %01100010
    ADCON1 = %01111111
    
        TRISB = 0
            
        loop:   
            Pause 500       ' Wait .5 second
            PORTB = %11111111
            Pause 500       ' Wait .5 second
            PORTB = %00000000
        Goto loop
        
    END
    But this code does not...

    Code:
    OSCCON = %01100010
    ADCON1 = %01111111
    
        TRISB = 0
            
        loop:   
            Pause 500       ' Wait .5 second
            PORTB = 1
            Pause 500       ' Wait .5 second
            PORTB = 0
        Goto loop
        
    END
    I tried searching for the answer and I could not find anything. Maybe I don't know how to search properly.

    Thanks in advance,
    Matt

    p.s. I'm using a pic18f1320 and programming it using the PICKIT 2
    p.s.s. Sorry if this post is in the wrong forum
    Last edited by xzolian; - 4th March 2007 at 00:00. Reason: added another code example

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    the second will toggle the PORTB.0 bit while the first toggle PORTB.3 bit. If you don't have LED on all PORTB pins, the problem is as this simple.

    Or once again i miss something obvious
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    I have placed an LED on pin 3 of port b. When I used these statements:
    PORTB.3 = 1 or PORTB = %11111111
    The LED on pin 3 of port b turns on.

    But when I use this statement:
    PORTB = 1
    The LED does not turn on.

    How can I set all of port b high or low with one statement?

  4. #4
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    PORTB = 1 = %00000001
    PORTB = 0 = %00000000
    Each bit equals a port pin. You are changing PORTB.0 only. If you wanted to change only bit 3, then it would be PORTB = %00001000

  5. #5
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ron Marcus View Post
    PORTB = 1 = %00000001
    PORTB = 0 = %00000000
    Each bit equals a port pin. You are changing PORTB.0 only. If you wanted to change only bit 3, then it would be PORTB = %00001000
    Or PORTB = 8
    Keith

    www.diyha.co.uk
    www.kat5.tv

  6. #6
    Join Date
    Mar 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    So if I do this...
    PORTB = 255

    Would it set all of PORTB high?

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yes indeed!

    PORTB=255 ' decimal
    PORTB=$FF 'Hexadecimal
    PORTB=%11111111 ' Binary

    P.S.: it's a good practice to set your PIC configuration fuses in your code.
    Code:
            '
            '       Pic Configuration
            '       =================
            asm
            
            __CONFIG  _CONFIG1H, _IESO_ON_1H & _FSCM_OFF_1H & _INTIO2_OSC_1H
                    ;
                    ;_IESO_ON_1H       Internal External Oscillator Switch Over mode enabled
                    ;_FSCM_OFF_1H      Fail-Safe Clock Monitor disabled
                    ;_INTIO2_OSC_1H    Internal RC, OSC1 as RA7, OSC2 as RA6
    
            __CONFIG  _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_27_2L
                    ;
                    ;_BORV_27_2L       BOR Voltage - 2.7v
                    ;_BOR_ON_2L        Brown-out Reset enabled
                    ;_PWRT_ON_2L       Power-up Timer enabled
    
            __CONFIG  _CONFIG2H, _WDT_OFF_2H & _WDTPS_32K_2H
                    ;
                    ;_WDT_OFF_2H       Watch Dog Timer disabled
                    ;_WDTPS_32K_2H     1:32,768    WDT Postscaler ratio
                    
            __CONFIG  _CONFIG3H, _MCLRE_ON_3H
                    ;
                    ;_MCLRE_ON_3H      MCLR enabled, RA5 input disabled
                    
            __CONFIG  _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_ON_4L
                    ;
                    ;_DEBUG_OFF_4L     BacKground deBUGger disabled
                    ;_LVP_OFF_4L       Low Voltage Prgramming disabled
                    ;_STVR_ON_4L       Stack over/underflow Reset enabled
                            
            __CONFIG  _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    
            __CONFIG  _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    
            __CONFIG  _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
                    
            __CONFIG  _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
                    
            __CONFIG  _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
                   
            __CONFIG  _CONFIG7H, _EBTRB_OFF_7H
            ENDASM
    There's a whole thread about that bellow. Take your time to read it.
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Last edited by mister_e; - 4th March 2007 at 00:27.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Mar 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help everyone.

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. MY FIRST scrolling 8X8 LED
    By earltyso in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th August 2008, 16:23
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

Members who have read this thread : 0

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