Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 7th November 2007, 07:35 PM   (permalink)
Default 16f84 - Floathing led with PIC

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
byrusber is offline  
Old 7th November 2007, 08:17 PM   (permalink)
Default

Read my tutorials, you can make any pattern you like.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th November 2007, 03:38 AM   (permalink)
Default

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.
Pommie is online now  
Old 8th November 2007, 05:21 AM   (permalink)
Default

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.
donniedj is offline  
Old 8th November 2007, 05:56 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
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 by Mike, K8LH; 8th November 2007 at 06:11 PM.
Mike, K8LH is offline  
Old 8th November 2007, 09:15 PM   (permalink)
Default

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
byrusber is offline  
Old 12th November 2007, 10:38 AM   (permalink)
Default

The above methods are superb.Nice work.

But some people do it from calling a Table which can load many patterns which is require.

But the OP satisfied with the above method.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is offline  
Old 14th November 2007, 06:07 PM   (permalink)
Default 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
byrusber is offline  
Old 14th November 2007, 06:35 PM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 15th November 2007, 05:37 AM   (permalink)
Default

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.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
PIC ASM - Summation two 16 bit numbers (16f84) byrusber Micro Controllers 10 28th October 2007 09:41 PM
High ADC sampling rate PIC, 18F needed? bananasiong Micro Controllers 24 28th October 2007 01:13 PM
PIC output pin keeps going low Endicron Micro Controllers 12 1st October 2007 09:15 AM
LED sensor help flemmard Micro Controllers 13 14th September 2007 07:07 PM
P channel FETs vs N channel FETs for LED Matrix applications ?? tdg8934 General Electronics Chat 3 9th September 2007 06:17 PM



All times are GMT. The time now is 01:47 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker