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.

Pic16f88

Status
Not open for further replies.
Have started a new project using a PIC16F88 on a tight budget.
Am using MPLAB 7.31 and writing in assembler.
I have attached the project in full and would like someone to look at the code as I cannot get anything to work.
As you will see the code should toggle outputs.
I am using the internal clock.
I have disconnected everything except the +5v and 0v but don't see any lines toggling.
I don't believe the CPU is running.
I am new to the PIC architecture and believe I have something basic wrong.
I am an experienced assembler programmer and 'C' programmer.
Once I have the CPU running I believe I will be OK.
I very much look forward to your help and also hopefully returning the favour when I can
Many thanks in anticipation. Mark.
 

Attachments

  • progs.zip
    21.5 KB · Views: 482
Have you simulated your code in the debugger? If you are trying to flash a LED, how do you have it connected to the PIC? I would connect the LED in the following manner: +5V -----/\/\/\-------LED--------PIC. I would then change your code to:
Code:
flashd:	
     bcf PORTA,1   ; RA1 Low (LED ON) Sink Current to Ground Through PIC
     call delay       ; delay 76mS			
     bsf PORTA,1   ; RA1 High (LED OFF)
goto	flashd

Also look up Nigel's Tutorials. ;)
 
Mark (Imagine Design) said:
Have started a new project using a PIC16F88 on a tight budget.
Am using MPLAB 7.31 and writing in assembler.
I have attached the project in full and would like someone to look at the code as I cannot get anything to work.
As you will see the code should toggle outputs.
I am using the internal clock.
I have disconnected everything except the +5v and 0v but don't see any lines toggling.
I don't believe the CPU is running.
I am new to the PIC architecture and believe I have something basic wrong.
I am an experienced assembler programmer and 'C' programmer.
Once I have the CPU running I believe I will be OK.
I very much look forward to your help and also hopefully returning the favour when I can
Many thanks in anticipation. Mark.

I would suggest you add a second call to delay, you need one after each change of state.

You might check my PIC tutorials as well?, although slight changes will be required for the 16F88 - but only VERY slight!.
 
Hi Mark,

If you don't have a bypass capacitor connected across VDD and VSS, that might prevent your PIC circuit from operating (especially if you're using a solderless breadboard).

You have the DEBUG fuse set. Are you running your circuit in DEBUG mode from an ICD2? If not, turn the DEBUG fuse off.

I've experienced problems with some power supplies if the BODEN fuse if off.

The INTOSC defaults to 32-KHz after any reset and I don't see where you might be setting the OSCCON register in your code for another frequency.
Code:
;
;  program initialization
;
Init    bsf     STATUS,RP0      ; bank 1                          |B1
        clrf    ANSEL           ; setup PORT A for digital I/O    |B1
;
        movlw   b'01110000'     ;                                 |B1
        movwf   OSCCON          ; select 8-MHz INTOSC clock       |B1
Stable  btfss   OSCCON,IOFS     ; INTOSC frequency stable?        |B1
        goto    Stable          ; no, branch and wait             |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
;
Good luck on your project. Regards, Mike
 
Although it will not affect your current code, your Interupt code is wrong. I just wanted to point it out as it may affect future code.

You currently have
Code:
PROG0	CODE
		movwf   w_temp			;save off current W register contents
		movf	STATUS,w        ;move status register into W register
		movwf	status_temp     ;save off contents of STATUS register
		movf	PCLATH,W        ;move pclath register into W register
		movwf	pclath_temp		;save off contents of PCLATH register

;*****************************************************************************
;								IRQ HANDLER
;*****************************************************************************

irq_handler:
		movf	pclath_temp,W	  ;retrieve copy of PCLATH register
		movwf	PCLATH			  ;restore pre-isr PCLATH register contents
		movf    status_temp,w     ;retrieve copy of STATUS register

		movwf	STATUS            ;restore pre-isr STATUS register contents
		swapf   w_temp,f	 	
		swapf   w_temp,w          ;restore pre-isr W register contents
		retfie                    ;return from interrupt

The code above the label irq_handler will not get executed.
You need to change it to:
Code:
PROG0	CODE
irq_handler:
		movwf   w_temp			;save off current W register contents
		movf	STATUS,w        ;move status register into W register
		movwf	status_temp     ;save off contents of STATUS register
		movf	PCLATH,W        ;move pclath register into W register
		movwf	pclath_temp		;save off contents of PCLATH register

;*****************************************************************************
;								IRQ HANDLER
;*****************************************************************************

		movf	pclath_temp,W	  ;retrieve copy of PCLATH register
		movwf	PCLATH			  ;restore pre-isr PCLATH register contents
		movf    status_temp,w     ;retrieve copy of STATUS register

		movwf	STATUS            ;restore pre-isr STATUS register contents
		swapf   w_temp,f	 	
		swapf   w_temp,w          ;restore pre-isr W register contents
		retfie                    ;return from interrupt

Mike.
 
New project

Many thanks to all.
I now have a flashing LED.
It's plain sailing from here....
I am now going to attempt to get an interrupt running and the USART.
I could be in touch soon...

regards Mark
 
Status
Not open for further replies.

Latest threads

Back
Top