0
\$\begingroup\$

I installed a NHD-0216HZ-FSW-FBW-33V3C with an MSP430g2553. I tried to initialize it for 4-bit mode in assembly language but black boxes still shown and initialization is not completed I think.

My connections are: DB4-DB7 --> P1.4-P1.7 respectively, RS --> P2.0, R/W --> P2.1, Enable --> P2.2

Here is my code:

Init:     bic.b     #0xFF,P1OUT  ;Clear P1, P1 = 0
      bis.b     #0x01,&P2OUT ;High RS = 1
      bic.b     #0x01,&P2OUT ;Clear RS = 0
      call      #Delay100ms
      mov.b     #0x30,&P1OUT 
      call      #Nibble      ;Wake up 1
      call      #Delay10ms 
      call      #Nibble      ;Wake up 2
      call      #Delay10ms       
      mov.b     #0x20,P1OUT
      call      #Nibble      ;Wake up 3
      call      #Command28
      call      #Command10
      call      #Command0F
      call      #Command06
      ret
Nibble  bis.b      #0x04,&P2OUT ;Enable High
      call       #Delay1ms
      bic.b      #0x04,&P2OUT ;Clock Enable - Falling Edge
      ret
Command28     mov.b     #0x28,&P1OUT //Data in port
      bic.b     #1,&P2OUT    //RS = 0 : Send Instruction
      bic.b     #0x02,&P2OUT //R/W = 0 : Write
      call      #Nibble      //Send Lower 4 Bits
      mov.b     #0x28,R4
      push      R4
      mov.b     #4,R5       ;Rotate Left Counte
C28           rla.b     R4
      dec       R5
      jnz       C28
      mov.b     R4,&P1OUT   //put data in output port
      call      #Nibble     //Send upper 4 bits
      pop       R4
      and.b     #0xF0,R4
      mov.b     R4,&P1OUT
      ret

This code is following the code in the NHD-0216HZ-FSW-FBW-33V3C datasheet from http://www.newhavendisplay.com/specs/NHD-0216HZ-FSW-FBW-33V3C.pdf. If someone can help me.

\$\endgroup\$
1
\$\begingroup\$

First of all: While the datasheet doesn't say it explicitly, the display you're working with is fully compatible with the Hitachi HD44780 display standard. (It's even using the same pinout as most HD44780 boards.)

Anyways. The behavior you're describing is typical of an HD44780 display that hasn't been initialized properly. In your case, this is because you're not sending the low halves of the "wake up" commands! These commands are like all the others; if you're using the 4-bit interface, you have to send the high half followed by the low half. My sample code sends 20, 20, 20, 28 (or, that is, 2, 0, 2, 0, 2, 8) to force the display into 4-bit mode; I'd recommend you do the same in your code, instead of putting the display temporarily into 8-bit mode with 30.

Additionally, I'd strongly recommend that you write a single routine to send the two nibbles of a byte to the display, rather than creating a bunch of separate hard-coded routines like the Command28 you have here. Your code will become a lot simpler once you've done this.

\$\endgroup\$
  • \$\begingroup\$ How can I write a single subroutine? \$\endgroup\$ – EMPV Nov 22 '15 at 6:09
  • \$\begingroup\$ The Command28 subroutine that you have in your question is almost there. Instead of loading the constant #0x28 to P1OUT and later into R4, pass it as an argument in a register. \$\endgroup\$ – duskwuff Nov 22 '15 at 6:28
  • \$\begingroup\$ Thank a lot, you really helped me. I eliminated a lot of code. \$\endgroup\$ – EMPV Nov 22 '15 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.