PDA

View Full Version : PORTB vs PORTB.0



xzolian
- 3rd March 2007, 23:52
Can some one tell me why this code works



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 ...



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...



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

mister_e
- 3rd March 2007, 23:59
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 :D

xzolian
- 4th March 2007, 00:09
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?

Ron Marcus
- 4th March 2007, 00:10
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

keithdoxey
- 4th March 2007, 00:19
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

xzolian
- 4th March 2007, 00:22
So if I do this...
PORTB = 255

Would it set all of PORTB high?

mister_e
- 4th March 2007, 00:22
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.


'
' 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

xzolian
- 4th March 2007, 00:33
Thanks for the help everyone.