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.

This really shouldn't be this hard :)

Status
Not open for further replies.

KMD

New Member
All I'm trying to do is get 5 lights to blink 3 times at start up, stay off for a brief time, and then have each light come on and go off (while the others stay off) in order of the port bit they are attached to.

The start of the program works fine, all 5 lights blink 3 times and then stay dark for a couple seconds. Once it gets to the LOOP, the light attached to PORTB,1 flashes constantly while the others behave like I'm expecting.

I've rewritten this thing about 20 times trying to figure out why, it's driving me nuts. I'm not so interested in the right way to do this, I'd prefer to find that out myself, I'm more interested in knowing why the PORTB,1 this isn't working the way I expect it to, thanks.



Code:
main
PORTSU
		movlw	0x07
		movwf	CMCON
		bsf		STATUS,	RP0		;switch to bank1
		movlw	b'00000000'		;put 0x0 into w
		movwf	TRISA			;copy w into trisa makes pin 17 an input
		movlw	b'00000000'		;set all portB pins to inputs
		movwf	TRISB			;
		bcf		STATUS, RP0		;move back to bank0

STARTUP
		movlw	b'11111111'		;make all pins on portb hot
		movwf	PORTB			;
		call	DELAY
		movlw	b'00000000'		;make all pins on portb low
		movwf	PORTB
		call	DELAY
		movlw	b'11111111'
		movwf	PORTB
		call	DELAY
		movlw	b'00000000'		;make all pins on portb low
		movwf	PORTB
		call	DELAY
		movlw	b'11111111'
		movwf	PORTB
		call	DELAY
		movlw	b'00000000'		;make all pins on portb low
		movwf	PORTB
		call	DELAY
		call	DELAY
		call	DELAY
		call	DELAY
			
		
LOOP
		movlw	b'00000001'
		movwf	PORTB
		call	BLINK

		movlw	b'00000010'
		movwf	PORTB
		call	BLINK

		movlw	b'00000100'
		movwf	PORTB
		call	BLINK

		movlw	b'00001000'
		movwf	PORTB
		call	BLINK

		movlw	b'00010000'
		movwf	PORTB
		call	BLINK

		goto	LOOP	

DELAY
d1		decfsz	count1,1		;
		goto	d1				;
		decfsz	count2,1		;
		goto	d1				;
		return					;	
BLINK
		call	DELAY
		movlw	PORTB
		movwf	save
		movlw	b'00000000'
		movwf	PORTB
		call	DELAY
		movlw	save
		movwf	PORTB
		call	DELAY
		return

FYI, I've been screwing around with this for so long, some of the comments are out of date.
 
Hi I don't like this part of your code:

BLINK
call DELAY
movlw PORTB
movwf save
movlw b'00000000'
movwf PORTB
call DELAY
movlw save
movwf PORTB
call DELAY
return

It should be movf save,w

Also, post your scheme...
And check your circuit for any short between PortB,1 and other PINs
 
Also this line (in the same section) is wrong "movlw PORTB", you can't use MOVLW to transfer anything to W except an explicitly stated number - in this case the assembler will relace 'PORTB' with it's equate value from the include file, which is 6.

As with your other incorrect line, it should be "movf PORTB, W", to transfer the contents of PORTB to the W register.

The incorrect line that Jay mentioned will have the same fault, it will load W with the numeric address of 'save', which will be defined in the definitons at the beginning of your code (something at least as high as 0x20 for a 628).
 
Nigel Goodwin said:
Also this line (in the same section) is wrong "movlw PORTB", you can't use MOVLW to transfer anything to W except an explicitly stated number - in this case the assembler will relace 'PORTB' with it's equate value from the include file, which is 6.

As with your other incorrect line, it should be "movf PORTB, W", to transfer the contents of PORTB to the W register.

The incorrect line that Jay mentioned will have the same fault, it will load W with the numeric address of 'save', which will be defined in the definitons at the beginning of your code (something at least as high as 0x20 for a 628).
Yes Nigel... strange that program is even working (partly but is)...
 
You guys absolutely ROCK, thanks. I'm guessing that same mistake has caused me no end of trouble all weekend long :oops: .

Yes Nigel... strange that program is even working

I love this line :lol: . I've gotten to use it so many times over the years. I've run into some pretty scarry network installs as a tech.
 
KMD said:
You guys absolutely ROCK, thanks. I'm guessing that same mistake has caused me no end of trouble all weekend long :oops: .

Yes Nigel... strange that program is even working

I love this line :lol: . I've gotten to use it so many times over the years. I've run into some pretty scarry network installs as a tech.
I know what you mean MegaLOL... :twisted:
 
flashing leds

hi kmd
im new to this forum.
to get what you want just remove the call blink and add call delay or delay2 if you want a longer delay.

other thing you dont have anything in count1/2 in delay

anyway try this below.

hope that sorts it for you.
phill


LOOP
movlw b'00000001'
movwf PORTB
call delay2

movlw b'00000010'
movwf PORTB
call delay2
movlw b'00000100'
movwf PORTB
call delay2

movlw b'00001000'
movwf PORTB
call delay2

movlw b'00010000'
movwf PORTB
call delay2
goto LOOP

DELAY
d1 decfsz count1,1 ;
goto d1 ;
decfsz count2,1 ;
goto d1 ;
return

delay2

movlw d'200' ;put 100 in w
movwf count1 ;put w in count1
d2 decfsz count1,1
goto d2

return
 
For the delay, u cld use:

movlw 0x07
movwf OPTION_REG ; u should have used #INCLUDE <urPIC.INC>

then just do:
delay
movlw val
movwf counter
loop clrf tmr0
bcf intcon,t0if
btfss intcon,t0if
goto $-1
decfsz counter,f
goto loop
return

You'll have a delay of:
val * 256 * 256 / clocking frequency or microcontroller...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top