PDA

View Full Version : 12F683 GPIO.3 MCLR pin - unusual response



dw_picbasic
- 19th December 2020, 08:52
Today I setup a 12F683 hoping to read pins 2,3, and 4 masked out as a 3-bit word.
I set the chip's bit config to turn off MCLR on pin 4 gpio.3

Pin 4 when not used as a MCLR reset functions as input only.
So I set pins 2, and 3 also as inputs

Then I put 10K resistors on each - pulling them down to ground.
I then set the code to read GPIO and mask out all the other pins.
Then right-shifted the results to derive the lowest 3 bits

Pulling any combination of these 3 pins high should result in values ranging 0-7.

Pins 2, and 3 acted as expected.
However, the MCLR pin was acting flaky.
Even with the pull down resistor on it - it was flipping back and forth between a high and low reading.
I've never seen this before.

I dug through the datasheet to see if I could find something peculiar about pin-4 MCLR with no success.

Ioannis
- 21st December 2020, 01:21
GP3 does not have any other function except MCLR if set to.

So the erratic behavior may be related to the software. Show the code please.

Ioannis

dw_picbasic
- 21st December 2020, 13:58
GP3 does not have any other function except MCLR if set to.

So the erratic behavior may be related to the software. Show the code please.

Ioannis

Thank you Ioannis!
A funny thing happened to me on the way to re-turning to this....... This morning it worked as I would have expected.
And I couldn't reproduce the previous behavior.
But I do thank you for prompting me.
I would have otherwise thought wrong about the chip.

Here is the code and use case:
I have a re-built Nintendo game controller.
It originally had a 4021 shift-register which died.
So I removed that part and replaced it with 6 germanium diodes - which convert 6 possible button presses to a 3-bit binary word (0-7)
For my test bench I have a pic-based LCD display I use as a Serial Monitor



' Name : 12F683_DiodeSwitchControl_SerialLCD-DisableMCLR.pbp
' Compiler : PBP3
' Target PIC : PIC12F683
' Oscillator : 4MHz internal
' Description : Diode Switch matrix 6 switches to 3bit binary
' Note: Disable MCLR_reset function PIN-4 to use this pin as input
' Send Output to Serial LCD

'1 VDD
'2 GP5/T1CKI/OSC1/CLKIN
'3 GP4/AN3/T1G/OSC2/CLKOUT
'4 GP3/MCLR/VPP
'5 GP2/AN2/T0CKI/INT/COUT/CCP1
'6 GP1/AN1/CIN-/VREF/ICSPCLK
'7 GP0/AN0/CIN+/ICSPDAT/ULPWU
'8 VSS

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
#ENDCONFIG

Include "modedefs.bas" ' Mode definitions for Serout

' Alias pins
LCD Con 0 ' Alias GPIO.0 to Serial LCD

' INIT global variables
SwitchNum Var Word

' Function Registers Setup
ANSEL = 0 ' Disable analog A/D functions
CMCON0 = 7 ' Analog comparators off
TRISIO = %00001110 ' GPIO.1,2,3 inputs - others outputs - and GP0 feeds LCD
GPIO = 0 ' Flush GPIO

' MAIN PROGRAM
mainloop:
Serout LCD, T9600, ["?c0"] ' Turn off flashing cursor
pause 50
Serout LCD, T9600, ["?f"] ' Clear screen start at leftmost cell
pause 50
Serout LCD, T9600, ["READY"]
pause 1000

DO WHILE (1)
Serout LCD, T9600, ["?f"] ' Clear screen start at leftmost cell
SwitchNum = GPIO & %00001110 'Capture GPIO(1,2,3) binary value
SwitchNum = SwitchNum >> 1


Serout LCD, T9600, [#SwitchNum]
Pause 50

LOOP
Goto mainloop ' Do it forever

End