0
\$\begingroup\$

Problem :

I'm using PIC16F84A as microcontroller , wh1602a (LCD) [16x2] , and two push buttons. I want to give the user two options say option 1 and option 2 on the display and the user presses one push button to hover between the options and one push button to confirm one of the options.

My attempt:

I thought about doing it as frames for example initially I start at frame one:

-> Option 1
 Option 2 

then once the hover button is pressed I clear the LCD and move to frame 2 which is

 Option 1
 -> Option 2 

and so on.

§ Can I move the cursor to any location on the LCD 16x2 map ?

§ How can I keep track of the cursor location ?

The manual of the LCD display is :

http://aquacontrol.narod.ru/spravka/WH1602A-YGH-CTK.pdf

asked Apr 7, 2018 at 6:10
\$\endgroup\$
1
  • \$\begingroup\$ Note I'm using 4 bit MODE \$\endgroup\$ Commented Apr 7, 2018 at 6:15

1 Answer 1

0
\$\begingroup\$

How can I keep track of the cursor location ?

With an 'int'. If the LCD is 16x2, then the cursor location could be tracked by a 5 bit integer (from 0 to 31). "Keeping track" translates to programmer lingo as keeping a variable in memory with the relevant data.

There isn't an instruction available on this module to get current position info, so you must keep track of it yourself every time it updates. This may require experimentation, as the datasheet is very non-descriptive about what each instruction does. If the position is updated in any given instruction, then update this variable accordingly until you get it right.

Can I move the cursor to any location on the LCD 16x2 map ?

Yes, with the cursor or display shift instruction. To get it to an exact location would mean making use of the tracking variable you already have in memory.

Now does it increment by itself when I print a letter? Or do I have to increment it myself. How is this variable I created linked to the LCD Display. For instance if I print letter 'H' on the screen how can I get the value of the cursor ?

The variable belongs to your code, so your code must update it. The module is oblivious to this variable's existance. Say we know, through experimentation, that each time you call instruction X the cursor moves Y positions. Therefore, the tracking variable must be updated by Y any time X is called. If printing letter 'H' makes the cursor move, then increment your variable by 1. If it does not, then keep the variable as is.

In the data sheet there is this row Set DDRAM Address 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 Set DDRAM address in address counter I'm using 4 bit mode so I can only make use of D7 D6 D5 D4 I can't find the suitable commands for the 4 bit mode.

In 4 bit interface, these longer instructions are broken down to 2 separate instructions. Refer to page 18 of the datasheet for an example.

answered Apr 7, 2018 at 6:36
\$\endgroup\$
3
  • \$\begingroup\$ Thank you for the reply , I'm working with MPLAB assembly code so what I did was EQU ADDRESSCURSOR d'13' which means I allocated memory address 13 to address of the cursor . Now does it increment by itself when I print a letter? Or do I have to increment it myself. How is this variable I created linked to the LCD Display. For instance if I print letter 'H' on the screen how can I get the value of the cursor ? \$\endgroup\$ Commented Apr 7, 2018 at 7:05
  • \$\begingroup\$ In the data sheet there is this row Set DDRAM Address 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 Set DDRAM address in address counter I'm using 4 bit mode so I can only make use of D7 D6 D5 D4 I can't find the suitable commands for the 4 bit mode. \$\endgroup\$ Commented Apr 7, 2018 at 7:10
  • \$\begingroup\$ I had misunderstood what you meant by "cursor", i thought you meant the arrow pointing to an option. I will update the answer to better fit what you need. \$\endgroup\$ Commented Apr 7, 2018 at 7:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.