Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Moved] need help explaining code. line by line

Not open for further replies.


Newbie level 4
Jan 21, 2013
Reaction score
Trophy points
Activity points
encoder = ra
out = rb.1
direction = rb.0
flash = rb.5

temp = 0Ch
counter = 0Dh
old = 0Eh
new = 0Fh
flag = 1Fh
armed = 1Eh

device pic16c54,rc_osc,wdt_off,protect_on
reset start

org 0

start mov !rb,#00100000b Why is there an exclamation mark?
mov !ra,#255
mov counter,#128
clrb out

mov old, encoder
and old, #00000011b loop
jb flash,test
call check_encoder

flashing cje counter,#128,loop
jb flag,timeout

mov OPTION,#00000111b
mov RTCC,#248
setb flag

timeout mov w,RTCC
jz drive
jmp loop

drive clrb flag
jb out,lower
setb out
clrb armed
jmp cont

lower clrb out
setb armed

cont cja counter,#128,down
clrb direction
snb armed
inc counter
jmp try_done

down setb direction
snb armed
dec counter

try_done cjne counter,#128,loop
clrb flag
jmp loop

check_encoder mov new, encoder
and new, #00000011b
mov temp, new
xor temp, old
jz :return

rl old
xor old, new

jb old.1, :up
:down dec counter

:up inc counter
mov old,new
:return ret

test mov counter,#129
jmp flashing

can someone explain these code to me? especially the one in bold?

anyone can help me? thanks a million
i have to explain it to my supervisor but i don't know how. attachment for the 2 files.


  • Desktop.rar
    3.2 KB · Views: 32

its code of which microcontroller................

it's in PIC16C54. i have to explain what the code means. but i don't get them. especially pin 16. of pic16C54

That is very strange 16C54 code.

What language is it written in? It's an old chip but I've programmed hundreds of them in the past and I don't recognize some of those opcodes.



The file in the attached .rar is a proper Pic16C54 servo motor program with notation.

Seems the # code shown has been doctored, by placing the Device Pic16C54 into it.
Assume it is really something like AVR Assembly doing the similar servo motor control.. ?

Ok. let's start this all over again.
thank you all for your help.

i am trying to understand how this PIC16C54 send data ( pulse and direction ) to the stepper motor driver 5804.
i have attached the data sheet of the kit,pic,stepper motor i am using and the stepper motor driver.

i need your help to understand how this pic16c54 "interact" with the driver. and how the driver analysis the data and move the motor.

note* motor i using page 3/4 (MY5602)


  • 5804 IC.pdf
    155.2 KB · Views: 41
  • k94.pdf
    26.3 KB · Views: 32
  • PI IC.pdf
    2.6 MB · Views: 29
  • MY3002-Astrosyn-datasheet-11809482.pdf
    633.9 KB · Views: 41
  • k94.bmp
    3.7 MB · Views: 25


You really need to first understand the principles of a stepper motors operation.

MicroChip have several application notes on this, some in Assembly, just two links below, search for more.
Also many basic stepper tutorials on the web, again one example below.

Once you understand how they function then it will be easier for you to follow the assembly code.
  • Like
Reactions: eeec


    Points: 2
    Helpful Answer Positive Rating
Not open for further replies.

Part and Inventory Search

Welcome to