Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F628 output 2V on high

Status
Not open for further replies.

Robin91

New Member
Hello,

Im trying to program a PIC16F628, but when set any pin on high, they output 4,5V (VDD) for a few seconds (random) and then drop down to 2V.
I have tryd this with 2 of these PIC's and both have the same problem.

Code (Hi-tech compiler):
Code:
#include <pic.h>
#include <htc.h>
#ifndef _XTAL_FREQ
 #define _XTAL_FREQ 4000000
#endif

__CONFIG(0x3F38);


void main(){
	TRISA=0b00000000;
	PORTA=0b11111111;
	TRISB=0b00000000;
	PORTB=0b11111111;
	
	while(1){
		
	}
}


Assembly spewed out by the compiler
Code:
opt subtitle "HI-TECH Software Omniscient Code Generator (Lite mode) build 7503"

opt pagewidth 120

	opt lm

	processor	16F628
clrc	macro
	bcf	3,0
	endm
clrz	macro
	bcf	3,2
	endm
setc	macro
	bsf	3,0
	endm
setz	macro
	bsf	3,2
	endm
skipc	macro
	btfss	3,0
	endm
skipz	macro
	btfss	3,2
	endm
skipnc	macro
	btfsc	3,0
	endm
skipnz	macro
	btfsc	3,2
	endm
indf	equ	0
indf0	equ	0
pc	equ	2
pcl	equ	2
status	equ	3
fsr	equ	4
fsr0	equ	4
c	equ	1
z	equ	0
pclath	equ	10
# 9 "C:\Users\Robin\Desktop\LightProject\TimeController\main.c"
	psect config,class=CONFIG,delta=2 ;#
# 9 "C:\Users\Robin\Desktop\LightProject\TimeController\main.c"
	dw 0x3F70 ;#
	FNROOT	_main
	global	_cycle1
	global	_cycle2
	global	_CMCON
psect	maintext,global,class=CODE,delta=2
global __pmaintext
__pmaintext:
_CMCON	set	31
	global	_PORTA
_PORTA	set	5
	global	_PORTB
_PORTB	set	6
	global	_RA0
_RA0	set	40
	global	_RA1
_RA1	set	41
	global	_RA3
_RA3	set	43
	global	_RA4
_RA4	set	44
	global	_TRISA
_TRISA	set	133
	global	_TRISB
_TRISB	set	134
	file	"TimeController.as"
	line	#
psect cinit,class=CODE,delta=2
global start_initialization
start_initialization:

psect	bssCOMMON,class=COMMON,space=1
global __pbssCOMMON
__pbssCOMMON:
_cycle1:
       ds      2

_cycle2:
       ds      2

; Clear objects allocated to COMMON
psect cinit,class=CODE,delta=2
	clrf	((__pbssCOMMON)+0)&07Fh
	clrf	((__pbssCOMMON)+1)&07Fh
	clrf	((__pbssCOMMON)+2)&07Fh
	clrf	((__pbssCOMMON)+3)&07Fh
psect cinit,class=CODE,delta=2
global end_of_initialization

;End of C runtime variable initialization code

end_of_initialization:
clrf status
ljmp _main	;jump to C main() function
psect	cstackCOMMON,class=COMMON,space=1
global __pcstackCOMMON
__pcstackCOMMON:
	global	?_main
?_main:	; 0 bytes @ 0x0
	global	??_main
??_main:	; 0 bytes @ 0x0
;;Data sizes: Strings 0, constant 0, data 0, bss 4, persistent 0 stack 0
;;Auto spaces:   Size  Autos    Used
;; COMMON          14      0       4
;; BANK0           80      0       0
;; BANK1           80      0       0
;; BANK2           48      0       0

;;
;; Pointer list with targets:



;;
;; Critical Paths under _main in COMMON
;;
;;   None.
;;
;; Critical Paths under _main in BANK0
;;
;;   None.
;;
;; Critical Paths under _main in BANK1
;;
;;   None.
;;
;; Critical Paths under _main in BANK2
;;
;;   None.

;;
;;Main: autosize = 0, tempsize = 0, incstack = 0, save=0
;;

;;
;;Call Graph Tables:
;;
;; ---------------------------------------------------------------------------------
;; (Depth) Function   	        Calls       Base Space   Used Autos Params    Refs
;; ---------------------------------------------------------------------------------
;; (0) _main                                                 0     0      0       0
;; ---------------------------------------------------------------------------------
;; Estimated maximum stack depth 0
;; ---------------------------------------------------------------------------------

;; Call Graph Graphs:

;; _main (ROOT)
;;

;; Address spaces:

;;Name               Size   Autos  Total    Cost      Usage
;;BITCOMMON            E      0       0       0        0.0%
;;EEDATA              80      0       0       0        0.0%
;;NULL                 0      0       0       0        0.0%
;;CODE                 0      0       0       0        0.0%
;;COMMON               E      0       4       1       28.6%
;;BITSFR0              0      0       0       1        0.0%
;;SFR0                 0      0       0       1        0.0%
;;BITSFR1              0      0       0       2        0.0%
;;SFR1                 0      0       0       2        0.0%
;;STACK                0      0       0       2        0.0%
;;BANK0               50      0       0       3        0.0%
;;BITSFR3              0      0       0       4        0.0%
;;SFR3                 0      0       0       4        0.0%
;;ABS                  0      0       4       4        0.0%
;;BITBANK0            50      0       0       5        0.0%
;;BITSFR2              0      0       0       5        0.0%
;;SFR2                 0      0       0       5        0.0%
;;BITBANK1            50      0       0       6        0.0%
;;BANK1               50      0       0       7        0.0%
;;BITBANK2            30      0       0       8        0.0%
;;BANK2               30      0       0       9        0.0%
;;DATA                 0      0       4      10        0.0%

	global	_main
psect	maintext

;; *************** function _main *****************
;; Defined at:
;;		line 13 in file "C:\Users\Robin\Desktop\LightProject\TimeController\main.c"
;; Parameters:    Size  Location     Type
;;		None
;; Auto vars:     Size  Location     Type
;;		None
;; Return value:  Size  Location     Type
;;		None               void
;; Registers used:
;;		wreg, status,2
;; Tracked objects:
;;		On entry : 17F/0
;;		On exit  : 0/0
;;		Unchanged: 0/0
;; Data sizes:     COMMON   BANK0   BANK1   BANK2
;;      Params:         0       0       0       0
;;      Locals:         0       0       0       0
;;      Temps:          0       0       0       0
;;      Totals:         0       0       0       0
;;Total ram usage:        0 bytes
;; This function calls:
;;		Nothing
;; This function is called by:
;;		Startup code after reset
;; This function uses a non-reentrant model
;;
psect	maintext
	file	"C:\Users\Robin\Desktop\LightProject\TimeController\main.c"
	line	13
	global	__size_of_main
	__size_of_main	equ	__end_of_main-_main
	
_main:	
	opt	stack 8
; Regs used in _main: [wreg+status,2]
	line	14
	
l1232:	
;main.c: 14: CMCON = 0x7;
	movlw	(07h)
	bcf	status, 5	;RP0=0, select bank0
	bcf	status, 6	;RP1=0, select bank0
	movwf	(31)	;volatile
	line	15
	
l1234:	
;main.c: 15: TRISA=0b00000000;
	bsf	status, 5	;RP0=1, select bank1
	bcf	status, 6	;RP1=0, select bank1
	clrf	(133)^080h	;volatile
	line	16
	
l1236:	
;main.c: 16: PORTA=0b11111111;
	movlw	(0FFh)
	bcf	status, 5	;RP0=0, select bank0
	bcf	status, 6	;RP1=0, select bank0
	movwf	(5)	;volatile
	line	17
;main.c: 17: TRISB=0b00000000;
	bsf	status, 5	;RP0=1, select bank1
	bcf	status, 6	;RP1=0, select bank1
	clrf	(134)^080h	;volatile
	line	18
	
l1238:	
;main.c: 18: PORTB=0b11111111;
	movlw	(0FFh)
	bcf	status, 5	;RP0=0, select bank0
	bcf	status, 6	;RP1=0, select bank0
	movwf	(6)	;volatile
	goto	l795
	line	20
;main.c: 20: while(1){
	
l794:	
	line	24
	
l795:	
	line	20
	goto	l795
	
l796:	
	line	25
	
l797:	
	global	start
	ljmp	start
	opt stack 0
GLOBAL	__end_of_main
	__end_of_main:
;; =============== function _main ends ============

	signat	_main,88
psect	maintext
	global	btemp
	btemp set 07Eh

	DABS	1,126,2	;btemp
	global	wtemp0
	wtemp0 set btemp
	end

The chip is connected to 4.5V and ground, and MCLR is directly connected to the according pin. (Did not work with pullup resistor).
The code seems to work, but the output voltage is just weird.

Does anyone have any solutions?
Thanks in advance.
 
Last edited:
After looking at the data sheet i think what your doing is fine... But are your config bits correct? if its around 2V it may be floating, which means the chip is ON but it never executed your code... In this case you may want to double check that your clock is working if your using a crystal, or that the internal OSC bits are right....

TRY this __CONFIG(0x3F70); and let me know
 
Last edited:
When i put the ports on low they stay around 0V so they are not floating i think.
Im using the internal OSC:
**broken link removed**

The config changed nothing.
The pin stays 4.5 a few seconds then drops to 3 and counts down to 2.
 
Last edited:
What does "MCLR is directly connected to the according pin" mean?
What is connected to the pins?

Edit, Can you change your config to something that is readable by humans such as,
__CONFIG(INTIO & WDTDIS & PWRTEN & BOREN & LVPDIS & UNPROTECT);
Check the manual for details.

Mike.
 
Last edited:
MCLR is connected to the programming voltage of my PIC programmer.
Im using a clone of PICKIT3 as programmer.
 
I think you need to turn the comparator Off to make all the I/Os digital.

CMCON = 0x7
 
Thank you, but still nothing appear to have changed.
Except that they dont start at 4,5V anymore but now start with 2V.
also port RA4 stays 0 for some reason.
 
Thank you, thats one mistery solved.
Now, does anyone know why the PIC have 2V as output on high?
Thank you very much for the help.
 
I’m not sure whether you’ve solved the problem or not, but in any case reading this may help you in dealing with PIC
 
The problem is still not solved but i found out 2V is just enough to be regonised as high by the other IC's.
Good article, i will pull(up/down) all pins in my circuit.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top