PDA

View Full Version : PortB pins will not initialize LOW, only HIGH?



ronbowalker
- 7th December 2009, 14:32
I am trying to initialize a PIC16F819 and it will not take the PORTB pins to a LOW setting on initialization. It does PORTA just fine, and it does both TRISA and TRISB settings correctly. What is it I am missing here?

'CODE:
'Initialize Inputs/Outputs
TRISA = %01110100
TRISB = %01000000
'Initialized Highs/Lows
PORTA = %10000001
PORTB = %00000000

I have also tried to use the (PORTB.0 = 0) way, and it too does not work.
Neither does (LOW PORTB.0).

Never had this problem with any of the other chips I have used.

Here is the .INC file info for MPASM......
__CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF

Archangel
- 8th December 2009, 02:51
I am trying to initialize a PIC16F819 and it will not take the PORTB pins to a LOW setting on initialization. It does PORTA just fine, and it does both TRISA and TRISB settings correctly. What is it I am missing here?

'CODE:
'Initialize Inputs/Outputs
TRISA = %01110100
TRISB = %01000000
'Initialized Highs/Lows
PORTA = %10000001
PORTB = %00000000

I have also tried to use the (PORTB.0 = 0) way, and it too does not work.
Neither does (LOW PORTB.0).

Never had this problem with any of the other chips I have used.

Here is the .INC file info for MPASM......
__CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
Hello ronbowalker,
enable the port latches Before the tris registers. Disable the other functions on these port pins especially any analog functions like CCP. CCP1CON = 0 SSPCON.5 = 0 ' disables Syncro. serial port

"When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORTB pin. Some
peripherals override the TRIS bit to make a pin an output,
while other peripherals override the TRIS bit to
make a pin an input. Since the TRIS bit override is in
effect while the peripheral is enabled, read-modifywrite
instructions (BSF, BCF, XORWF) with TRISB as
the destination should be avoided. The user should
refer to the corresponding peripheral section for the
correct TRIS bit settings."

peterdeco1
- 8th December 2009, 19:27
Hi Ronbowalker. Use this header at the top of your program. I have never had a problem with it.

OSCCON = $60 'sets int osc to 4mhz
adcon1 = 7 ' set inputs to digital. adcin command will convert to analog
@ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON

Then add your program code.