Electronics > Beginners
Assembly code Help! PIC16F57
<< < (16/32) > >>
KL27x:

--- Quote ---It's coming I think, be it at a rediculously slow snails pace. Lol
--- End quote ---
After first playing with PIC AXE, it took me roughly 6 months to make a PIC blink using assembly. After stumbling through some crappy internet tutorials, I resorted to carrying around a PIC datasheet and slowly learning how to put read the tech speak.

I highly recommend you buy the "Gooligum PIC assembly" tutorials, if you find this stuff fun. They're like $5.00 each, if I recall. I stumbled across them several years too late, but I still learned more than a few tricks. And they are easy reading/doing and will probably be fun if you get them before you burn yourself out.

Once you safeguard the motor outputs, you could use your slot machine as a learning device and follow along the baseline tutorial, outputting to the LEDs and using the buttons as inputs. 

Electrofinn:
Think it was sequence1, I have added it anyway just to try it. created separate asm save so I can mess about.



--- Quote ---*In fact, another thing comes to mind. Where that bcf counter_hi,4 instruction was (I forget the title;header, but it was error/instance #11 of counter_hi, IIRC ). Because of the way that this register is used in auto1/2/3, and because of what it does in feature/pattern, this instruction should really be replaced by a bit mask.** If somewhere else, say in autoX, counter reaches 64 or higher, when it gets used to this spot that incf counter_hi and then clears bit 4... well, when pattern is called, that will cause a bad jump.

**
;;;;;;;;;;;;;;;;;;;;;;;;;;
;bcf counter_hi,4
;
movlw b'00001111'
andwf counter_hi,f
;;;;;;;;;;;;;;;;;;;;;;;;;


--- End quote ---


have noticed something else, when I run out of credits and after it waits the two seconds before displaying the "pattern" sequence, rather beginning at the start of the table it often starts somewhere in the middle of the table loop. just trying to figure out what this is telling me, it doesn't matter anyway it's just an interesting observation and I am thinking it has something to do with what ever is in the register at the time causing it to jump straight to that part of the table, sometimes it begins at the start of the pattern table.

Don't feel you have to respond or dig any deeper, you have already spent far too much of your time on this.
KL27x:
Look at the subroutine sequence. You will see that the first time it is called, it is checking bit 7 of mode_byte. Presumably, this is to determine if this is the first time sequence is being called by the Loop, or not.

So if mode_byte 7 is clear, this subroutine clears counter_hi, which determines where pattern starts its "cycle." And it clears counter_lo, which determines when sequence progresses to the next point (the first time, at least). And it sets bit 7 of mode_byte, so that the next time it gets called, it will not repeat these steps. Then, when sequence has been completed, bit 7 of modebyte is cleared. So it is ready to start over. Apparently, it continues until credit_count is zero. This must occur in one of the other active subroutines.

Now, the problem here is that sequence, along with every single other subroutine which takes any significant amount of time, is not performed in one shot from beginning to end when it is called. Only one tiny slice of sequence gets performed on each cycle of Loop.* It will perform the same thing 256 times (as determined by counter_lo), before it progresses to the line in pattern. So counter_lo determines the speed that the LEDs change.

*You know this, automatically, because there is no interrupt routines (and the chip probably doesn't even have this feature). In order to keep the 7 segment displays refreshed, no subroutine may hold the program counter hostage for any significant amount of time, unless the 7 segment displays are either all off or displaying the same thing.

So while sequence is being executed, other things are also being executed. Some other part of the code might be setting bit 5 of modebyte to kill/hold sequence. Presumably if modebyte 5 is set at any other place in the code, bit 7 would also be cleared to "reset" sequence so it starts at the beginning next time. But maybe this has been missed, or maybe the authors prefer it to start at a random location. Who knows, maybe they use some of these registers as part of the random number generator. Or... to beat an old drum, here, there may be a bad memory share/handling regarding counter_hi.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sequence   
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
      ;if mode_byte,5 is cleared, these subroutines are called by Loop
         ;sequence
         ;random
         ;flash
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      clrf   fsr
      btfsc   mode_byte,7      ;TEST 'IN PROGRESS' BIT
   goto      sequence1
      clrf   counter_hi
      clrf   counter_lo
      bsf      mode_byte,7      ;SET 'IN PROGRESS' BIT

sequence1   
      bsf      counter_lo,7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;      incf   counter_lo,f
;      btfss   status,zer
      incfsz    counter_lo,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   retlw .0
      incf   counter_hi,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;insert this code
      movlw   .1
      btfsc   counter_hi,4
      xorwf   new_byte,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      bcf      counter_hi,4   ;this must go back to the original bcf counter_hi,4
      movf   credit_count,f
      btfsc   status,zer
   retlw   .0
      bcf      mode_byte,7
      bcf      mode_byte,5
      bsf      mode_byte,0
   retlw   .0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
KL27x:
This structure of the subroutine is not too great. BTW, here, I will show you how to free up some extra space so you have more room on page 3.

I shuffled one of the subroutines and I added some new code to feature, so you can see how to change the rate of the LED pattern. See "feature".

So check out "slow" to see how to liberate some space if you run into the "half page error."


pages are program memory space
000-1ff page0
200-3ff page1
400-5ff page2
600-7ff page3

000-0ff is the bottom half of page0
100-1ff is the top half of page0

To see where any of your subroutines/labels are, you can open the list file.

Click "file" at the top left of the ide.
Select Open
And change "file type" box to find list file
And open the list file.

At the very bottom of this file, there are all your labels in alphabetical order. And in the leftmost column you will find the location of this label to see what page it is on.
Electrofinn:
it's really annoying that he didn't have the final code but then I don't think It would of looked much better if this release is anything to go by.
 
can you confirm that I put the bit mask in correctly?

sequence1   
      bsf      counter_lo,7
;   v2.02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;      incf   counter_lo,f
;      btfss   status,zer
      incfsz counter_lo,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      goto   sequend
      incf   counter_hi,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;insert this code
      movlw   .1
      btfsc   counter_hi,4
      xorwf   new_byte,f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   bcf      counter_hi,4   ;this must go back to the original bcf counter_hi,4
;
   movlw b'00001111'
   andwf counter_hi,f
;;;;;;;;;;;;;;;;;;;;;;;;;
   movf   credit_count,f
   btfsc   status,zer
   goto   sequend
   bcf   mode_byte,7
   bcf   mode_byte,5
   bsf   mode_byte,0
sequend   retlw   00
 
Navigation
Message Index
Next page
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod