Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Some quick help with hex and bits... I think

Status
Not open for further replies.

magician13134

New Member
Hi, I'm trying to interface with an HD44780 LCD, and I've been able to do all the simple things, display characters, clear it, move the cursor back to the home position, etc. But I want to be able to do some more advanced commands, and that's where I'm stuck. I've found a site that has a table of all the commands:
How to control a HD44780-based Character-LCD
But I'm not sure exactly how to use them. The LCD library I'm using has a command write function, so if I do
Code:
lcd.commandWrite(0x01);
it will clear the display,
Code:
lcd.commandWrite(0x02);
will move the cursor to the home position. But after that, I'm confused. After that, I'm not sure how to get the numbers to use in commandWrite(). For example, if I wanted to turn the display on, turn the cursor on and turn the blink on, how would I do that? I know that command is in DB3, so that would be 0x08, right? Then I would need to do to get the options in that? I've read something about using the OR (|) function... But I'm not really very sure... Thanks!!
 
Hi, I'm trying to interface with an HD44780 LCD, and I've been able to do all the simple things, display characters, clear it, move the cursor back to the home position, etc. But I want to be able to do some more advanced commands, and that's where I'm stuck. I've found a site that has a table of all the commands:
How to control a HD44780-based Character-LCD
But I'm not sure exactly how to use them. The LCD library I'm using has a command write function, so if I do
Code:
lcd.commandWrite(0x01);
it will clear the display,
Code:
lcd.commandWrite(0x02);
will move the cursor to the home position. But after that, I'm confused. After that, I'm not sure how to get the numbers to use in commandWrite(). For example, if I wanted to turn the display on, turn the cursor on and turn the blink on, how would I do that? I know that command is in DB3, so that would be 0x08, right? Then I would need to do to get the options in that? I've read something about using the OR (|) function... But I'm not really very sure... Thanks!!

hi,
It sounds like you are working with 'C'.?

How to control a HD44780-based Character-LCD

All the command codes are listed in the link you posted.

Use the commandwrite() for all the commands.

Code:
4.1.3.6. Display mode 
Purpose: - Sets display control
- Required entry mode must be set in W
  b0    : 0 = cursor blink off, 1 = cursor blink on (if b1 = 1)
  b1    : 0 = cursor off,  1 = cursor on
  b2    : 0 = display off, 1 = display on (display data remains in DD-RAM)
  b3-b7 : don't care

Code: LCDDMODE
    ANDLW       0x007               ; Strip upper bits
    IORLW       0x008               ; Function set
    CALL        LCDPUTCMD
    RETURN
 
Last edited:
I understand that they're there, but they aren't quite in the right format... I need a number like this:
0x007 or 0x008 and they just say things like this
"b0 : 0 = cursor blink off, 1 = cursor blink on (if b1 = 1)
b1 : 0 = cursor off, 1 = cursor on
b2 : 0 = display off, 1 = display on (display data remains in DD-RAM)"
How do I turn those 0s and 1s into 0x007 or whatever the number would be?
 
Are you writing in 'C' or Assembler.?
 
Code:
4.1.3.6. Display mode 
Purpose: - Sets display control
- [B]Required entry mode must be set in W[/B]  
  b0    : 0 = cursor blink off, 1 = cursor blink on (if b1 = 1)
  b1    : 0 = cursor off,  1 = cursor on
  b2    : 0 = display off, 1 = display on (display data remains in DD-RAM)
  b3-b7 : don't care

Code: LCDDMODE
    ANDLW       0x007               ; Strip upper bits
    IORLW       0x008               ; Function set
    CALL        LCDPUTCMD
    RETURN

I'll use this code to explain.
Required entry mode must be set in W
Say you want cursor blink off, so b0 =0
say cursor on b1 = 1
say display on b2 =1

so W = xxxxx110
ANDLW to strip any upper bits.
IORLW 0x008 ; select function SET
commandwrite(W)

Does this help.?
 
Ohh, it does. Except... What is IORLW doing to W? I'm a little puzzled. At first I just thought 110 was in binary and the Hex was 8... but it's 6... That's not right. Sorry, I'm new to these bit operations...
And one more thing, Is 0x8 the same as 0x08 the same as 0x008? I wouldn't think so, but I just want to be sure. Because the documentation of the LCD class I'm using (oh, it's C) says to use commandWrite(int) like commandWrite(2). So for 0x008 I would do commandWrite(8), for 0x08 would I do commandWrite(80)? Thanks!
 
Last edited:
Ohh, it does. Except... What is IORLW doing to W? I'm a little puzzled. At first I just thought 110 was in binary and the Hex was 8... but it's 6... That's not right. Sorry, I'm new to these bit operations...
And one more thing, Is 0x8 the same as 0x08 the same as 0x008? I wouldn't think so, but I just want to be sure. Because the documentation of the LCD class I'm using (oh, it's C) says to use commandWrite(int) like commandWrite(2). So for 0x008 I would do commandWrite(8), for 0x08 would I do commandWrite(80)? Thanks!

Surely this would only write 8.??? 00001000
Whats happened to b2,b1 and b0.?
Shouldnt it be 00001110 as per the example.
 
Last edited:
Maybe that was just for the first one commandWrite(1) since that's only B0...

Anyway, I'm still not able to figure this out myself. I understand what you said, so if I wanted blink on, then it would be 111 after stripping, and then pass through the IORLW command to get... something. I don't know how to do that command... Is there a calculator for that online or something? Thanks
 
Ohh, it does. Except... What is IORLW doing to W? I'm a little puzzled. At first I just thought 110 was in binary and the Hex was 8... but it's 6... That's not right. Sorry, I'm new to these bit operations...
And one more thing, Is 0x8 the same as 0x08 the same as 0x008? I wouldn't think so, but I just want to be sure. Because the documentation of the LCD class I'm using (oh, it's C) says to use commandWrite(int) like commandWrite(2). So for 0x008 I would do commandWrite(8), for 0x08 would I do commandWrite(80)? Thanks!

IORLW 0x08; sets b3 to '1' Function command bit.
it dosnt affect the other bits.
 
I'm sorry, but that makes me even more confused. So does 110 equal 0x08? If so how? What does something like 111 equal in that format? I can't test if this function is working because LCD on, cursor on, no blink (0x08) is the default, let's say I wanted to turn the cursor off. That gives me 100. What do I do with that number. I'm in C and I don't see an IORLW command... Thank you...
 
Maybe that was just for the first one commandWrite(1) since that's only B0...

Anyway, I'm still not able to figure this out myself. I understand what you said, so if I wanted blink on, then it would be 111 after stripping, and then pass through the IORLW command to get... something. I don't know how to do that command... Is there a calculator for that online or something? Thanks


hi,
I use MPLAB assembler not 'C'

Why dont work out all the command codes you want to use and give them a label, then commandwrite(label)
eg: for the example shown CurNoBlink equ decimal 15; or 0x0e

Use the corresponding define/equ in the 'C' language

then commandwrite(CurNoBlink)
 
Ok, that sounds good, but how did you find out that cursor no blink equals fifteen? That's the part I'm having trouble with.

Code:
I'll use this code to explain.
Required entry mode must be set in W
Say you want cursor blink off, so b0 =0 
say cursor on b1 = 1
say display on b2 =1

[B]so W = xxxxx110 [/B]
ANDLW to strip any upper bits.
[B]IORLW 0x008 ; select function SET,,,, [COLOR="Blue"]Now xxxx1110 = 0x0e = 14[/COLOR][/B]
commandwrite(W)

Look at the edited code.

example #2 for blink on, cursor on display on,,,,, xxxxx1111

IORLW 0x08; set b3 to '1'

so xxxx1111 == 0x0f = 15

I made a typo in previous post 0x0e = 14 , sorry about that.:)

So you could have a label CurOnBlinkOn equ 0x0f ; 15
 
Last edited:
I think I understand what you're talking about when you mention using an OR operator to put together the LCD commands. I think that might be similar to what I did awhile back. First I defined the various command bit masks like this;

Code:
;
;  44780 LCD command bit masks
;
Clear   equ     b'00000001'     ; Clear (1.53 msecs)
Home    equ     b'00000010'     ; Home (1.53 msecs)
;
;  44780 "entry mode set" bit masks
;
CursInc equ     b'00000110'     ;
CursDec equ     b'00000100'     ;
ShftOn  equ     b'00000101'     ;
ShftOff equ     b'00000100'     ;
;
;  44780 "display on/off control" bit masks
;
DispOn  equ     b'00001100'     ;
DispOff equ     b'00001000'     ;
CursOn  equ     b'00001010'     ;
CursOff equ     b'00001000'     ;
BlnkOn  equ     b'00001001'     ;
BlnkOff equ     b'00001000'     ;
;
;  44780 "cursor/display shift" bit masks
;
CursRt  equ     b'00010100'     ; shift cursor right
CursLt  equ     b'00010000'     ; shift cursor left
ShftRt  equ     b'00011100'     ; shift display right
ShftLt  equ     b'00011000'     ; shift display left
;
;  44780 "function set" bit masks
;
m8bits  equ     b'00110000'     ; select 8 bit interface
m4bits  equ     b'00100000'     ; select 4 bit interface
m1line  equ     b'00100000'     ; select 1 line display
m2line  equ     b'00101000'     ; select 2 line display
fon5x7  equ     b'00100000'     ; select 5x7 font
;
cgram   equ     b'01000000'     ; CGRAM + 0..63
;
; ddram addresses
;
        radix   dec
line0   equ     128+0           ;
line2   equ     128+64          ;
line3   equ     128+20          ;
line4   equ     128+64+20       ;
And here's an example of how you might use the commands. Remember to OR only the commands which belong to the same group.

Code:
;
        call    InitLCD         ; initialize LCD subsystem        |B0
        PutLCD  cmd,Home        ; set ddram addr to 'home'        |B0
;
;  "entry mode set"
;
        PutLCD  cmd,CursInc|ShftOff
;
;  "display on/off control"
;
        PutLCD  cmd,DispOn|CursOn|BlnkOff
        PutLCD  cmd,DispOff
        PutLCD  cmd,DispOn|CursOff
;
        PutLCD  cmd,cgram+0     ; cgram addr + 0 (char '0')       |B0
        PutLCD  dat,b'00100'    ; upload char 0 "Up Arrow"        |B0
        PutLCD  dat,b'01110'    ;                                 |B0
        PutLCD  dat,b'11111'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00000'    ;                                 |B0
        PutLCD  cmd,cgram+8     ; cgram addr + 8 (char '1')       |B0
        PutLCD  dat,b'00100'    ; upload char 1 "Dn Arrow"        |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'11111'    ;                                 |B0
        PutLCD  dat,b'01110'    ;                                 |B0
        PutLCD  dat,b'00100'    ;                                 |B0
        PutLCD  dat,b'00000'    ;                                 |B0
;
        PutLCD  cmd,line1       ; ddram line 1, htab 0            |B0
        PutLCD  dat,0           ; the <up> arror char             |B0
        PutLCD  cmd,line1+3     ; ddram line 1, htab 3            |B0
        PutLCD  str,"K8LH Clock"
        PutLCD  cmd,line2       ; ddram line 2, htab 0            |B0
        PutLCD  dat,1           ; the <dn> arrow char             |B0
        PutLCD  cmd,line2+4     ; ddram line 2, htab 4            |B0
        PutLCD  str,"HH:MM:SS"
 
Yup, that makes a ton of sense. That's probably where I got the idea from, seeing code like that. I was wondering how to do that today too, so thanks for that too. :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top