0
\$\begingroup\$

I have a ts12864a-2v2 LCD and I think its controller is KS0108B. I have downloaded this lib to use it for my LCD and also my MCU is STM32F103RET6. the schematic I have used to connect LCD to MCU is this:

figure1

And the MCU's pins are connected to the LCD like this:

MCU       LCD
PB0  -->  DB0
PB1  -->  DB1
PB2  -->  DB2
PB3  -->  DB3
PB4  -->  DB4
PB5  -->  DB5
PB6  -->  DB6
PB7  -->  DB7
PB8  -->  RES
PB9  -->  R/W
PB10 -->  E
PB11 -->  CSA
PB12 -->  CSB

please consider the D/I pin is NC(not connected). is it neccessory? I couldn't find anything about it in the KS0108-STM32.c file.

And the circuit is this:

figure2

The KS0108-STM32.c is this:

#include "stm32f10x.h"

#define KS0108_PORT  GPIOB

#define KS0108_RS    GPIO_Pin_8
#define KS0108_RW    GPIO_Pin_9
#define KS0108_EN    GPIO_Pin_10

#define KS0108_CS1   GPIO_Pin_11
#define KS0108_CS2   GPIO_Pin_12
#define KS0108_CS3   GPIO_Pin_13

#define KS0108_D0    0

#define DISPLAY_STATUS_BUSY 0x80

extern unsigned char screen_x;
extern unsigned char screen_y;

GPIO_InitTypeDef GPIO_InitStructure;

//-------------------------------------------------------------------------------------------------
// Delay function /for 8MHz/
//-------------------------------------------------------------------------------------------------
void GLCD_Delay(void)
{
  __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop");
}
//-------------------------------------------------------------------------------------------------
// Enalbe Controller (0-2)
//-------------------------------------------------------------------------------------------------
void GLCD_EnableController(unsigned char controller)
{
switch(controller){
    case 0 : GPIO_ResetBits(KS0108_PORT, KS0108_CS1); break;
    case 1 : GPIO_ResetBits(KS0108_PORT, KS0108_CS2); break;
    case 2 : GPIO_ResetBits(KS0108_PORT, KS0108_CS3); break;
    }
}
//-------------------------------------------------------------------------------------------------
// Disable Controller (0-2)
//-------------------------------------------------------------------------------------------------
void GLCD_DisableController(unsigned char controller)
{
switch(controller){
    case 0 : GPIO_SetBits(KS0108_PORT, KS0108_CS1); break;
    case 1 : GPIO_SetBits(KS0108_PORT, KS0108_CS2); break;
    case 2 : GPIO_SetBits(KS0108_PORT, KS0108_CS3); break;
    }
}
//-------------------------------------------------------------------------------------------------
// Read Status byte from specified controller (0-2)
//-------------------------------------------------------------------------------------------------
unsigned char GLCD_ReadStatus(unsigned char controller)
{
unsigned char status;

GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 0xFF << KS0108_D0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(KS0108_PORT, &GPIO_InitStructure);

GPIO_SetBits(KS0108_PORT, KS0108_RW);
GPIO_ResetBits(KS0108_PORT, KS0108_RS);
GLCD_EnableController(controller);
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, KS0108_EN);
GLCD_Delay();
status = ((GPIO_ReadInputData(KS0108_PORT) >> KS0108_D0) & 0xFF);
GPIO_ResetBits(KS0108_PORT, KS0108_EN);
GLCD_DisableController(controller);
return status;
}
//-------------------------------------------------------------------------------------------------
// Write command to specified controller
//-------------------------------------------------------------------------------------------------
void GLCD_WriteCommand(unsigned char commandToWrite, unsigned char controller)
{
while(GLCD_ReadStatus(controller)&DISPLAY_STATUS_BUSY);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin  = (0xFF << KS0108_D0);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(KS0108_PORT, &GPIO_InitStructure);

GPIO_ResetBits(KS0108_PORT, KS0108_RS | KS0108_RW);
GLCD_Delay();
GLCD_EnableController(controller);
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, (commandToWrite << KS0108_D0));
commandToWrite ^= 0xFF;
GPIO_ResetBits(KS0108_PORT, (commandToWrite << KS0108_D0));
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, KS0108_EN);
GLCD_Delay();
GPIO_ResetBits(KS0108_PORT, KS0108_EN);
GLCD_Delay();
GLCD_DisableController(controller);
}

//-------------------------------------------------------------------------------------------------
// Read data from current position
//-------------------------------------------------------------------------------------------------
unsigned char GLCD_ReadData(void)
{
unsigned char tmp;
while(GLCD_ReadStatus(screen_x / 64)&DISPLAY_STATUS_BUSY);
GPIO_StructInit(&GPIO_InitStructure);  
GPIO_InitStructure.GPIO_Pin = 0xFF << KS0108_D0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(KS0108_PORT, &GPIO_InitStructure);

GPIO_SetBits(KS0108_PORT, KS0108_RS | KS0108_RW);

GLCD_EnableController(screen_x / 64);
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, KS0108_EN);
GLCD_Delay();
tmp = ((GPIO_ReadInputData(KS0108_PORT) >> KS0108_D0) & 0xFF);
GPIO_ResetBits(KS0108_PORT, KS0108_EN);
GLCD_DisableController(screen_x / 64);
screen_x++;
return tmp;
}
//-------------------------------------------------------------------------------------------------
// Write data to current position
//-------------------------------------------------------------------------------------------------
void GLCD_WriteData(unsigned char dataToWrite)
{
while(GLCD_ReadStatus(screen_x / 64)&DISPLAY_STATUS_BUSY);

GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (0xFF << KS0108_D0);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(KS0108_PORT, &GPIO_InitStructure);

GPIO_ResetBits(KS0108_PORT, KS0108_RW);
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, KS0108_RS);
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, (dataToWrite << KS0108_D0));
dataToWrite ^= 0xFF;
GPIO_ResetBits(KS0108_PORT, (dataToWrite << KS0108_D0));
GLCD_Delay();
GLCD_EnableController(screen_x / 64);
GLCD_Delay();
GPIO_SetBits(KS0108_PORT, KS0108_EN);
GLCD_Delay();
GPIO_ResetBits(KS0108_PORT, KS0108_EN);
GLCD_Delay();
GLCD_DisableController(screen_x / 64);
screen_x++;
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
void GLCD_InitializePorts(void)
{
vu32 i;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin   =  GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed =  GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode  =  GPIO_Mode_Out_PP;

GPIO_Init(KS0108_PORT, &GPIO_InitStructure);
GPIO_Write(KS0108_PORT, KS0108_CS1 | KS0108_CS2 | KS0108_CS3 | KS0108_RS | KS0108_RW | (0xFF << KS0108_D0));
}
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
unsigned char GLCD_ReadByteFromROMMemory(char * ptr)
{
  return *(ptr);
}

And the my program is this:

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "KS0108.h"
#include "graphic.h"

/* Private functions ---------------------------------------------------------*/





/*******************************************************************************
* Function Name  : main
* Description    : Main Programme
* Input          : None
* Output         : None
* Return         : None
* Attention      : None
*******************************************************************************/


int main(void)
{
    GLCD_Initialize();
    GLCD_ClearScreen();

    GLCD_GoTo(0,0);
    GLCD_WriteString("+-------------------+");
    GLCD_GoTo(0,1);
    GLCD_WriteString("|     Universal     |");
    GLCD_GoTo(0,2);
    GLCD_WriteString("|   KS0108 library  |");
    GLCD_GoTo(0,3);
    GLCD_WriteString("|                   |");
    GLCD_GoTo(0,4);
    GLCD_WriteString("|  en.radzio.dxp.pl |");
    GLCD_GoTo(0,5);
    GLCD_WriteString("|  STM32 Cortex-M3  |");
    GLCD_GoTo(0,6);
    GLCD_WriteString("|  microcontrollers |");
    GLCD_GoTo(0,7);
    GLCD_WriteString("+-------------------+");

    while(1)//Loop for ever.
    {

    }
}

Alright, so far so good! I compiled the program and downloaded it to the MCU correctly and easily! ok, let's to turn on the circuit. all things I can see is just this:

figure3

Why? also I have checked out the MCU's pins and I saw this:

figure4

more zoom:

figure5

Why the GLCD doesn't work?

\$\endgroup\$
2
\$\begingroup\$

Maybe because the D/I pin is disconnected...? That pin is very much needed to make the LCD work - it's what selects whether you are sending Data, or Instructions to the LCD.

If you don't tell it what kind of bytes you're throwing at it are, how can it hope to work out what to do with them?

In your library it is known as the RS pin - Register Select. Some also refer to it as the C/D pin - Command / Data.

\$\endgroup\$
  • \$\begingroup\$ Thanks Majenko but as I said "I couldn't find anything about it in the KS0108-STM32.c file" \$\endgroup\$ – Roh Dec 11 '14 at 12:17
  • \$\begingroup\$ Edited my answer to tell you where in your library it is referenced, and by what name. \$\endgroup\$ – Majenko Dec 11 '14 at 12:19
  • \$\begingroup\$ Are you sure? let to check it. I thought it's for RES pin. \$\endgroup\$ – Roh Dec 11 '14 at 12:19
  • 1
    \$\begingroup\$ Yes, I am sure. Take a look at GLCD_WriteData and GLCD_WriteCommand. You'll see one small difference between the two - in one RS is set, in the other it is cleared. Now, you wouldn't keep resetting the screen all the time like that now would you? \$\endgroup\$ – Majenko Dec 11 '14 at 12:21
  • \$\begingroup\$ Ops! What happened to me!? :) you was right! I checked it and now it's working but not correctly! look: upload.tehran98.com/upme/uploads/f48cfaabe0c95efc1.jpg \$\endgroup\$ – Roh Dec 11 '14 at 12:29

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.