PDA

View Full Version : Driving the SmartDisplay, first impressions



astouffer
- 17th December 2008, 03:48
After a bit of trial and error and the help of a co-worker I got the NKK SmartDisplay up and running. First of all the chip select pin is an active low and initially I had it tied directly to ground. That resulted in very erratic and random operation. Chip select is now tied to a pin on the pic with a 10k pullup and then set low at the start of the program.

http://www.nkksmartswitch.com/media/pdf/IS01DBFRGB.pdf

To display anything useful you have to use shiftout with MSBFIRST and send the command $40 and then $FF to turn on all three leds for a white background. Next send $41 and $FF all leds at full brightness.

To send data to the lcd it expects $55 and then the full 256 bytes to set every pixel (64x32). When sending display data LSBFIRST must be used. The display is non addressable so any changes need to be made to the array and sending out the entire contents again. Right now that is 32 SHIFTOUT commands with 8 hex values each. The display has its own RAM so it does not need to be written to continuously.

We plan to use the display as an indicator that's only updated when the user makes changes to a pot, almost like a volume indicator. Drawing the letters pixel by pixel isn't that big a deal. I found the article at EDN using an excel sheet to get the hex values.

Tell me if I'm on the right track as far as updating the display. An initial array template is created and written to RAM or the EEPROM at startup. Then the contents are read and sent to the display. Numbers 0-9 will be defined as a group of bytes and be given the corresponding variable name. If an update is needed the hex values for the digit are written to the relevant part of the array in memory and then the entire contents are sent to the display.

The chip I'm using is the 16F876A but I'm not sure where this should be done, in the EEPROM or data RAM? I found the post by Mel about using code space as extra memory but which to actually go with? Any feedback is appreciated.

Darrel Taylor
- 22nd December 2008, 00:43
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="900" HEIGHT="600" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com/files/NKK/NKKmodes.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com/files/NKK/NKKmodes.swf" WIDTH="900" HEIGHT="600" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>

Are you using the USART for anything else in this project?
And is this thing on a breadboard, or already on PCB?

astouffer
- 22nd December 2008, 17:47
Are you using the USART for anything else in this project?
And is this thing on a breadboard, or already on PCB?

Wow, pretty impressive! No the USART is not being used for anything and everything is on a piece of vector board now. The main purpose of the pic is to control the speed of two motors via pots and then hpwm to a L298N chip. A few pins are used for limit switches and thats about the extent until this display idea came up. All that code is running fine. The display shouldn't update unless the adcin value changes.

Two speeds need displayed, something like this:

RPM:
400
IPS:
0.70

or like

RPM IPS
600 0.40

Only the first two digits of rpm will change (560,570) and ips will never go above 0.80. Many thanks for your time.

Darrel Taylor
- 23rd December 2008, 00:43
OK, I think I've got it all turned around the right way now. :o
And there's some options to flip it around different ways if it's not, so hopefully this should do it.

I was asking about the USART, because it's possible to use it in Sychronous mode to drive the display really fast, but it only sends data LSB first so I needed to reverse the bit order in case you want to use it. But for now, let's stick with SHIFTOUT.

Note: You MUST be assembling with MPASM. The default PM.exe will not work.<hr>
There are 8 modes that are selectable at any time.
Simply set the variable NKKmode to the mode number and update the display.
See the mode examples in post #2. <hr>
There are 5 commands for use with the NKK display.


NKKclear&nbsp; - clears the screen
NKKtext&nbsp;&nbsp; - write Text at a specified location
NKKbyte&nbsp;&nbsp; - display a BYTE variable
NKKword&nbsp;&nbsp; - display a WORD variable
NKKupdate - Update the Display
<hr>
NKKclear

This will clear the screen buffer in memory.

@ NKKclear ; clear the NKK screen buffer
You must call NKKupdate for the changes to be seen.

NKKtext (row, col, "Text")

Displays a string of text at the specified location.

@ NKKtext (1,1,"RPM:")
Above code displays RPM: at Row1 Column1.
The end of each row wraps to the beginning of the next row. So you can actually fill the entire display with 1 command of 40 chars.

@ NKKtext (1,1,"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ=%$&")


NKKbyte (row, col, width, justification, Variable)

Displays a BYTE variable in a fixed width field, with leading zero blanking and left or right justification.

@ NKKbyte (1,3,3,right,ByteVar)
The line above would display the value in ByteVar at Row1 Column3.
The field size is 3 characters, and it will be Right justified with leading 0's blanked.
Justification can be LEFT, RIGHT or ZEROS. Zeros will NOT blank the leading 0's.


NKKword (row, col, width, justification, Variable)
Displays a WORD variable in a fixed width field, with leading zero blanking and left or right justification.

@ NKKword (2,2,4,right,RPM) ; Display RPM
The line above would display the WORD value in RPM at Row2 Column2.
The field width is 4 characters, right jusified.
Justification can be LEFT, RIGHT or ZEROS. Zeros will NOT blank the leading 0's.


NKKupdate - Update the Display

This command does most of the work. It actually sends the screen to the display.
The other commands only work on the character buffer.
After they are done changing the buffer, call this to see them displayed.

@ NKKupdate ; Send data to the display

<hr>
There are 2 options available

NKK_LSBFIRST

This option reverses the bit order of each byte being sent.
This would be useful when using the USART's synchronous mode.
If using SHIFTOUT or the MSSP module. Do not use this option, and send all data MSB first.

DEFINE NKK_LSBFIRST


NKK_REVERSED - Scans Left to Right

This option makes a mirror image of the display.
It's mainly there for me to debug with HyperTerminal.

DEFINE NKK_REVERSED

<hr>

This is a test program that I believe you should start with.
You will need to fill in the NKKstartData: and NKKsendByte: subroutines with SHIFTOUT statements to interface with your display.
Just follow the comments.
RPM VAR WORD
IPS VAR WORD

INCLUDE "NKK.pbp"

Initialize:
NKKmode = 6 ; 4x5 mode
@ NKKclear ; clear the NKK screen buffer
@ NKKtext (1,1,"RPM:") ; row 1, column 1
@ NKKtext (3,1,"IPS:") ; row 3, column 1
@ NKKtext (4,2,"0.") ; row 4, column 2

;----[ The Main Loop ]------------------------------------------------------
Main:
@ NKKword (2,2,4,right,RPM) ; Display RPM
@ NKKword (4,4,2,zeros,IPS) ; Display IPS
@ NKKupdate ; Send data to the display
RPM = RPM + 10
IPS = IPS + 2
PAUSE 1000
GOTO Main

;----[ Send Command to start Display Data Transfer ]------------------------
NKKstartData:
; *** this subroutine should send the $55 command ***

RETURN

;----[ Send 1 byte to the NKK display ]-------------------------------------
NKKsendByte:
; *** this subroutine should send one byte at a time ***
; *** The byte to send is in the variable OutByte ***
; *** Send the data MSB first ***

RETURN

You'll also need to turn on the backlight yourself.

If all goes well, it should look something like this.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3139" /><!-- 3139 -->

Download the NKK.pbp file below, and remove the .txt extension.
Place it in your PBP folder. Usually c:\PBP. Or you can put it in the same folder as your main program file.

The whole thing compiles to about 1400 words on a 16F, or 2600 bytes on an 18F.
Good Luck!

astouffer
- 23rd December 2008, 20:05
Here is my compiled code.



@ __CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify
CMCON = %00000111 'comparators off

TRISC.3 = 0 'clock
TRISC.4 = 0 'chip select active low
TRISC.5 = 0 'data

RPM VAR WORD
IPS VAR WORD
clock VAR PORTC.3
sdata VAR PORTC.5

INCLUDE "NKK.pbp"
Include "modedefs.bas"

shiftout clock,sdata,MSBFIRST,[$40] 'led color command
shiftout clock,sdata,MSBFIRST,[%00111011] 'teal
shiftout clock,sdata,MSBFIRST,[$41] 'led bright command
shiftout clock,sdata,MSBFIRST,[%11111111] 'full bright

Initialize:
NKKmode = 6 ; 4x5 mode
@ NKKclear ; clear the NKK screen buffer
@ NKKtext (1,1,"RPM:") ; row 1, column 1
@ NKKtext (3,1,"IPS:") ; row 3, column 1
@ NKKtext (4,2,"0.") ; row 4, column 2

;----[ The Main Loop ]------------------------------------------------------
Main:
@ NKKword (2,2,4,right,RPM) ; Display RPM
@ NKKword (4,4,2,zeros,IPS) ; Display IPS
@ NKKupdate ; Send data to the display
RPM = RPM + 10
IPS = IPS + 2
PAUSE 1000
GOTO Main

;----[ Send Command to start Display Data Transfer ]------------------------
NKKstartData:
shiftout clock,sdata,MSBFIRST,[$55] 'xfer data command
; *** this subroutine should send the $55 command ***

RETURN

;----[ Send 1 byte to the NKK display ]-------------------------------------
NKKsendByte:
shiftout clock,sdata,MSBFIRST, [1]
; *** this subroutine should send one byte at a time ***
; *** The byte to send is in the variable OutByte ***
; *** Send the data MSB first ***

RETURN


What displays is 8 vertical lines, each 1 pixel wide. How many bytes should be sent in that last subroutine? Many thanks again for your time and help.

Darrel Taylor
- 23rd December 2008, 20:34
The shiftout in the NKKsendByte: routine is always sending a 1, not the data.

I know I said to send 1 byte, but I didn't actually mean to send a 1. :)
<br>

astouffer
- 29th December 2008, 17:25
@ __CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify
CMCON = %00000111 'comparators off

TRISC.3 = 0 'clock
TRISC.4 = 0 'chip select active low
TRISC.5 = 0 'data

RPM VAR WORD
IPS VAR WORD
clock VAR PORTC.3
sdata VAR PORTC.5

INCLUDE "NKK.pbp"
Include "modedefs.bas"

shiftout clock,sdata,MSBFIRST,[$40] 'led color command
shiftout clock,sdata,MSBFIRST,[%00111011] 'teal
shiftout clock,sdata,MSBFIRST,[$41] 'led bright command
shiftout clock,sdata,MSBFIRST,[%11111111] 'full bright

Initialize:
NKKmode = 6 ; 4x5 mode
@ NKKclear ; clear the NKK screen buffer
@ NKKtext (1,1,"RPM:") ; row 1, column 1
@ NKKtext (3,1,"IPS:") ; row 3, column 1
@ NKKtext (4,2,"0.") ; row 4, column 2

;----[ The Main Loop ]------------------------------------------------------
Main:
@ NKKword (2,2,4,right,RPM) ; Display RPM
@ NKKword (4,4,2,zeros,IPS) ; Display IPS
@ NKKupdate ; Send data to the display
RPM = RPM + 10
IPS = IPS + 2
PAUSE 1000
GOTO Main

;----[ Send Command to start Display Data Transfer ]------------------------
NKKstartData:
shiftout clock,sdata,MSBFIRST,[$55] 'xfer data command
; *** this subroutine should send the $55 command ***

RETURN

;----[ Send 1 byte to the NKK display ]-------------------------------------
NKKsendByte:
; *** this subroutine should send one byte at a time ***
; *** The byte to send is in the variable OutByte ***
; *** Send the data MSB first ***

RETURN


Hope everyone enjoyed their time off this past week. Now back to coding :)

Compiling the test program as above lights up the back light but nothing gets displayed. I tried defining the IPS and RPM vars with values in case that was the problem but nothing changed. Any ideas?

Darrel Taylor
- 29th December 2008, 19:54
Guess my hint didn't work too well.

Put this line in the NKKsendByte: subroutine.

shiftout clock,sdata,MSBFIRST, [OutByte]

astouffer
- 30th December 2008, 17:23
Doh, it was pretty much spelled out for me. Everything works but I had to change the NKKsendByte: to LSBFIRST because it was garbled. Again many thanks and let me know where to send the case of beer :D

Darrel Taylor
- 30th December 2008, 22:13
Great! I'm glad you got it working.

I'd REALLY like to have that BEER. But it always seems to go FLAT after shipment through Email. :D

If you have a camera, I'd love to see a picture of the display working.
Maybe next to your thumb, or a coin or something.

Best regards,