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.

16f84 - Floathing led with PIC

Status
Not open for further replies.

byrusber

New Member
Hey,

i have 8 leds on PORTB
i want to light them alternately, and then turn off

like

1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0
1 1 1 1 1 0 0 0
1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1
0 0 0 1 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0

how can i do that with PIC ASM ?
thx for the help
 
I thought of a simple way that just complements the carry flag.
Code:
		clrf	PORTB		;start all off
		bsf	STATUS,C	;set carry flag
Loop		rrf	PORTB		;shift carry into port b
		movlw	1		;Bit 0 = carry flag
		xorwf	STATUS,W	;complement carry flag
		movwf	STATUS		;write it back
		call	Delay		;must not corrupt the carry flag.
		goto	Loop		;do it all again


Delay		movlw	0x1F
		movwf	d1
		movlw	0x4F
		movwf	d2
Delay_0		decfsz	d1, f
		goto	$+2
		decfsz	d2, f
		goto	Delay_0
		return

It should be 1 instruction shorter but the simulator doesn't seem to execute xorwf STATUS,F correctly.

Can you tell, I was bored.

Mike.
 
The code needed to do this is so elementary. Configuring the TRISB, interrupts and timers is more involved. How did you get pass the thicket yet drown in the puddles.
 
Pommie said:
I thought of a simple way that just complements the carry flag.
That's very clever...

Unless I'm mistaken, can't you eliminate the "setc" instruction (bsf STATUS,C) before the loop?

No need to preserve Carry in the delay routine for this example;

Code:
;
        clrf    PORTB           ;
Loop
        clrc                    ;
        btfss   PORTB,0         ; 
        setc                    ;
        rrf     PORTB,F         ;
        call    Delay           ;
        goto    Loop            ;
;
 
Last edited:
This code works properly:

Code:
	list p=16f84
	include "p16f84.inc"
	
ax		equ 0x10
bx		equ 0x12

Reset_Vector code 0x000
goto start
code 0x002A

start
	clrf 	PORTB
	bsf  	STATUS,5
	clrf 	TRISB
	bcf  	STATUS,5
	movlw 	d'8'
	movwf	ax
	movlw 	d'8'
	movwf	bx
FIRST
	bsf 	STATUS,0
	rrf 	PORTB,1
	decfsz	ax,1
	goto 	FIRST
LAST
	bcf	STATUS,0
	rrf	PORTB,1
	decfsz	bx,1
	goto	LAST
LOOP
	goto LOOP 
	end
 
Delay

Can anyone tell me how can i make 0.1 second delay here ?
i mean

1 0 0 0 0 0 0 0
(0.1 s later)
1 1 0 0 0 0 0 0
(0.1 s later)
1 1 1 0 0 0 0 0
(0.1 s later)
1 1 1 1 0 0 0 0
..
..
..

0 0 0 0 0 0 1 1
(0.1 s later)
0 0 0 0 0 0 0 1
(0.1 s later)
0 0 0 0 0 0 0 0


i want to use this delay in that code :

Code:
	list p=16f84
	include "p16f84.inc"
	
ax		equ 0x10
bx		equ 0x12

Reset_Vector code 0x000
goto start
code 0x002A

start
	clrf 	PORTB
	bsf  	STATUS,5
	clrf 	TRISB
	bcf  	STATUS,5
	movlw 	d'8'
	movwf	ax
	movlw 	d'8'
	movwf	bx
FIRST
	bsf 	STATUS,0
	rrf 	PORTB,1
	decfsz	ax,1
	goto 	FIRST
LAST
	bcf	STATUS,0
	rrf	PORTB,1
	decfsz	bx,1
	goto	LAST
LOOP
	goto LOOP 
	end
 
Like I said much earlier in this thread, check my tutorials, where I use the Delay Code Generator found on the PICList to generate the delays - or you could just take the subroutines from my tutorials.
 
Delay code generate gave this routine for 1 second.

Code:
Del1s	movlw	0x08
	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

			;3 cycles
	goto	$+1
	nop
	return

For your pattern, 1 second delay is too slow something like 5Hz gap will be more attractive for eyes.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top