Questions regarding interfacing and custom characters for NHD-C0216CZ-FSW-FBW-3V
Hello!,
I'm currently evaluating a NHD-C0216CZ-FSW-FBW-3V. I've managed to establish basic communication through the synchronous serial interface (basically SPI, from what I can determine), and am able to do things such as clear the display, move the cursor, and print standard characters.
I'm running into some confusion is in a couple areas.
- How do I actually determine what the OSC speed is? The datasheet only seems to provide that OSC speed can be changed with the F2~0 bits, but has no indication as to what specifically the bits control in terms of the ST7032 oscillator speed?
- Reading the "Read Busy Flag and Address" or "Read Data From RAM" registers seems to be impossible? This display seems to be write only given the absence of a R/W pin of any kind? So why even list the command in the datasheet? Am I missing something?
- To write a custom character into CGRAM, from my understanding consists of simply setting the CGRAM address, then writing 8 bytes of data each containing a single 5-bit line of data. This does not seem to work when I have tried it. I will elaborate on exactly how I am trying below. Am I correct that CGRAM locations 0x00 to 0x0F should be free for me to use for custom characters?
[EDIT: Got the custom characters working properly, see my post below]
Regarding #3 in particular, I want to make sure I'm following the correct steps to set the CGRAM character data for CGRAM Addr == 0x00. Here are the functions I wrote to handle communication:
#define NHD_0216CZ_LINE_LEN 16
#define NHD_0216CZ_SET_DDRAM_MASK 0x80
#define NHD_0216CZ_SET_CGRAM_MASK 0x40
/* NHD_WriteCom
* - Sets REGSEL to 0 (Command) and writes a byte to the display
*/
void NHD_WriteCom(uint8_t command){
NHD_REGSEL_Write(0);
SPIM_WriteByte(command);
}
/* NHD_WriteData
* - Sets REGSEL to 1 (Data) and writes a byte to the display
*/
void NHD_WriteData(uint8_t data){
NHD_REGSEL_Write(1);
SPIM_WriteByte(data);
}
void NHD_Putc(char c){
NHD_WriteData((uint8_t)c);
}
/** NHD_Init
* - Initializes the NHD Display (per datasheet example)
*/
void NHD_Init(void){
SPIM_Start();
NHD_RESET_Write(0);
CyDelay(2);
NHD_RESET_Write(1);
CyDelay(20);
NHD_WriteCom(0x30); //WakeUp
CyDelay(2);
NHD_WriteCom(0x30); //WakeUp
NHD_WriteCom(0x30); //WakeUp
NHD_WriteCom(0x39); //Function Set
NHD_WriteCom(0x14); //Internal Osc Freq
NHD_WriteCom(0x56); //Power Control
NHD_WriteCom(0x6D); //Follower Control
NHD_WriteCom(0x70); //Contrast
NHD_WriteCom(0x0C); //Display ON
NHD_WriteCom(0x06); //Entry Mode
NHD_WriteCom(0x01); //Clear Display
CyDelay(10);
}
/** NHD_SetCursor
* - Sets display DDRAM location to desired Row/Column of the display
*/
void NHD_SetCursor(uint8_t row, uint8_t col){
uint8_t cmd = 0;
row = CLAMP_HIGH(row,1); //0-1
col = CLAMP_HIGH(col, NHD_0216CZ_LINE_LEN-1); //0-15
/*|1|AC6|AC5|AC4|AC3|AC2|AC1|AC0|*/
cmd = NHD_0216CZ_SET_DDRAM_MASK | (row << 6) | (col);
NHD_WriteCom(cmd);
CyDelayUs(30);
}
/** NHD_SetCGRAM_Addr
* - Sends command to set the CGRAM Address to the passed in address
*/
void NHD_SetCGRAM_Addr(uint8_t addr){
uint8_t cmd = 0;
/*|0|1|AC5|AC4|AC3|AC2|AC1|AC0|*/
cmd = (NHD_0216CZ_SET_CGRAM_MASK | (addr & 0x7F));
NHD_WriteCom(cmd);
CyDelayUs(30);
}
/** NHD_SetCharacterData
* - Sets data at specified CGRAM address to passed in custom character data
*/
void NHD_SetCharacterData(uint8_t cg_addr, uint8_t * data){
uint8_t i = 0;
cg_addr = CLAMP_HIGH(cg_addr,0x3F); //Constrain to 0x3F max address
NHD_SetCGRAM_Addr(cg_addr);
for (i = 0; i < NHD_0216CZ_CHAR_H; i++){
NHD_WriteData(data[i]); //This should increment CGRAM Address automatically each write
CyDelayUs(30);
}
}
I am using them as follows to try and write a repeating custom character across the entire display:
/*Custom Character, Half 1, Half 0*/
static uint8_t CustomChar[8] = { 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F};
NHD_Init();
NHD_SetCursor(0,0); //Cursor To Top Row
NHD_SetCharacterData(0x00,CustomChar); //Set CGRAM 0x00 to our custom character
/*Set all characters in top row to 0x00 (custom character)*/
for (uint8_t i = 0; (i < NHD_0216CZ_LINE_LEN); i++){
NHD_Putc(0x00);
CyDelayUs(30);
}
CyDelay(1); //1ms between lines (probably not needed)
/*Set all characters in bottom row to 0x00 (custom character)*/
NHD_SetCursor(1,0); //Cursor To Bottom Row
for (uint8_t i = 0; (i < NHD_0216CZ_LINE_LEN); i++){
NHD_Putc(0x00);
CyDelayUs(30);
}
I can replace the NHD_Putc(0x00) with something like NHD_Putc('A') and the 'A' character is displayed correctly, so I figure it's probably an issue with how I am setting the CGRAM.
Could someone clarify how this is supposed to work?
Thanks!
-
After going over it again I figured out what was going on with the CGRAM and my custom characters.
I was assuming that the Instruction Table bits (IS<2:1>) were 00, when it turns out the initialization code for the panel (specifically, writing the 0x39 command) sets the IS bits to 01. So I was sending the "Write CGRAM" command to the wrong instruction set.
When I ensure the IS bits are cleared to 00, then perform the write to CGRAM, my custom character is written and I am able to print it as I would any other character in the table.
Would still appreciate clarifications on #1 and #2 if possible.
Thanks!
0 -
Hello Kyle,
It is great to hear you figured out your custom character issue.
Regarding your other questions:
- The ST7032 datasheet provides more information on the OSC speed adjustment. Please see page 26 for details.
- Unfortunately, it is not possible to read using the display's serial interface. The serial data pin is input only.
If you have any questions, don't hesitate to ask.
Best Regards,
Cody J
0 -
Hi Cody,
Appreciate the reply. I have been through the ST7032 datasheet but all that gives me is the details on how Frame Frequency is changed with F<2:0>, with nothing about how it affects OSC:
Is there a way to derive the OSC frequency from the frame frequency?
Thanks!
0 -
Hello Kyle,
Digging deeper into the ST7032 datasheet, the LCD Frame Frequency section starting on page 50 contains information that may help you derive OSC frequency from frame frequency.
Best Regards,
Cody J
0
Please sign in to leave a comment.
Comments
4 comments