What is JB used for here?

Toby picture Toby · Nov 20, 2012 · Viewed 22.3k times · Source

I'm trying to understand some example asm that came with a development board (XL400), with a view to converting it to C.

The asm code is included below, unfortunately the documentation, such as it is, is translated very badly from Chinese, which makes it worse than useless. Also its a long time since I've used asm!

In the code there is a JB instruction in the DELAY subroutine (third last line of code). I cannot understand what it does or how it is supposed to operate. Googling JB results in explanation for a different form (JB label) so Im not sure if the asm is right even?? Help much appreciated, Ta

 RS EQU P2.0
 RW EQU P2.1
 E EQU P2.2
 ORG 0080H
 MOV P0,#00000001B  ;- Screen
 ACALL ENABLE
 MOV P0,#00000001B  ;- Screen
 ACALL ENABLE
 MOV P0,#00111000B  ;Display
 ACALL ENABLE
 MOV P0,#00001111B  ;Show switch control
 ACALL ENABLE
 MOV P0,#00000110B  ;Input mode
 ACALL ENABLE
 MOV P0,#0C0H       ;Data memory address
 ACALL ENABLE
 mov p0,#01000001b  ;ASCII code
 SETB RS
 CLR RW
 CLR E
 ACALL DELAY
 SETB E
 AJMP $

ENABLE: CLR RS           ;Send orders
 CLR RW
 CLR E
 ACALL DELAY
 SETB E
 RET

DELAY: MOV P0,#0FFH
 CLR RS
 SETB RW
 CLR E
 NOP
 SETB E
 JB P0.7,DELAY      ;Judgement busy signs
 RET

 END

Answer

fvu picture fvu · Nov 20, 2012

The JB instruction in 8051 assembler jumps to the address indicated by the label in the second operand if the bit specified by the first operand is set. So in your case it will jump to MOV P0,#0FFH if P0.7 is set.

The JB label instruction you are referring to is an 8086 instruction (jump below based on the result of the CMP instruction just before) so you were looking on the wrong page.

EDIT: I don't know exactly what type of LCD they're using but I think it's the busy flag - as these displays are all rather closely related to the venerable Hitachi 44780. In the board's schematic P0.7 is connected to display pin 14, which commonly is DB7, and that's where the busy flag lives. Of course it's always best to use the documentation of the actual display, but this one is probably pretty close and could get you started. Also, that display is so popular that it's very easy to find code in all possible languages on howto program it. Might be easier to follow that route than to reverse engineer the assembly.