//------------------------------------------------------------------------------------------------- // 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 ); // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // GPIO_Init(KS0108_PORT, &GPIO_InitStructure); GPIO_Init(KS0108_PORT,GPIO_PIN_ALL,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_WriteLow(GPIOC, KS0108_RW); GLCD_Delay(); GPIO_WriteHigh(GPIOC, KS0108_RS); GLCD_Delay(); GPIO_Write(KS0108_PORT, (GPIO_Pin_TypeDef)(dataToWrite )); GLCD_Delay(); GLCD_EnableController(screen_x / 64); GLCD_Delay(); GPIO_WriteHigh(GPIOC, KS0108_EN); GLCD_Delay(); GPIO_WriteLow(GPIOC, KS0108_EN); GLCD_Delay(); GLCD_DisableController(screen_x / 64); screen_x++; }
//------------------------------------------------------------------------------------------------- // Write command to specified controller //------------------------------------------------------------------------------------------------- void GLCD_WriteCommand(unsigned char commandToWrite, unsigned char controller) { while(GLCD_ReadStatus(controller)&DISPLAY_STATUS_BUSY); KS0108_DATA_DIR = 0xFF; KS0108_CTRL_PORT &= ~(KS0108_RW | KS0108_RS); GLCD_EnableController(controller); KS0108_DATA_PORT = commandToWrite; KS0108_CTRL_PORT |= KS0108_EN; GLCD_Delay(); KS0108_CTRL_PORT &= ~KS0108_EN; GLCD_DisableController(controller); }
//------------------------------------------------------------------------------------------------- // Read Status from specified controller (0-2) //------------------------------------------------------------------------------------------------- unsigned char GLCD_ReadStatus(unsigned char controller) { unsigned char status; KS0108_DATA_DIR = 0x00; KS0108_CTRL_PORT |= KS0108_RW; KS0108_CTRL_PORT &= ~KS0108_RS; GLCD_EnableController(controller); KS0108_CTRL_PORT |= KS0108_EN; GLCD_Delay(); status = KS0108_DATA_PIN; KS0108_CTRL_PORT &= ~KS0108_EN; GLCD_DisableController(controller); return status; }
//------------------------------------------------------------------------------------------------- // Write data to current position //------------------------------------------------------------------------------------------------- void GLCD_WriteData(unsigned char dataToWrite) { while(GLCD_ReadStatus(screen_x / 64)&DISPLAY_STATUS_BUSY); KS0108_DATA_DIR = 0xFF; KS0108_CTRL_PORT &= ~KS0108_RW; KS0108_CTRL_PORT |= KS0108_RS; KS0108_DATA_PORT = dataToWrite; GLCD_EnableController(screen_x / 64); KS0108_CTRL_PORT |= KS0108_EN; GLCD_Delay(); KS0108_CTRL_PORT &= ~KS0108_EN; GLCD_DisableController(screen_x / 64); screen_x++; }
//------------------------------------- void GLCD_WriteData(unsigned char dataToWrite) { unsigned int byte; DELAY() PIO_Clear(&GLcdpins[2]); PIO_Set(&GLcdpins[0]); byte = dataToWrite; DATAPORT(byte); GLCD_EnableController(screen_x / 64); PIO_Set(&GLcdpins[1]); DELAY(); PIO_Clear(&GLcdpins[1]); GLCD_DisableController(screen_x / 64); screen_x++; }
//------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------- void GLCD_WriteCommand(unsigned char commandToWrite, unsigned char controller) { unsigned int command; DELAY(); PIO_Clear(&GLcdpins[0]); PIO_Clear(&GLcdpins[2]); GLCD_EnableController(controller); command=commandToWrite; DATAPORT(command); PIO_Set(&GLcdpins[1]); DELAY(); PIO_Clear(&GLcdpins[1]); GLCD_DisableController(controller); }
//------------------------------------------------------------------------------------------------- // Read data from current position //------------------------------------------------------------------------------------------------- unsigned char GLCD_ReadData(void) { unsigned char data; while(GLCD_ReadStatus(screen_x / 64)&DISPLAY_STATUS_BUSY); KS0108_DATA_DIR = 0x00; KS0108_CTRL_PORT |= (KS0108_RW | KS0108_RS); GLCD_EnableController(screen_x / 64); //GLCD_Delay(); KS0108_CTRL_PORT |= KS0108_EN; GLCD_Delay(); data = KS0108_DATA_PIN; KS0108_CTRL_PORT &= ~KS0108_EN; GLCD_DisableController(screen_x / 64); screen_x++; return data; }
//------------------------------------------------------------------------------------------------- // 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 ; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Init(KS0108_PORT, &GPIO_InitStructure); GPIO_Init(KS0108_PORT,GPIO_PIN_ALL,GPIO_MODE_IN_PU_NO_IT); GPIO_WriteHigh(GPIOC, KS0108_RW); GPIO_WriteLow(GPIOC, KS0108_RS); GLCD_EnableController(controller); GLCD_Delay(); GPIO_WriteHigh(GPIOC, KS0108_EN); GLCD_Delay(); status = ((GPIO_ReadInputData(KS0108_PORT) ) & 0xFF); GPIO_WriteLow(GPIOC, 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 ); // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // GPIO_Init(KS0108_PORT, &GPIO_InitStructure); GPIO_Init(KS0108_PORT,GPIO_PIN_ALL,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_WriteLow(GPIOC, (GPIO_Pin_TypeDef)(KS0108_RS | KS0108_RW)); GLCD_Delay(); GLCD_EnableController(controller); GLCD_Delay(); GPIO_Write(KS0108_PORT, (GPIO_Pin_TypeDef)(commandToWrite )); GLCD_Delay(); GPIO_WriteHigh(GPIOC, KS0108_EN); GLCD_Delay(); GPIO_WriteLow(GPIOC, KS0108_EN); GLCD_Delay(); GLCD_DisableController(controller); }