# pic 12f508 GP2 no output

#### ytandy100

Joined Oct 25, 2019
9
i bought some new pic 12f508 chips for a project and found that i could not output on pin 2 , i have looked on various forums and tried all the answers i could find but none worked , i have included the program so you can see what i have and tell me where i went wrong please .

Code:
                                ;   GP2 Test program
list     p=112f508
#include p12f508.inc

__CONFIG 0X0FEA
;
ORG     0
MOVWF    OSCCAL
OPTION    0XDF        ;11011111

;Note: If the T0CS bit is set to ‘1’, it will override
;the TRIS function on the T0CKI pin.

;bit 5 T0CS: Timer0 Clock Source Select bit
;1 = Transition on T0CKI pin (overrides TRIS on the T0CKI pin)
;0 = Transition on internal instruction cycle clock, FOSC/4

;5.3 TRIS Registers
;The Output Driver Control register is loaded with the
;contents of the W register by executing the TRIS f
;instruction. A ‘1’ from a TRIS register bit puts the corresponding
;output driver in a High-Impedance mode. A
;‘0’ puts the contents of the output data latch on the
;selected pins, enabling the output buffer. The exceptions
;are RB3/GP3, which is input only and the T0CKI
;pin, which may be controlled by the OPTION register.
;See Register 4-3 and Register 4-4.

SETUP     MOVLW    0XC0        ;set all 6 bits as output even 3 in only pin
TRIS        GPIO
CLRF        GPIO

MOVLW    0X00
MOVWF    0X18

NEXT    MOVF        0X18,W
INCF        0X18,F
MOVWF    GPIO
;        BSF        GPIO,2        ;to try direct control of port bit
CALL        DELAY
;        BCF        GPIO,2        ;to try direct control of port bit
GOTO        NEXT

DELAY    MOVLW    0X01        ;LONG TIME COUNT (7)
MOVWF    0X15

T0        MOVLW    0X80        ;MED TIME COUNT (00)
MOVWF    0X16

T1        MOVLW    0X00        ;SHORT TIME COUNT (00)
MOVWF    0X17

T2        DECFSZ    0X17,F
GOTO        T2
DECFSZ    0X16,F
GOTO        T1
DECFSZ    0X15,F
GOTO        T0
RETLW     0

END
Moderators note : used code tags

Last edited by a moderator:

#### bertus

Joined Apr 5, 2008
22,097
Hello,

Is this correct : list p=112f508
Or should it be : list p=12f508

Bertus

#### jpanhalt

Joined Jan 18, 2008
11,088
Rge 12F508 doesn't use Banks.

#### jpanhalt

Joined Jan 18, 2008
11,088

Line 39 loads GPIO with 0 then goes to delay and does that again. 0x18 does get incremented, and eventually moves to GPIO, but how long does the delay work out to be? The flash may be too quick.

What happens if you implement lines 40 and 42 and forget about line 38?

Have you stepped through the code in a simulator?

Last edited:

#### ytandy100

Joined Oct 25, 2019
9
thank you for replying , it should be list p=12f508 but it didnt change anything .

#### ytandy100

Joined Oct 25, 2019
9
View attachment 219768

Line 39 loads GPIO with 0 then goes to delay and does that again.

What happens if you implement lines 40 and 42?
thank you for replying , line 39 is out putting contents of 0X18 which is just a counter , that peice of code works as i have LEDs on all 6 pins and only GP2 and GP3 dont work and GP3 is an input only pin but i had to try it , 40 and 42 do nothing .

#### ytandy100

Joined Oct 25, 2019
9
View attachment 219768

Line 39 loads GPIO with 0 then goes to delay and does that again. 0x18 does get incremented, and eventually moves to GPIO, but how long does the delay work out to be? The flash may be too quick.

What happens if you implement lines 40 and 42 and forget about line 38?

Have you stepped through the code in a simulator?
in the simulator the option reg always goes to 0X00 but that shouldnt effect GP2 and everything else seems to work as it should that is GPIO is counting up , the delay is slow enough that i can see GP0 , GP1 , ? ,X , GP4 , GP5 , i have also tried turning the LEDs around and connecting to positive , still no change on GP2 .

#### ytandy100

Joined Oct 25, 2019
9
in the simulator the option reg always goes to 0X00 but that shouldnt effect GP2 and everything else seems to work as it should that is GPIO is counting up , the delay is slow enough that i can see GP0 , GP1 , ? ,X , GP4 , GP5 , i have also tried turning the LEDs around and connecting to positive , still no change on GP2 .
ok , im back again , when i switched to simulator i didnt read the warning and tried to use the chip which didnt work so switched to mplab sim to get results , when i switched back to programmer i got this -
PICkit 3 Connected.
PK3Err0045: You must connect to a target device to use PICkit
3.

The target has invalid calibration data (20).

i then did this
Programming...
Programming/Verify complete

and all outputs now work , any idea why something changed , i tried three chips and no GP2 out then a slight goof and this one works , i have been trying for days to get this working .

#### ytandy100

Joined Oct 25, 2019
9
thank you for all replys , i wouldnt have tried sim and then made a booby that destroyed calibration code at 0X1FF which made the GP2 pin work as output (yes really) , i tried the same using the on chip sim and ignored warnings again and when i go back and reprogram the chip GP2 worked as output , when i tried using pickit3 to reset calibration data GP2 stopped working as output , 0X00 , 0X1F worked (didnt try all just a few) but 0X20 stopped again and the original value was 0X26 , hope this info helps some in the future.
i still dont know what is happening , just that it is

#### ytandy100

Joined Oct 25, 2019
9
Code:
                                ;   GP2 Test program
list     p=12f508
#include p12f508.inc

__CONFIG 0X0FEA
;
ORG     0
MOVWF    OSCCAL

MOVLW    0            ;CALIBRATION DATA WORKS  O.K.. WITH THIS HERE
;i dont know what is using W reg but it upsets GP2

OPTION    0XDF        ;11011111

;Note: If the T0CS bit is set to ‘1’, it will override
;the TRIS function on the T0CKI pin.

;bit 5 T0CS: Timer0 Clock Source Select bit
;1 = Transition on T0CKI pin (overrides TRIS on the T0CKI pin)
;0 = Transition on internal instruction cycle clock, FOSC/4

;5.3 TRIS Registers
;The Output Driver Control register is loaded with the
;contents of the W register by executing the TRIS f
;instruction. A ‘1’ from a TRIS register bit puts the corresponding
;output driver in a High-Impedance mode. A
;‘0’ puts the contents of the output data latch on the
;selected pins, enabling the output buffer. The exceptions
;are RB3/GP3, which is input only and the T0CKI
;pin, which may be controlled by the OPTION register.
;See Register 4-3 and Register 4-4.

SETUP     MOVLW    0XC0        ;set all 6 bits as output even 3 in only pin
TRIS        GPIO
CLRF        GPIO

MOVLW    0X00
MOVWF    0X18

NEXT    MOVF        0X18,W
INCF        0X18,F
MOVWF    GPIO
;        BSF        GPIO,2        ;to try direct control of port bit
CALL        DELAY
;        BCF        GPIO,2        ;to try direct control of port bit
GOTO        NEXT

DELAY    MOVLW    0X01        ;LONG TIME COUNT (7)
MOVWF    0X15

T0        MOVLW    0X80        ;MED TIME COUNT (00)
MOVWF    0X16

T1        MOVLW    0X00        ;SHORT TIME COUNT (00)
MOVWF    0X17

T2        DECFSZ    0X17,F
GOTO        T2
DECFSZ    0X16,F
GOTO        T1
DECFSZ    0X15,F
GOTO        T0
RETLW     0

;    MOVLW    0X06

END

#### ytandy100

Joined Oct 25, 2019
9
im back , one last time , i will put up the whole code again but it is only a small change

#### jpanhalt

Joined Jan 18, 2008
11,088
If you had given a decent description of the problem, as in your post #6 originally, we might have been of more help.

I started with the 12F508 many years ago and am quite familiar with it. I used the osc. calibration to fine tune it. Obviously, you realized that GP3 is input only. As for the correction in code, I am anxious to see it.