PDA

View Full Version : PIC16F628 Port B.4 Problem



Tinkerer13
- 30th April 2012, 15:32
Hi-

I cannot find what I am missing. I cannot control Port B.4, it acts as an input and interrupts the program flow. I have code below that shows the problem:

' Device Settings
@ DEVICE PIC16F628 ' PIC Device
@ DEVICE EC_OSC ' External Oscillator
@ DEVICE LVP_OFF ' Low-Voltage Programming
@ DEVICE WDT_OFF ' Watchdog Timer
@ DEVICE PWRT_ON ' Power-On Reset
@ DEVICE MCLR_OFF ' Master Clear
@ DEVICE BOD_OFF ' Brown-Out Detect
@ DEVICE CPD_OFF ' Data Memory Code Protection
@ DEVICE PROTECT_OFF ' Program Code Protection
' Set Environment Variables
DEFINE OSC 20 ' Oscillator speed, 20MHz
TRISA = %00000000 ' Port A All Outputs
TRISB = %00000000 ' Port B All Outputs
' Main Program
PortB = $FF ' Port B All Set High
PortB.4 = 1 ' B4 Set High

While (1)
toggle PortA.0 ' Heartbeat
pause 250
WEND
END


When I run this, all port B goes high except B.4. I have tried to use a pull-up, in case it is open collector, but that stops the heartbeat. I have tried several different 628s, and they all act the same. I figure it must be a fuse set wrong, but I don't know what.

Any help would be gratefully accepted!

Darrel Taylor
- 30th April 2012, 21:42
Although your configuration shows LVP_OFF, it's possible that the configuration is not getting programmed into the chip.
With LVP enabled, if B4 (PGM) goes high it puts the chip in programming mode.

What programmer are you using?
And is it set to program the configuration bits?

Demon
- 1st May 2012, 02:36
Is it Port B.4 that you want to toggle? Port A has analog features, you have to disable them first.

As it is, you set it high and leave it.

By the way, you don't have to set B.4 high after setting all of Port B high, it's already high.

Robert

EDIT: Aren't we supposed to use XT for 20mhz external oscillators? Can't remember, sure I read something about that tonight.

Tinkerer13
- 1st May 2012, 14:48
Hi again-

I'm using the melabs Serial Programmer (2003) which has served me for many years. I agree that it looks like the LVP fuse is being ignored. Is there a way to check its state? Is there an alternative way to set it?

As to the program itself, yes, setting both port B and B.4 high is redundant, but the output is low. That is the problem in a nutshell. Toggling A.0 shows me whether the program is running (which it does not seem to be doing).

Thanks again!

Tinkerer13
- 1st May 2012, 14:53
Never mind, I found it. Darryl was right, the programmer is ignoring my fuse settings. Setting them manually takes care of the issue.

Sorry for the bother. =)