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
 
Thread Tools Display Modes
Old 27th February 2004, 07:51 PM   (permalink)
Default Crude assembly counter

I want to run a routine seven times. Would something like this work?:

Code:
Counter equ 20   ; variable to put the counter in

   ; Main code here.
   ;  At some point it'll call RoutineName

RoutineName
   movlw b'01111111'
   movwf Counter
RoutineLoop
   
   Goto Transmit          ;  this being the routine to be done seven times
   RRNFC Counter,1     ; roll the bits right, don't use carry, store result in counter?
   BTFSC Counter,1     ; check counter.  skip next  line if it's clear?
   Goto RoutineLoop     ; repeat loop if there are still bits in Counter
   Return  ;  if there are no bits in Counter return to where RoutineName was called
I'm not sure about my use (and understanding) of RRFNC. also am i checking the lsb using BTFSC COunter,1 ?

Any suggestions appreciated..

Mark
__________________
Muss es Sein? Es muss sein...
Mark Lazarides is offline   Reply With Quote
Old 27th February 2004, 09:17 PM   (permalink)
Default

What's RRNFC?. Assuming this is PIC assembler, bits go from 0 to 7, so the least significant bit would be 0, not 1.

If you want to see how loops are done, have a look at my PIC tutorials, many of those use loops.
Nigel Goodwin is online now   Reply With Quote
Old 27th February 2004, 09:38 PM   (permalink)
Default

DECFSZ is best for loop counting.

Code:
Counter equ 20   ; variable to put the counter in 

   ; Main code here. 
   ;  At some point it'll call RoutineName 

RoutineName 
   movlw 7 
   movwf Counter 
RoutineLoop 
    
   CALL Transmit          ;  this being the routine to be done seven times 
   DECFSZ Counter,f
   Goto RoutineLoop     ; repeat loop if there are still bits in Counter 
;
   Return  ;  if there are no bits in Counter return to where RoutineName was called
__________________
"Having to do with Motion Control"
motion is offline   Reply With Quote
Old 28th February 2004, 03:08 PM   (permalink)
Default

Thanks for the help. I see now how complicated i was trying to make it!

Quote:
Originally Posted by Nigel Goodwin
What's RRNFC?. Assuming this is PIC assembler, bits go from 0 to 7, so the least significant bit would be 0, not 1.
20ff RRNCF f,d

Rotate right (no carry)

(found it in the MPLAB help files)
__________________
Muss es Sein? Es muss sein...
Mark Lazarides is offline   Reply With Quote
Old 28th February 2004, 03:39 PM   (permalink)
Default

Ah! - 16 bit core, not 12 or 14 :lol:
Nigel Goodwin is online now   Reply With Quote
Old 28th February 2004, 07:22 PM   (permalink)
Default

Remeber ASM is very specific, its best when asking for help that you clearly say what device you are using, the fuse settings, as well as a breif overview of what the final application will be.

Low end microcontrollers, been developed in ASM, don't deal very well with the idea of box design, where you don't care about other peoples code to be run on the same micro.
TheAnimus is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 11:36 AM.


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