PDA

View Full Version : 12F675 / MCLR use



Acetronics2
- 3rd September 2009, 19:56
Hi,

Who could explain me that ???

This simple program is a flip-flop with button debouncing ... simple, eh !

( Button1 is on the low side - LOW level if pushed )

When using MCLR ... output ( GPIO.2) is LOW at power-up ... Ok

When disabling MCLR ( internal reset ) ... output is HIGH at power-up ... ???
Instead to what it should be !!!

Did I miss something ???




' Madproject
'
'Anti rebond pour sauter à la perche ( ??? )
'
' 16F629 mode INTOSC @ 4 Mhz
'
' le 03/09/2009 139 Lignes
'************************************************* *****************************
'************************************************* *****************************

'************************************************* *****************************
' CONFIG
'************************************************* *****************************

@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BODEN_ON

DEFINE OSC 4
DEFINE OSCCAL_1K 1
DEFINE BUTTON_PAUSE 100

ADCON0 = 0
ANSEL = 0
CMCON = 7
VRCON = 0
OPTION_REG.5 = 0
OPTION_REG.7 = 1 'Disable Pull-Ups




Bouton1 VAR GPIO.0
Bouton2 VAR GPIO.1
Sortie VAR GPIO.2
'LedVisu VAR GPIO.3 ' Attention : Sortie PIC en C/O !!!
LedVisu VAR GPIO.4
'set VAR GPIO.5

x VAR byte
Delay VAR byte

GPIO = %00000011 'All pins LOW IF outputted - no startup bug.
TRISIO = %00000011 'set GPIO.0 & GPIO.1 as inputs Others Output

'************************************************* *****************************
Attente: ' On attend !!!
'************************************************* *****************************

Delay = 0
BUTTON Bouton1,0,255,0,Delay,1,Action ' Poussoir à la masse enfoncé

PAUSE 10 ' 10 ms entre scans
GOTO Attente ' Non? : retour départ

'************************************************* *****************************
Action: ' On a enfoncé le bouton plus de 100 ms
'************************************************* *****************************

TOGGLE Sortie ' On inverse la sortie
TOGGLE LedVisu

'************************************************* *****************************
Attente2: ' On attend que le bouton soit relâché ...
'************************************************* *****************************

Delay = 0
BUTTON Bouton1,1,255,0,Delay,1,Attente ' Le bouton est il relaché ???
'
GOTO Attente2 ' NON On boucle

'************************************************* *****************************
END



Alain

Melanie
- 3rd September 2009, 21:17
Never trust the state of any I/O on Power-Up - regardless of what the Datasheet says.

Always preset your I/O's within your program to what you want them to be as one of the first things you do when initialising the PIC.

dhouston
- 3rd September 2009, 22:17
From the datasheet...
Figure 3-3 shows the diagram for this pin. The GP3 pin
is configurable to function as one of the following:
• a general purpose input
• as Master Clear Resetand...
bit 5 MCLRE: GP3/MCLR pin function select(5)
1 = GP3/MCLR pin function is MCLR
0 = GP3/MCLR pin function is digital I/O, MCLR internally tied to VDDand from your config fuses...
_MCLRE_ON

Melanie
- 4th September 2009, 00:40
I think Alain is talking about GPIO.2 having an anomally when you configure GPIO.3 (MCLR) for different states. In theory it shouldn't effect that pin...

dhouston
- 4th September 2009, 02:36
I think Alain is talking about GPIO.2 having an anomally when you configure GPIO.3 (MCLR) for different states. In theory it shouldn't effect that pin...
Ahhh! I misunderstood and thought he was trying to make GPIO.3 an output although I expected he would know better. I should have known better.

What happens if the order of the TRISIO = and GPIO = statements are reversed?

Acetronics2
- 4th September 2009, 08:22
Never trust the state of any I/O on Power-Up - regardless of what the Datasheet says.

Always preset your I/O's within your program to what you want them to be as one of the first things you do when initialising the PIC.

Hi, Mel

You do know the only one I trust in, is you, Mel ... ( Violins [ON] , Crooner [ON], Rose Petals drop [ON], Champagne [ON] ... )

I just think you missed my two I/O Config lines ... ( Was late, eh ...)

I must tell it ALSO affects GPIO.4 ... so, I have to try adding a little PAUSE after those CONFIG Lines, I smell a Power on little issue ... That make BUTTON read a low level when power up ...

OR May be a " HIGH GPIO.0 " Command before the first BUTTON Command to ensure the High Level ...

Testing a HIGH level for Button1 pressed is to also an idea ( some capacitive effects on GPIO.0 ??? ... despite it has no load but a Pullup resistor !) ...

But, that's not something " normal " ...

Alain

Acetronics2
- 4th September 2009, 10:18
As I smelled ...

Adding a little PAUSE 50 ( 40 is not enough ! ) just past the I/O config Lines solved the issue ...

HIGH GPIO.0 didn't work ...

Alain ( bug killer ...)