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.

Does this asm code look correct ? PIC12F509

Status
Not open for further replies.
This is how I would write code so that a pattern is displayed when the switch is pressed and then a different pattern would be displayed 1 second later.
Code:
;******** Main Code
start
        movlw   b'001000'       ; Configure only GP3 as a input
        tris    GPIO
loop	btfsc   GPIO,3          ; Is switch 3 pressed?
        goto    TurnOn          ;yes so go turn on LEDs
	clrf	LEDs		;turn off LEDs
	clrf	LEDs2
	clrf	DisplayCount	;reset counter
	goto	Display
TurnOn	movfw	DisplayCount
	xorlw	.10		;reached 1 second
	btfsc	STATUS,Z
	goto	Pattern2	;yes, go do pattern 2
	incf	DisplayCount,F	;increment counter - only if displaying pattern 1
	;do pattern 1
	movlw	0x55		;setup pattern 1
	movwf	LEDs
	movlw	0x05
	movwf	LEDs2
	goto	Display
Pattern2
	movlw	0xAA		;setup pattern 2
	movwf	LEDs
	movlw	0x0A
	movwf	LEDs2
Display
	movlw	.25		;400uS * 25 = 10mS
	movwf	MultiCount	
DisLoop	call	Multiplex	;this takes 400uS
	decfsz	MultiCount,F	;time up
	goto	DisLoop		;no, so do it again
	goto	loop		

;****************** Delay Subroutine ( 10 ms )

Note how calling multiplex 25 times makes up a delay of 10mS and therefore makes timing 1 second very easy.

Have fun.

Mike.
 
Pommie I ment like if you just hit the switch for a second then released it it would run a routine but if you held it for 5 seconds it would play the other routine and not the first one is this possible it will maby be a week before I can get any of the hardware at all so im still just trying to figure out the code for the switch but other then that everything is great including the multiplex routine and im kinda understanding how to turn each LED on and what not now I just have to find the 12F509's again in my house ahah by that time all have all the stuff I need and can start scewing with things to see what works what doesn't thanks
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top