Tengo un ts12864a-2v2 LCD y yo cree que su controlador es KS0108B . He descargado esta biblioteca para usarla en mi LCD y también mi MCU es STM32F103RET6. El esquema que he usado para conectar LCD a MCU es este:
YlospinesdelaMCUestánconectadosalapantallaLCDdeestamanera:
MCULCDPB0-->DB0PB1-->DB1PB2-->DB2PB3-->DB3PB4-->DB4PB5-->DB5PB6-->DB6PB7-->DB7PB8-->RESPB9-->R/WPB10-->EPB11-->CSAPB12-->CSB
tengaencuentaqueelpinD/IesNC(noconectado).¿Esnecesario?NopudeencontrarnadaalrespectoenelarchivoKS0108-STM32.c
.
Yelcircuitoeseste:
El KS0108-STM32.c es esto:
#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);
}
Y el mi programa es este:
/* 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.
{
}
}
Muy bien, hasta ahora todo bien! ¡Compilé el programa y lo descargué en MCU de manera correcta y fácil! Ok, vamos a encender el circuito. Todas las cosas que puedo ver son solo esto:
¿Porqué?TambiénherevisadolospinesdelaMCUyviesto:
más zoom:
¿Por qué el GLCD no funciona?