My first running Picaxe.

Artie2

New Member
I decided to start with something dirt-simple, just so I could actually see this thing work. It just flashes 4 LED's in a binary count, then repeats. It was fun to see how simple this is once you get the feel for it.

My first "gotcha" was forgetting to move the jumper over to the "serial in" position. :p

Code:
setup:
  dirs=%00010111
  setint %00001000,%00001000
 
main:
 for b0 = 0 to 31'    Count to 31 and
   if b0 = 8 then'    jump from 8 to 24
    b0=24'            since we aren't using pin 3.
   endif  
  pins=b0
  pause 300
 next b0
 pause 2000
 for b1=1 to 10'      Flash all four
  pins=%00000000'     LED's ten times
  pause 100'          for no particular
  pins=%00010111'     reason.
  pause 100
 next b1
 goto main
 
Interrupt:'           Clear all LED's
  b0=0'               start over if button
  pins=%00000000'     3 is pressed.
  pause 3000
 
check:'               Hold if button 3 held down.
 if pin3=1 then goto check
  setint %00001000,%00001000
 return
Now . . . on to bigger and better projects. ;)
 

Artie2

New Member
Thanks, and yup. I'm hooked.

The first thing my friend said, after it started flashing was, "Can you make it go back and forth, like KnightRider?" :D

I said "sure", and we did that next.
 

westaust55

Moderator
Working Program

Hi Artie,

congratulations on your first working program.

Well done for the good formatting and adding comments.
Makes the programs much easier to read.

Can I suggest that you do put the apostrophe immediately in front of the comment rather than immediately at the back of the commands.

so:
Code:
for b0 = 0 to 31'        Count to 31 and
becomes
Code:
for b0 = 0 to 31        'Count to 31 and
my personal preference is to use a semicolon in lieu of an apstrophe as I think it stands out more:
Code:
for b0 = 0 to 31        ;Count to 31 and

Not "knocking" your work (it still works as expected) but all may find it a little easier to follow.

Again great work


EDIT:
Artie,
just realised, you have an interrupt subroutine at the bottom with a SETINT command to restore the SETINT
but you have no initial SETINT command to start the interrup process. Maybe just some left over code that could be deleted or a start of something bigger . . .
 
Last edited:

westaust55

Moderator
Hi again Artie,

further to my earlier post (one back) some further assistance for you.

If you look at the attachment I have made, you will see that in jumping from the count of 7 up to 24 you are in fact still trying to set pin 3 which you were aiming to avoid.

so really you need to count from 0 to 7 then jump to 16 and count up to 23

here is a modified version for the first part to help you:
Code:
main:
  FOR b0 = 0 TO 15    ; for the 16 possible lighting combinations
    IF b0 < 8 THEN
      pins = b0       ; for first 8 combinations using pins 0,1 and 2
    ELSE              ; skip use of pin 3
      pins = b0 + 8   ; for second 8 combinations using pins 4 + 0, 1 and 2
    ENDIF
  NEXT b0
Keep up the good work, have fun, learn from your mistakes, and above all else, don't be afraid to ask questions.
 

Attachments

Last edited:

Artie2

New Member
Can I suggest that you do put the apostrophe immediately in front of the comment rather than immediately at the back of the commands.
Yeah . . . thats left over from my BASIC days. In QB, you had to put the apostrophe at the end of the active code in order to be able to add the spaces. I didn't realize that this editor would allow that. Thanks for the tip.

westaust55 said:
Artie,
just realised, you have an interrupt subroutine at the bottom with a SETINT comamnt to restore the SETINt
but you have no initial SETINT command to start the interrup process. Maybe just some left over code that could be deleted or a start of something bigger . . .
Actually, its at the very beginning of my code. Right after the "dirs=" command in my "Setup:" header.

If you look at the attachment I have made, you will see that in jumping from the count of 7 up to 24 you are in fact still trying to set pin 3 which you were aiming to avoid.
Ah . . . I see that now. I had to single-step through both of our codes to see what you meant. That brings up another question:

Lets say I was using a 14M, where pin 3 could be used as an output, but I wanted to run this same code. Would my initial "dirs=%00010111" command mask pin 3, or would the "pins=" command override it? In other words, does one command take precedence over the other, or does it just go by which command came last?

Thanks for all the help.
Artie
 

westaust55

Moderator
Ah yes, I see the SETIN now - :rolleyes:

scanned up and down before but failed to see it :(


with respect to the use of the DIRS command,
DIRS is not a valid command on the 14M. DIRS is only for the 08 and 08M

On the 14M, 28X/28X1, 40X and 40X1 You actual must use the DIRSC command instead. Suggest that you have a look at manual 2 page 97

Then for the 14M look at manual 1 page 77. The DIRSC command acts upon a total of 6 pins, 3 are normal inputs by default and 3 are normally outputs by default.

on the non 08/08M chips with the exception of the 14M which is as mentioned above, the PINS = command works on the standard outputs and there no possibility to use the dirs command so there is no conflict or precedence.
 
Last edited:
Top