Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 11th April 2008, 03:54 PM   (permalink)
Default PIC16F627A Blink issue

As i am starting to practice on more chips i use the blink as a start... But i ran into a issue... it doesnt want to blink just stays on solid... and since i can not debug with out a ICD 2 well... i cant debug lol here is my code

Code:
	list      p=16f627A           ; list directive to define processor
	#include <P16F627A.inc>       ; processor specific variable definitions
	__CONFIG   0x3f78 ;_CP_OFF & _DATA_CP_OFF & _LVP_OFF & _WDT_OFF & _INTOSC_OSC_CLKOUT 

	cblock 0x00
	d1
	d2
	d3
	endc

	ORG     0x00			; processor reset vector
Main
	clrf	PORTA			;Initialize PORTA by setting output data latches
	movlw	0x07 			;Turn comparators off and
	movwf	CMCON 			;enable pins for I/O functions
   	bsf 	STATUS, RP0		;select bank 1
	movlw	0x1D			;data direction
	movwf	TRISA			;set PortA all outputs
	bsf	PCON, 3			;OSCF: INTOSC oscillator frequency bit: 1=4 MHz typical
	bcf	STATUS, RP0		;select bank 0

Loop	
	bsf	PORTA, 1		;set RA1 High
	call	Delay
	bcf	PORTA, 1		;set RA1 Low
	goto	Loop			;go back and do it again

Delay
	movlw	0x03
	movwf	d1
	movlw	0x18
	movwf	d2
	movlw	0x02
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0
	goto	$+1
	return
	END				; directive 'end of program'
AtomSoft is offline   Reply With Quote
Old 11th April 2008, 04:09 PM   (permalink)
Default

Well it is obvious, after bsf PORTA,1 you call delay but after bcf PORTA,1 you forgot to call it again and jump to Loop which sets the output to 1 again.

Petr
petrv is offline   Reply With Quote
Old 11th April 2008, 04:11 PM   (permalink)
Default

Quote:
Originally Posted by petrv
Well it is obvious, after bsf PORTA,1 you call delay but after bcf PORTA,1 you forgot to call it again and jump to Loop which sets the output to 1 again.
Well spotted!
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now   Reply With Quote
Old 11th April 2008, 04:12 PM   (permalink)
Default

[quote=AtomSoft]As i am starting to practice on more chips i use the blink as a start... But i ran into a issue... it doesnt want to blink just stays on solid... and since i can not debug with out a ICD 2 well... i cant debug lol here is my code

The ICD2 can't debug the 16F628A either, it doesn't have debug support built in. The 16F88 does though.

Of course you could simply simulate it in MPLAB.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 11th April 2008, 04:16 PM   (permalink)
Default

RAM starts at 0x20 on the 16F627A PIC
Code:
    list      p=16f627A           ; list directive to define processor
    #include <P16F627A.inc>       ; processor specific variable definitions
    __CONFIG  _WDT_OFF & _INTOSC_OSC_NOCLKOUT

    cblock 0x20
    d1,d2,d3
    endc

    ORG     0x00            ; processor reset vector
Main
    clrf    PORTA            ;Initialize PORTA by setting output data latches
    movlw    0x07             ;Turn comparators off and
    movwf    CMCON             ;enable pins for I/O functions
       bsf     STATUS, RP0        ;select bank 1
    movlw    0x1D            ;data direction
    movwf    TRISA            ;set PortA all outputs
    bsf    PCON, 3            ;OSCF: INTOSC oscillator frequency bit: 1=4 MHz typical
    bcf    STATUS, RP0        ;select bank 0

Loop    
    bsf    PORTA, 1        ;set RA1 High
    call    Delay
    bcf    PORTA, 1        ;set RA1 Low
    goto    Loop            ;go back and do it again

Delay
    movlw    0x03
    movwf    d1
    movlw    0x18
    movwf    d2
    movlw    0x02
    movwf    d3
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay_0
    goto    $+1
    return
    END                ; directive 'end of program'    END
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 11th April 2008 at 04:19 PM.
blueroomelectronics is offline   Reply With Quote
Old 11th April 2008, 04:17 PM   (permalink)
Default

Not 100% true, ICD2 *can* debug it but not alone, it is necessary to buy a special adapter from Microchip (AC162053) - costs about $35 - that allows you to debug code for 627A/628A/648A.

Of course 16F88 can be debugged with ICD2 or PicKit2 alone, without any additional hardware.

Petr
petrv is offline   Reply With Quote
Old 11th April 2008, 04:33 PM   (permalink)
Default

ok thanks guys i cant believe i missed something so small and yeah i know it starts at 0x20 but just habit of 00 lol thanks.
AtomSoft is offline   Reply With Quote
Old 11th April 2008, 08:21 PM   (permalink)
Default

ICD? Learn to use the simulator in the IDE very very good period. A few taps of the single step F7 key would have solved this in under 30 seconds. I never actually used ICD, do not know how, don't want to know.

Standardize your delays. Make a set for micro seconds, milli seconds, and seconds similar to my code below.
Code:
Set LED
Call usec100
Call usec100
Clear LED
Call usec100
Call usec100
Loop

movlw .50
movw milli_time        ; Load milli_time only once because it is persisted into milli_time_temp.
Set LED                ; A.K.A non-volatile.
Call milli_delay
Clear LED
Call milli_delay
Loop


Code:
USEC_10:
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	RETURN
USEC_20:
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	GOTO	$ + 1
	RETURN
USEC_100:			;----FORMULA--4MHZ CLOCK---------
	MOVLW	.31		;  [3(CNTJ-1)+2] + CHANGE
	MOVWF	CNTJ		;  CHANGE = 8 USEC
	DECFSZ	CNTJ, F		;  [3(CNTJ-1)+2] + 8
	GOTO	$ - 1	        ;--------------------------------
	NOP
	NOP
	RETURN

MS_DELAY:
	MOVF	MILLI_TIME, W    ;---------------------------------------
        MOVW    MILLI_TIME_TEMP  ;MILLI SECOND DELAY
MS_LOOP	MOVLW	0XA4             ;DELAY = X MILLI-SECOND (4MHZ CLOCK).
	MOVWF	CNTJ             ;---------------------------------------
	DECFSZ	CNTJ, F
	GOTO	$ - 1
	MOVLW	0XA4
	MOVWF	CNTJ
	DECFSZ	CNTJ, F
	GOTO	$ - 1

	DECFSZ	MS_TIME_TEMP, F	;IF COUNTER ENDS,
	GOTO	MS_LOOP		;ELSE- REPEAT
	RETURN			;THEN- EXIT LOOP
See my last signature line below. ===========================\/

Last edited by donniedj; 11th April 2008 at 08:36 PM.
donniedj is offline   Reply With Quote
Old 11th April 2008, 11:01 PM   (permalink)
Default

Simulator just doesnt work in some cases.

Like here is my end code for a 7 Seg Display count up 0 - 9... I wouldnt want to try to simulate this.. would get confusing... RA5 and RA7 are inuse so used RB0 and RB1...
Code:
	list      p=16f627A           ; list directive to define processor
	#include <P16F627A.inc>       ; processor specific variable definitions
	__CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _WDT_OFF & _INTOSC_OSC_NOCLKOUT 

	cblock 0x20
	d1
	d2
	d3
	endc

	ORG     0x00			; processor reset vector
Main
	clrf	PORTA			;Initialize PORTA by setting output data latches
	movlw	0x07 			;Turn comparators off and
	movwf	CMCON 			;enable pins for I/O functions
   	bsf 	STATUS, RP0		;select bank 1
	movlw	0x00			;data direction
	movwf	TRISA			;set PortA all outputs
	movwf	TRISB			;set PortB all outputs
	bsf	PCON, 3			;OSCF: INTOSC oscillator frequency bit: 1=4 MHz typical
	bcf	STATUS, RP0		;select bank 0

Loop	
	movlw	b'01011111'		;Show 0
	movwf	PORTA
	movlw	0x01		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'00000110'		;Show 1
	movwf	PORTA
	movlw	0x00		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'10011011'		;Show 2
	movwf	PORTA
	movlw	0x03		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'10001111'		;Show 3
	movwf	PORTA
	movlw	0x02		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'11000110'		;Show 4
	movwf	PORTA
	movlw	0x02		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'11001101'		;Show 5
	movwf	PORTA
	movlw	0x02		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'11011101'		;Show 6
	movwf	PORTA
	movlw	0x03		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'00000111'		;Show 7
	movwf	PORTA
	movlw	0x00		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'11011111'		;Show 8
	movwf	PORTA
	movlw	0x03		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	movlw	b'11011111'		;Show 9
	movwf	PORTA
	movlw	0x02		; RB0 = E RB1 = G
	movwf	PORTB
	call	Delay
;////////////////////////////////////////////////////
	goto	Loop
Delay				; 1 Sec Delay
	movlw	0x07
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0
	goto	$+1
	goto	$+1
	goto	$+1
	return
	END				; directive 'end of program'
AtomSoft is offline   Reply With Quote
Old 12th April 2008, 06:16 AM   (permalink)
Default

Of course the use of the simulator is limited but sometimes it is still useful - for example I used it yesterday to quickly verify my delay loop produces the exact delay and not a few instr. cycles longer or shorter... using the logic analyzer inside the simulator it was easy and quick.

Petr
petrv is offline   Reply With Quote
Old 12th April 2008, 12:00 PM   (permalink)
Default

How come sometimes my Logic Analyzer isnt available? Like i cant open it because its greyed out?
AtomSoft is offline   Reply With Quote
Old 12th April 2008, 02:32 PM   (permalink)
Default

Not sure, which PIC?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 12th April 2008, 02:45 PM   (permalink)
Default

sometimes the 1320 but remember its on simulator and its greyed out in MPLAB of course
AtomSoft is offline   Reply With Quote
Old 12th April 2008, 02:49 PM   (permalink)
Default

In a pinch the OshonSoft simulator has a 7 segment display. It's demo is limited to 30 uses.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 13th April 2008, 02:32 AM   (permalink)
Default

Setting d1,d2,d3 in a watch and pressing the F7 would have revealed that d1 to d3 were not being assigned and overwritten, and that a delay between BCF and GOTO were missing.
Code:
    cblock 0x00
    d1,d2,d3
    endc

    ORG     0x00           ; processor reset vector
Loop    
    bsf    PORTA, 1        ;set RA1 High
    call    Delay
    bcf    PORTA, 1        ;set RA1 Low
    goto    Loop           ;go back and do it again
donniedj is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Switching power supply issue. dbtoutfit General Electronics Chat 41 25th March 2008 03:21 AM
issue with my handheld console draining batterys... tgg General Electronics Chat 0 26th September 2007 03:37 AM
ESD Issue? Kind of long Peach General Electronics Chat 21 8th April 2007 01:47 AM
Need Someone Realy Good At Computers..... REAL good PapaSmurf Chit-Chat 16 3rd May 2006 10:30 PM
EPE magazine - may 2001 issue - PIC graphics LCD scope evandude General Electronics Chat 4 12th December 2004 05:43 PM



All times are GMT. The time now is 10:26 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.