static void LCD_PortInit(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); //开启引脚时钟G RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //开启引脚时钟G //配置读写控制为推挽输出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = LCD_WR_PIN|LCD_RD_PIN|LCD_CE_PIN|LCD_CD_PIN|LCD_RST_PIN|LCD_FS_PIN|LCD_LED_PIN/ LCD_DATA1_PIN|LCD_DATA2_PIN|LCD_DATA3_PIN|LCD_DATA4_PIN|LCD_DATA5_PIN|LCD_DATA6_PIN|LCD_DATA7_PIN|LCD_DATA8_PIN; //LCD_WR GPIO_Init(LCD_WR_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LCD_AD_CTRL_PIN ; GPIO_Init(LCD_AD_CTRL_PORT, &GPIO_InitStructure); GPIO_RESET(RST); GPIO_SET(CE); GPIO_SET(WR); GPIO_SET(AD_CTRL); GPIO_SET(RD); GPIO_SET(CD); GPIO_RESET(FS); //使用8*8模式 GPIO_SET(LED); //打开背光 }
/**************************************************************************** * 名 称:void LCD_Init(void) * 功 能:初始化LCD * 入口参数:无 * 出口参数: * 说 明:无 ****************************************************************************/ void LCD_Init(void) { //LCD管脚初始化 LCD_PortInit(); GPIO_RESET(RST); SysTimeDly(2); GPIO_SET(RST); SysTimeDly(1); //使能片选 GPIO_RESET(CE); //初始化设置 send_1hex_data_and_1cmd_to_lcm(TEXT_HOME_ADDRESS, LCD_TXT_STP); //文本显示区首地址 send_2data_and_1cmd_to_lcm(LCD_BYTES_X, 0x00, LCD_TXT_WID); //文本显示区宽度 send_1hex_data_and_1cmd_to_lcm(GRAPHIC_HOME_ADDRESS, LCD_GRH_STP); //图形显示区首地址 send_2data_and_1cmd_to_lcm(LCD_BYTES_X, 0x00, LCD_GRH_WID); //图形显示区宽度 send_2data_and_1cmd_to_lcm(0x02,0x00,LCD_CGR_POS); //CGRAM偏置地址设置 LCD_WriteCommand(LCD_MOD_OR); //逻辑"或" //先清屏,再开显示 ClearScreen(); //开显示 LCD_WriteCommand(LCD_DIS_GON); //启用图形显示 }
static void LCD_WriteDataAuto(unsigned char nData) { CheckBusy(0x08); GPIO_RESET(CD); LCD_WRITE_DATA(nData); //向MCU写入数据,准备向LCD输出数据 GPIO_RESET(WR); LCD_SET_DATA_OUT(); LCD_Delay(NS100_DLY(2)); //延时 GPIO_SET(WR); LCD_Delay(NS100_DLY(4)); LCD_SET_DATA_IN(); }
/*---------------------------------------------------------------------------*/ void enc28j60_arch_spi_select(void) { GPIO_RESET(SPI_CS_PORT, SPI_CS_BIT); /* SPI delay */ delay(); }
/**************************************************************************** * 名 称:void fLCD_ReadData_Row(void) * 功 能:读LCD数据,LCD数据线为连续递增排列 * 入口参数:无 * 出口参数:LCD data * 说 明:无 ****************************************************************************/ static u8 fLCD_ReadData_Row(void) { u8 uTmp; //IO口配置为输入模式 GPIO_SET(AD_CTRL); uTmp = (u8)(LCD_DATA1_PORT ->IDR ); //读数据 GPIO_RESET(AD_CTRL); //IO口配置为输出模式 return uTmp; }
static void bolt_wlan_off(void) { u16 gpio_base = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; u32 gpio_conf; /* Make sure pin is owned by GPIO subsystem and not ACPI */ gpio_conf = inl(gpio_base + GPIO_OWNER(0)); gpio_conf |= GPIO_OWNER_GPIO << 29; outl(gpio_conf, gpio_base + GPIO_OWNER(0)); /* Set GPIO29 config to only be reset on RSMRST */ gpio_conf = inl(gpio_base + GPIO_RESET(0)); gpio_conf |= GPIO_RESET_RSMRST << 29; outl(gpio_conf, gpio_base + GPIO_RESET(0)); /* Set WLAN_OFF_L (GPIO29) as Output GPIO driven high */ gpio_conf = GPIO_MODE_GPIO | GPIO_DIR_OUTPUT | GPO_LEVEL_HIGH; outl(gpio_conf, gpio_base + GPIO_CONFIG0(29)); }
/*---------------------------------------------------------------------------*/ uint8_t enc28j60_arch_spi_write(uint8_t output) { int i; uint8_t input; input = 0; for(i = 0; i < 8; i++) { /* Write data on MOSI pin */ if(output & 0x80) { GPIO_SET(SPI_MOSI_PORT, SPI_MOSI_BIT); } else { GPIO_RESET(SPI_MOSI_PORT, SPI_MOSI_BIT); } output <<= 1; /* Set clock high */ GPIO_SET(SPI_CLK_PORT, SPI_CLK_BIT); /* SPI delay */ delay(); /* Read data from MISO pin */ input <<= 1; if(GPIO_GET(SPI_MISO_PORT, SPI_MISO_BIT) != 0) { input |= 0x1; } /* Set clock low */ GPIO_RESET(SPI_CLK_PORT, SPI_CLK_BIT); /* SPI delay */ delay(); } return input; }
/**************************************************************************** * 名 称: void LCD_WriteCommand(uint8 nCmd) * 功 能: 写LCD命令 * 入口参数:u8 命令 * 出口参数:无 * 说 明: 无 ****************************************************************************/ void LCD_WriteCommand(unsigned char nCmd) { CheckBusy(0x03); GPIO_SET(CD); LCD_WRITE_DATA(nCmd); //向MCU写入数据,准备向LCD输出数据 GPIO_RESET(WR); LCD_SET_DATA_OUT(); LCD_Delay(NS100_DLY(2)); //延时 GPIO_SET(WR); LCD_Delay(NS100_DLY(4)); LCD_SET_DATA_IN(); }
/*---------------------------------------------------------------------------*/ void enc28j60_arch_spi_init(void) { /* Set pins to output or input mode */ SPI_CLK_DIRP |= SPI_CLK_BIT; SPI_CS_DIRP |= SPI_CS_BIT; SPI_MOSI_DIRP |= SPI_MOSI_BIT; SPI_MISO_DIRP &= ~SPI_MISO_BIT; /* The CS pin is active low, so we set it high when we haven't selected the chip. */ GPIO_SET(SPI_CS_PORT, SPI_CS_BIT); /* The CLK is active low, we set it high when we aren't using it. */ GPIO_RESET(SPI_CLK_PORT, SPI_CLK_BIT); }
/**************************************************************************** * 名 称: bool CheckBusy(unsigned char nMask) * 功 能: LCD忙检测 * 入口参数: u8: 判忙类型 * 出口参数: bool: false--忙 ; true--不忙 * 说 明: 无 ****************************************************************************/ static bool CheckBusy(unsigned char nMask) { unsigned char nState; unsigned short int i = 0; GPIO_SET(CD); GPIO_RESET(RD); LCD_Delay(NS100_DLY(1)); //延时 do{ nState = fLCD_ReadData_Row(); if(++i > 10000) { GPIO_SET(RD); return false; } }while((nState & nMask) != nMask); GPIO_SET(RD); return true; }
static inline void output_disable(void) { /* GPF0 (disable OR'ing FETs) = 0 */ STM32_GPIO_BSRR(GPIO_F) = GPIO_RESET(0); }
static inline void discharge_disable(void) { STM32_GPIO_BSRR(GPIO_F) = GPIO_RESET(1); adc_disable_watchdog(); }
#include "registers.h" #include "system.h" #include "task.h" #include "timer.h" #include "util.h" #include "usb_pd.h" /* ------------------------- Power supply control ------------------------ */ /* GPIO level setting helpers through BSRR register */ #define GPIO_SET(n) (1 << (n)) #define GPIO_RESET(n) (1 << ((n) + 16)) /* Output voltage selection */ enum volt { VO_5V = GPIO_RESET(13) | GPIO_RESET(14), VO_12V = GPIO_SET(13) | GPIO_RESET(14), VO_13V = GPIO_RESET(13) | GPIO_SET(14), VO_20V = GPIO_SET(13) | GPIO_SET(14), }; static inline void set_output_voltage(enum volt v) { /* set voltage_select on PA13/PA14 */ STM32_GPIO_BSRR(GPIO_A) = v; } static inline void output_enable(void) { /* GPF0 (enable OR'ing FETs) = 1 */ STM32_GPIO_BSRR(GPIO_F) = GPIO_SET(0);
/**************************************************************************** * 名 称:void fLCD_LEDOFF(void) * 功 能:关闭LCD背光 * 入口参数: * 出口参数: * 说 明:无 ****************************************************************************/ void fLCD_LEDOFF(void) { GPIO_RESET(LED); }