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.

Did I fry my PIC?

Status
Not open for further replies.

tempus

Member
Hey all;

I finally got my PIC (16F737), but so far I can't get it to work. Since this is my first foray into the uprocessor world, I don't know if this is a problem with my programming or my breadboarding. When I was putting the PIC in my breadboard, the pins didn't quite line up (which they never do) so I had to pull it out a couple times to gently move the pins inward. After 2 or 3 tries, I got it to go in, powered it up, and it didn't do what I had planned (i.e., I had some LEDs connected to it to see if I could light them up). On closer inspection, I noticed that I had (you guessed it) inserted it backwards. Novice mistake i know and I could've kicked myself. The question is: did I kill it in the processor? Here's some info. Both the ground and V+ pin had 5v on them, as did a pin that was configured as an input (there was no 10k pullup on it).

Also (to help me understand my readings), I have port B conifgured as inputs with weak pullups enabled. These all read 5v when the IC is powered up. Is that how they should read, or do the pins with pullups enabled need to be connected to V+ also?

Thanks
 
Last edited:
heh sounds like the pick shoudl be alive.

Did you have GND on anything?

Download the datasheet for the pic:
https://www.electro-tech-online.com/custompdfs/2009/10/30498c.pdf

On page 4. Just wire the main parts:
VSS = GND (PINS 8 & 19)

VDD = 5V+ (PIN 20)

VPP = 10k to 5V+ (PIN 1) (AKA MCLR/VPP/RE3)

PGD = PICKIT (PIN 28) (AKA RB7/PGD)

PGC
= PICKIT (PIN 27) (AKA RB6/PGC)

PICKIT 2 PINS:
-1------2-----3-----4-----5--
VPP--VDD--VSS--PGD--PGC
 
Last edited:
PIC's usually survive been put in the wrong way round, they are VERY sturdy devices, I've never managed to kill one yet.

Check the connections used in my tutorials, they connect everything you need, and nothing you don't.

Personally I never use breadboards, they are far too unreliable, and many problems posted here are down to breadboards, in particular connecting them incorrectly.
 
Thanks for all the replies. This sounds promising anyway.

Did you have GND on anything?

The only things that would've had ground on them would have been configured as an input and an input with pullup enabled.

I can't test it using your suggestion because I don't have a PICKIT.

if both the GND and 5V RAIL had 5V then there wasnt a ground hopefully. Without a ground nothing bad should happen i guess.

I thought of that afterwards too - really with 5v at each of those pins I would think it would be like nothing was connected at all, since they would be at the same potential.

PIC's usually survive been put in the wrong way round, they are VERY sturdy devices, I've never managed to kill one yet.

That's good news.

Personally I never use breadboards, they are far too unreliable, and many problems posted here are down to breadboards, in particular connecting them incorrectly.

I've had more than my fair share of problems with breadboards too - you know, the type where you spend a couple days trying out every possible alternative, then you finally pull the piece out and hook it up in a different area of the breadboard and everything works fine? Unfortunately, I don't really know any other way to test things without doing a lot of soldering/unsoldering. I think it would be a good idea to build a test board of some sort, but I really only need to get this one project working.

Thanks
 
I designed many circuits using minimum and maximum spec's from datasheets and buying name-brand parts from reliable manufacturers (not cheap Chinese junk from E-Bay). I built the circuits on epoxy-fiberglass stripboard (never on an intermittent breadboard) and every single one worked perfectly.
 
breadboards are great ! I would make a PCB of my own with full outputs and a header for programming tho. Mainly so i can program and have the outputs and all ready to be used. Only for testing tho.

Prototypes on a Strip board.
Final on a PCB made.
 
you should be fine. What are you using for a programmer?

I'm using a JDM enhanced with PICPgm software. I pulled it out, it redetected it and I was able to reprogram it as well.

Still isn't working though. I was wondering - I have the Config stuff set in my code. Do I have to set it in the software programmer too?

Thanks
 
I'm using a JDM enhanced with PICPgm software. I pulled it out, it redetected it and I was able to reprogram it as well.

Still isn't working though. I was wondering - I have the Config stuff set in my code. Do I have to set it in the software programmer too?

No, the software should read it from the HEX file.

Make sure you verify it after programming, this will confirm it's programmed correctly.
 
Thanks again for the replies. I've got 14 switches connected to the PIC. Each one is programmed to send a logic high one or more outputs, which will control a CMOS switch and an indicator LED. So the opening code checks all the switches to see if any are pushed. When 1 is, it follows the appropriate goto path, where a switch debounce algorithm is employed along with a mute function to hopefully get rid of any audible clicks that may enter into the audio path (I'm switching audio signals). Here's the code:

Code:
	list	p=pic16f737
		#include	<P16F737.inc>		; processor specific variable definitions
		radix	hex
;
	__CONFIG    _CONFIG1,  _CP_OFF & _CCP2_RB3 & _DEBUG_OFF & _VBOR_2_0 & _BOREN_0 & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__CONFIG    _CONFIG2,  _BORSEN_0 & _IESO_OFF & _FCMEN_OFF
;------------------------------------------------------------
;				Counter locations
dbcount		equ		0x21
dc1			equ		0x22
;------------------------------------------------------------
			org		0x000
;
;Initialization

start		bsf		STATUS,RP0		
			bcf		STATUS,RP1		;bank 1
			bsf 	OSCCON,IRCF2 	;set int osc 110=4Mhz	
			bsf 	OSCCON,IRCF1			
			bcf 	OSCCON,IRCF0
			movlw	0x0f			;conifgure all pins as
			movwf	ADCON1			;   digital inputs
			bcf		OPTION_REG,7	;enable PORTB pullups
			movlw	0xf8			;load w with 11111000
			movwf	TRISA			;make RA0-RA4 inputs,RA5-RA7 outputs
			movlw	0xff			;load w with 1's
			movwf	TRISB			;make PORTB inputs	
			movlw	0xF		 		;load w with 00001111
			movwf	TRISC			;make RC0-RC3 outputs, RC4-RC7 inputs
			bcf		STATUS,  RP0	;bank 0
			bsf		PORTA,6			;output hi RA6 - mute on
			nop		
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			movlw	0x00			;load w with 0's
			movwf	PORTC			;all effects bypassed
			bcf		PORTA,6			;output lo RA6 - mute off

;Main Program			

switch		btfss	PORTE,3			;bypass switch hi?
			goto	bypass			;no - swtich pressed
			btfss	PORTA,0			;comp vb switch hi?
			goto	compvb			;no - switch pressed
			btfss	PORTA,1			;comp switch hi?
			goto	comp			;no - switch pressed
			btfss	PORTA,2			;flanger switch hi?
			goto	flanger			;no - switch pressed
			btfss	PORTA,3			;chorus switch hi?
			goto	chorus			;no - switch pressed
			btfss	PORTA,4			;delay switch hi?
			goto	delay			;no - switch pressed
			btfss	PORTB,0			;comp delay switch hi?
			goto	compdelay		;no - switch pressed
			btfss	PORTB,1			;comp flanger switch hi?
			goto	compflanger		;no - switch pressed
			btfss	PORTB,2			;ch delay switch hi?
			goto	chdelay	 		;no - switch pressed
			btfss	PORTB,3			;clch delay switch hi?
			goto	clchdelay		;no - switch pressed
			btfss	PORTB,4			;cl flanger switch hi?
			goto	clflanger		;no - switch pressed
			btfss	PORTB,5			;cl chorus switch hi?
			goto	clchorus		;no - switch pressed
			btfss	PORTB,6			;clean switch hi?
			goto	clean			;no - switch pressed
			btfss	PORTB,7			;comp delay vb switch hi?
			goto	compdlyvb		;no - switch pressed
			goto	switch			;check all switches again

;					Switch Actions
;
bypass		;	debounce switch down
db_down		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly
			btfsc	PORTE,3			;if button up (RE3 hi),
			goto	db_down			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly
			;	actual switching	
			bsf		PORTA,6			;turn mute on
			nop
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			movlw	0x00			;load w with 0's
			movwf	PORTC			;all effects bypassed
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off			
			;	debounce switch up 
db_up		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly
			btfss	PORTE,3			;if button down (RE3 lo),
			goto	db_up			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly
			goto	switch

compvb		;	debounce switch down
db_down1	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly1		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly1
			btfsc	PORTA,0			;if button up (RA0 hi),
			goto	db_down1		;restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly1	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'10000000'		
			movwf	PORTC			;turn comp on
			bcf		PORTA,5			;output lo RA5 - vb on
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up1		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly1		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly1
			btfss	PORTA,0			;if button down (RA0 = lo),
			goto	db_up1			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly1
			goto	switch			;check switches again

comp		;	debounce switch down
db_down2	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly2		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly2
			btfsc	PORTA,1			;if button up (RA1 hi),
			goto	db_down2		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly2	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'10000000'		
			movwf	PORTC			;turn comp on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up2		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly2		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly2
			btfss	PORTA,1			;if button down (RA1 lo),
			goto	db_up2			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly2
			goto	switch			;check switches again

flanger		;	debounce switch down
db_down3	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly3		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly3
			btfsc	PORTA,2			;if button up (RA2 hi),
			goto	db_down3		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly3	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'01000000'		
			movwf	PORTC			;turn flanger on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up3		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly3		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly3
			btfss	PORTA,2			;if button down (RA2 = lo),
			goto	db_up3			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly3
			goto	switch			;check switches again

chorus		;	debounce switch down
db_down4	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly4		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly4
			btfsc	PORTA,3			;if button up (RA3 hi),
			goto	db_down4		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly4	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'00100000'		
			movwf	PORTC			;turn chorus on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up4		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly4		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly4
			btfss	PORTA,3			;if button down (RA3 lo),
			goto	db_up4			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly4
			goto	switch			;check switches again

delay		;	debounce switch down
db_down5	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly5		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly5
			btfsc	PORTA,4			;if button up (RA4 hi),
			goto	db_down5		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly5	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'00010000'		
			movwf	PORTC			;turn delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
				;	debounce switch up 
db_up5		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly5		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly5
			btfss	PORTA,4			;if button down (RA4 lo),
			goto	db_up5			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly5
			goto	switch			;check switches again

compdelay	;	debounce switch down
db_down6	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly6		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly6
			btfsc	PORTB,0			;if button up (RB0 hi),
			goto	db_down6		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly6	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'10010000'		
			movwf	PORTC			;turn comp and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off	
			;	debounce switch up 
db_up6		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly6		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly6
			btfss	PORTB,0			;if button down (RB0 lo),
			goto	db_up6			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly6
			goto	switch			;check switches again

compflanger	;	debounce switch down
db_down7	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly7		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly7
			btfsc	PORTB,1			;if button up (RB1 hi),
			goto	db_down7		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly7	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'11000000'		
			movwf	PORTC			;turn comp and flanger on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up7		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly7		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly7
			btfss	PORTB,1			;if button down (RB1 lo),
			goto	db_up7			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly7
			goto	switch			;check switches again

chdelay		;	debounce switch down
db_down8	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly8		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly8
			btfsc	PORTB,2			;if button up (RB2 hi),
			goto	db_down8		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly8	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'00110000'		
			movwf	PORTC			;turn chorus and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up8		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly8		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly8
			btfss	PORTB,2			;if button down (RB2 lo),
			goto	db_up8			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly8
			goto	switch			;check switches again

clchdelay	;	debounce switch down
db_down9	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly9		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly9
			btfsc	PORTB,3			;if button up (RB3 hi),
			goto	db_down9		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly9	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'00110000'		
			movwf	PORTC			;turn chorus and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up9		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly9		incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly9
			btfss	PORTB,3			;if button down (RB3 lo),
			goto	db_up9			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly9
			goto	switch			;check switches again

clflanger	;	debounce switch down
db_down10	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly10	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly10
			btfsc	PORTB,4			;if button up (RB4 hi),
			goto	db_down10		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly10	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'01000000'		
			movwf	PORTC			;turn flanger on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up10		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly10	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly10
			btfss	PORTB,4			;if button down (RB4 lo),
			goto	db_up10			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly10
			goto	switch			;check switches again

clchorus	;	debounce switch down
db_down11	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly11	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly11
			btfsc	PORTB,5			;if button up (RB5 hi),
			goto	db_down11		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly11	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'00100000'		
			movwf	PORTC			;turn chorus on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up11		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly11	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly11
			btfss	PORTB,5			;if button down (RB5 lo),
			goto	db_up11			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly11
			goto	switch			;check switches again

clean		;	debounce switch down
db_down12	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly12	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly12
			btfsc	PORTB,6			;if button up (RB6 hi),
			goto	db_down12	;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly12	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'00000000'		
			movwf	PORTC			;turn chorus and delay on
			bsf		PORTA,5			;output hi RA5 - vb off
			nop
			bcf		PORTA,7			;output lo RA7 - clean channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up12		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly12	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly12
			btfss	PORTB,6			;if button down (RB6 lo),
			goto	db_up12			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly12
			goto	switch			;check switches again

compdlyvb	;	debounce switch down
db_down13	movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly13	incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly13
			btfsc	PORTB,7			;if button up (RB7 hi),
			goto	db_down13		;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly13	
			;	actual switching
			bsf		PORTA,6			;turn mute on
			movlw	b'10010000'		
			movwf	PORTC			;turn comp and delay on
			bcf		PORTA,5			;output lo RA5 - vb on
			nop
			bsf		PORTA,7			;output hi RA7 - lead channel on
			call	mutedelay		;mute for 2ms
			bcf		PORTA,6			;turn mute off
			;	debounce switch up 
db_up13		movlw	0x0d			;max count = 10ms/768us = 13 = 0x0d
			movwf	dbcount
			clrf	dc1				;reset dc1
up_dly13	incfsz	dc1,f			;delay 256x3 = 768us
			goto	up_dly13
			btfss	PORTB,7			;if button down (RB7 lo),
			goto	db_up13			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	up_dly13
			goto	switch			;check switches again
;-----------------------------------------------------------------------------
;					mutedelay - 2ms delay 
;
mutedelay
									;1993 cycles
			movlw	0x8E
			movwf	dbcount
			movlw	0x02
			movwf	dc1
Delay_0
			decfsz	dbcount, f
			goto	$+2
			decfsz	dc1, f
			goto	Delay_0
									;3 cycles
			goto	$+1
			nop						;4 cycles (including call)
			return

			end

Does everything look OK?

Thanks
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top