PDA

View Full Version : How to set a pin high an keep it there?



ShortBus
- 27th September 2009, 05:10
Utter newbie here... I have three different LEDs on a PIC16F688. Here is my code:
symbol GREEN = PORTA.1
symbol ORANGE = PORTA.0
symbol BLUE = PORTA.2

porta = %00000000
trisa = %00000000

main:
high orange
pause 1000
high green
pause 1000
high blue
pause 1000

end

This code obviously lights the LEDs in sequence. However each LED turns off before the next one is set high. How do light one, then two, and then all three? Thanks!

Charles Linquis
- 27th September 2009, 05:32
Try this:



main:

PORTA = %00000001
pause 1000
PORTA = %00000011
pause 1000
PORTA = %00000111
PAUSE 1000

end



It looks like you are experiencing a read-modify-write problem. You can search for more info on this forum.

Darrel Taylor
- 27th September 2009, 06:14
INCLUDE "AllDigital.pbp (http://www.picbasic.co.uk/forum/showthread.php?t=11100)"

symbol GREEN = PORTA.1
symbol ORANGE = PORTA.0
symbol BLUE = PORTA.2

porta = %00000000
trisa = %00000000

main:
high orange
pause 1000
high green
pause 1000
high blue
pause 1000

end

mackrackit
- 27th September 2009, 06:46
ANSEL=%00000000
CMCON0=%00000111

Will do the same as Darrel's suggestion and this
http://www.picbasic.co.uk/forum/showthread.php?t=561
plus the data sheet will actually help you learn why. :)

Darrel Taylor
- 27th September 2009, 07:41
...
Will do the same as Darrel's suggestion and this
http://www.picbasic.co.uk/forum/showthread.php?t=561
plus the data sheet will actually help you learn why. :)

Sure,
But if you run ALLDIGITAL first, then you know where to look in the datasheets, because it's already told you what settings you need to use.
If you want to learn, look them up.

People never find the analog registers they need to set by looking in the datasheet first.
:p

mackrackit
- 27th September 2009, 08:33
Sure,
But if you run ALLDIGITAL first, then you know where to look in the datasheets, because it's already told you what settings you need to use.
If you want to learn, look them up.

People never find the analog registers they need to set by looking in the datasheet first.
:p
If you keep going with all of your add ons (includes) you will have any PIC as easy as a STAMP.

What is the maximum amount of includes you have used in a program? ;)

Darrel Taylor
- 27th September 2009, 09:12
:eek: I hope not ... Stamp's don't bring back any memories of "Easy" for me.

What is the maximum amount of includes you have used in a program? ;)
Probably 12-15, but I've never really counted.

90% of my programs only have 2 includes.
care to guess which ones?
<br>

Jerson
- 27th September 2009, 09:37
90% of my programs only have 2 includes.
care to guess which ones?


Care if I take a shot? Must be DT_ints and PBP_reenter.

:)

Darrel Taylor
- 27th September 2009, 09:42
Ding Ding Ding ... Give that man a cigar!

If you smoke cigars :)
<br>

ShortBus
- 27th September 2009, 16:25
Thanks for the replies!

Including "ALLDIGITAL.pbp" didn't affect anything (as far as I can tell). Attempting to set those registers simply gives me a couple of compiler errors about an "undefined symbol." Charle's example, however, did the trick. Any idea why the other suggestions didn't work?

comwarrior
- 27th September 2009, 16:40
90% of my programs only have 2 includes.
care to guess which ones?
<br>

BS1DEFS.BAS and BS2DEFS.BAS? :p lol

Darrel Taylor
- 27th September 2009, 19:33
Thanks for the replies!

Including "ALLDIGITAL.pbp" didn't affect anything (as far as I can tell). Attempting to set those registers simply gives me a couple of compiler errors about an "undefined symbol." Charle's example, however, did the trick. Any idea why the other suggestions didn't work?

You might have the wrong chip selected in the Device drop-down box.
Because those are the registers you need to set for a 16F688.
<br>

boroko
- 29th September 2009, 10:04
BS1DEFS.BAS and BS2DEFS.BAS? lol
Reply With Quote

Very funny! Made me smile.

comwarrior
- 30th September 2009, 01:38
Darrel's not speaking to me now :(

[gives Darrel a little prod]

Darrel Taylor
- 30th September 2009, 04:05
Darrel's not speaking to me now :(
Did I miss something?

I've got that "Paying the rent" thing going on, haven't talked to hardly anyone recently.
Why can't it be the 24th century, so we don't need money anymore?

If you meant post #11 ...
My opinions should be well known ...

http://www.darreltaylor.com/files/BadStomp.gif

Ingvar
- 1st October 2009, 15:50
Ouch, that brings back painful memories of the time i stepped on an IC lying on it's back. No, i was not wearing shoes at the time ......

mackrackit
- 1st October 2009, 16:01
Ouch, that brings back painful memories of the time i stepped on an IC lying on it's back. No, i was not wearing shoes at the time ......
One of the reasons I like surface mounts...:p