大理水控初始版本
diff --git a/lcd/glcd_spi.c b/lcd/glcd_spi.c
new file mode 100644
index 0000000..1e65708
--- /dev/null
+++ b/lcd/glcd_spi.c
@@ -0,0 +1,115 @@
+/**
+ * \file STM32F10x.c
+ * \brief Device implementation for ST STM32F10x ARM Cortex-M3 MCUs
+ * Requires the use of ST's Standard Peripheral Library
+ * \author Andy Gock
+ * \todo Code is untested!
+ */
+
+/*
+ Copyright (c) 2012, Andy Gock
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of Andy Gock nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Includes from CMSIS and Peripheral Library */
+#include "stm32f10x.h"
+#include "../sys_hw/timer.h"
+#include "glcd_spi.h"
+#include "ST7565R.h"
+
+void glcd_HW_init(void)
+{
+ /* Initialisation of GPIO and SPI */
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Set up GPIO pins */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
+
+ /* DC pin */
+ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_DC_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(CONTROLLER_SPI_DC_PORT, &GPIO_InitStructure);
+
+ /* RESET pin */
+ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_RST_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(CONTROLLER_SPI_RST_PORT, &GPIO_InitStructure);
+
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
+ GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ GLCD_BKL_ON();
+
+ /* Make sure chip is de-selected by default */
+ GLCD_DESELECT();
+
+ /* Initialise SPI */
+ spi_init();
+
+ /* Send reset pulse to LCD */
+ glcd_reset();
+ delay_ms(1);
+
+ glcd_ST7565R_init();
+
+ /* Set all dots black and hold for 0.5s, then clear it, we do this so we can visually check init sequence is working */
+// glcd_all_on();
+// delay_ms(50);
+ glcd_normal();
+
+ glcd_set_start_line(0);
+ glcd_clear_now();
+}
+
+void glcd_spi_write(uint8_t c)
+{
+ GLCD_SELECT();
+ spi_transive(c, 1000);
+ GLCD_DESELECT();
+}
+
+void glcd_reset(void)
+{
+ GLCD_SELECT();
+ GLCD_RESET_LOW();
+ delay_ms(2);
+ GLCD_RESET_HIGH();
+ GLCD_DESELECT();
+}
+/*void GLCD_BKL_ON(void)
+{
+ GPIO_SetBits(GPIOA, GPIO_Pin_15);
+}
+void GLCD_BKL_OFF(void)
+{
+ GPIO_ResetBits(GPIOA, GPIO_Pin_15);
+}*/