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.

16F1827 & PK3 problem?

Status
Not open for further replies.

AGCB

Member
I'm just starting to use/learn a 16F1827 and got a new Pickit 3. It is hooked up for ICSP. I wrote a very simple program to start with (blink a LED) and got it to program but as soon as I remove the programmer from the circuit, the delay values change to much longer than when the programmer is in the circuit.

I'm using MPLAB on a XP. The PK3 is conected to the target per the instrution sheet that came with it. I assume that I can remove the programmer as soon as it's done, or is there something to do before pulling it out?

I've attached the code.

Also, if you see any obvious extra or lack of code please let me know what could be better or is not needed. Thanks Aaron
 

Attachments

  • TRY_THIS_10 copy.txt
    1.7 KB · Views: 189
I suspect that your assembler will have given a warning something like this:

Message[313] C:\PIC\PIC16\JUNK\JUNK.ASM 45 : CBLOCK constants will start with a value of 0.

You need to tell the assembler where CBLOCK should start, and address 0 is no good, as vital SFRs are located at zero.

Hope this helps
 
You do have you cblock wrong

Code:
	list		p=16f1827      
	#include	<p16f1827.inc> 

    __CONFIG _CONFIG1, _FOSC_XT & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
	
	 ;------------------------------------------------------------------------------
     ; VARIABLE DEFINITIONS
     ;
     ; Available Data Memory divided into Bank 0-15.  Each Bank may contain 
     ; Special Function Registers, General Purpose Registers, and Access RAM 
     ;
     ;------------------------------------------------------------------------------

       CBLOCK 0x20 ; Define GPR variable register locations
            dc1  ; User variables allocated contiguously
            dc2  ; 
            dc3  ; 
       ENDC


    	ORG     0x0000            ; processor reset vector  
    	GOTO    START
start
	banksel	cm1con0
	bcf	cm1con0,7	;turn off comparators
	bcf	cm2con0,7	  ;
	banksel	adcon0
	bcf	adcon0,0	;A2D off
	banksel	ansela
	clrf	ansela		;porta digital i/o
	clrf	anselb		;portb digetal i/o
	
	banksel	trisa
	clrf	trisa		;porta output
	clrf	trisb		;portb output
	banksel	porta
	clrf	porta		;outputs LO
	clrf	portb
	
Main    
	
	BSF     PORTB,2        ; Turn on LED connected to RB2
	movlw	.50 	       ; 500 ms delay
        CALL    adj_delay_ms
        BCF     PORTB,2        ; Turn off LED connected to RB2
        movlw	.50 
        CALL    adj_delay_ms 
        GOTO    Main 


;------Adjustable delay-----10-2550 ms(2.55 seconds)------------
                   ; delay = W x 10ms
			; enter with multiplier in WREG before CALL					
	
	

adj_delay_ms	

        banksel dc3                ; Wx10.015ms
        movwf   dc3             
dly2    movlw   .13             ; repeat inner loop 13 times
        movwf   dc2             ; -> 13x(767+3)-1 = 10009 cycles
        clrf    dc1             ; inner loop = 256x3-1 = 767 cycles
dly1    decfsz  dc1,f           
        goto    dly1
        decfsz  dc2,f           ; end middle loop
        goto    dly1            
        decfsz  dc3,f           ; end outer loop
        goto    dly2
       

        return


        END
 
Thanks be80be and hexreader

I did have the cblock info in the program but when I edited out my personal notes to post, I deleted that too.

The problem was in my cofiguration word for can type oscilator. It should have been _EXT_HS so you were on the right track.

??? In my setup, is it necesary to turn off comparators AND a2d AND set ansel as digital? Or can any of these steps be eliminated? Thanks Aaron
 
Well you found it I was going to post the configure after i looked at the data sheet. But you have that now it should work.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top