void LCD_write_data(unsigned char Recdata) //写数据 { uint16_t PORT_DATA, tmpCmd = 0; Delay_1ms(2); //LCD1602_RS=1; //RS=1 GPIO_SetBits(LCD1602_RS_PORT, LCD1602_RS_PIN); Delay_1ms(2); PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT); PORT_DATA &= (~LCD1602_DB_MASK); tmpCmd = (uint16_t)(LCD_SWAP_High4Bits(Recdata) & 0xf0) << 2; PORT_DATA |= tmpCmd; GPIO_Write(LCD1602_DB_PORT, PORT_DATA); // 写高四位 //LCD_DATA&=0X0f; // 清高四位 //LCD_DATA|=Recdata&0xf0; // 写高四位 LCD_en_write(); Recdata=Recdata<<4; // 低四位移到高四位 PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT); PORT_DATA &= (~LCD1602_DB_MASK); tmpCmd = 0; tmpCmd = (uint16_t)(LCD_SWAP_High4Bits(Recdata) & 0xf0) << 2; PORT_DATA |= tmpCmd; GPIO_Write(LCD1602_DB_PORT, PORT_DATA); // 写低四位 //LCD_DATA&=0X0f; // 清高四位 //LCD_DATA|=Recdata&0xf0; // 写低四位 LCD_en_write(); }
uint8_t lcd_read(uint8_t rs) { __IO uint8_t data; if(rs) { //read data lcd_rs_high(); } else { //read busy flag lcd_rs_low(); } lcd_rw_high(); // read mode //set data pins to input GPIO_InitStructure.GPIO_Pin = DATA_PORT_Pin_0 | DATA_PORT_Pin_1 | DATA_PORT_Pin_2 | DATA_PORT_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(LCD_PORT, &GPIO_InitStructure); //read 2 nibbles lcd_e_high(); //enable lcd_e_delay(); data = (uint8_t)GPIO_ReadInputData(LCD_PORT) << 4; lcd_e_low(); //disable lcd_e_delay(); lcd_e_high(); //enable lcd_e_delay(); data |= (uint8_t)GPIO_ReadInputData(LCD_PORT) & 0x0F; lcd_e_low(); //disable return data; }
void LCD_write_command(unsigned char command) //写指令 { uint16_t PORT_DATA, tmpCmd = 0; //LCD1602_RS=0; //RS=0 GPIO_ResetBits(LCD1602_RS_PORT, LCD1602_RS_PIN); Delay_1ms(2); PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT); PORT_DATA &= (~LCD1602_DB_MASK); //GPIO_Write(LCD1602_DB_PORT, PORT_DATA); tmpCmd = ((uint16_t)(LCD_SWAP_High4Bits(command) & 0xf0)) << 2; PORT_DATA |= tmpCmd; GPIO_Write(LCD1602_DB_PORT, PORT_DATA); // 写高四位 LCD_en_write(); command=command<<4; // 低四位移到高四位 PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT); PORT_DATA &= (~LCD1602_DB_MASK); //GPIO_Write(LCD1602_DB_PORT, PORT_DATA); tmpCmd = 0; tmpCmd = ((uint16_t)(LCD_SWAP_High4Bits(command) & 0xf0)) << 2; PORT_DATA |= tmpCmd; GPIO_Write(LCD1602_DB_PORT, PORT_DATA); // 写低四位 //LCD_DATA|=command&0xf0; LCD_en_write(); }
void AER_readBus(uint16_t *aer_data){ uint8_t data = 0; uint16_t data_16 = 0; //Podria hacer un readinputdata de 16 bits de todos los pines pero guardarlo en un uint8_t, aunque los otros pines no estén configurados? data_16 = GPIO_ReadInputData(AERbus_port); data = (uint8_t)GPIO_ReadInputData(AERbus_port); *aer_data = ((uint16_t)data); }
void vIO_Refresh(void *pvParameters) { for(;;) { taskENTER_CRITICAL(); GPIO_Write(GPIOD,GPIOD_BUFFER); /*output*/ GPIO_Write(GPIOD,GPIOF_BUFFER); GPIOE_BUFFER = GPIO_ReadInputData(GPIOE); /*input*/ GPIOG_BUFFER = GPIO_ReadInputData(GPIOG); taskEXIT_CRITICAL(); vTaskDelay(10/portTICK_RATE_MS); } }
// TIMER #4 IRQ void TIM4_IRQHandler(void) { __disable_irq(); if (TIM_GetITStatus(TIM4,TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM4,TIM_IT_Update); uint16_t keys = 0; // COL#1 GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET); GPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_SET); keys = (GPIO_ReadInputData(GPIOA) << 1) & 0b111000; // COL#2 GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET); GPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_RESET); keys |= (GPIO_ReadInputData(GPIOA) >> 2) & 0b000111; if (keys != keys_last) { keys_debounce = 0; keys_ready = 0; } else { keys_debounce++; if (keys_debounce >= 2) { keys_debounce = 0; keys_ready = 1; keys_pressed = keys; } else keys_ready = 0; } keys_last = keys; }
/* //Read_BusyFlag_AddressCounter ***********************************************************/ char TC2002A_Read_BF_AC(void) { short data; // //change input-port data bus port DB7~DB0 // TC2002A_Delay(); TC2002A_E(0); //Enable=0 TC2002A_RS(0); //RS TC2002A_RS(0); //RS TC2002A_RW(1); //R/W TC2002A_RW(1); //R/W TC2002A_Delay(); TC2002A_E(1); //Enable=1 TC2002A_E(1); //Enable=1 // //read data bus port DB7~DB0 <= PB15~8 SetBusInput; TC2002A_Delay(); data = (short)GPIO_ReadInputData(GPIOB); //GetInputTC2002A_u16BUS(); TC2002A_Delay(); TC2002A_Delay(); // TC2002A_E(0); //Enable=0 TC2002A_E(0); //Enable=0 // //change output-port data bus port DB7~DB0 //data bus output port DB7~DB0 ResBusOutput; // return( (char)(data>>8) ); }
int main(void) { // Initialize delay function DelayInit(); // Initialize ADC, PWM, and GPIO ADC_Setup(); PWM_Setup(); GPIO_Setup(); while (1) { // Read input switch (active low) effect = GPIO_ReadInputData(GPIOB); // Invert and mask input switch bits effect = ~effect & 0x7000; // If any audio effect is active, then turn on LED if (effect) { // Turn on LED (active low) GPIO_ResetBits(GPIOC, GPIO_Pin_13); } else { GPIO_SetBits(GPIOC, GPIO_Pin_13); } DelayMs(50); } }
void exti0_isr ( void ) { uint16_t i; /* Toggle LED1 */ //gpio_toggle_blinkenlight(); if ( EXTI_GetITStatus ( EXTI_Line0 ) != RESET ) { /* Toggle LED1 */ gpio_toggle_blinkenlight(); // append to queue if ( server_itemcount < SERVER_QUEUE_MAX ) { i = server_itemcount++; server_queue [ i ] = (uint8_t) GPIO_ReadInputData ( GPIOE ); //if ( server_queue [ i ] > 0 ) { //gpio_toggle_blinkenlight(); //} } // queue full? /* Clear the EXTI line 0 pending bit */ EXTI_ClearITPendingBit ( EXTI_Line0 ); } // exti0 status __asm__("nop"); } // exti0 isr
/** * @brief Example firmware main entry point. * @par Parameters: * None * @retval * None */ void main(void) { u8 Leds; /* Contains which LEDs to operate */ /* Initialize I/Os in Output Mode */ GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST); /* Toggles LEDs */ while (1) { /* Check button status */ if ((GPIO_ReadInputData(BUTTON_PORT) & BUTTON_PIN) == (u8)0x00) { /* Button is pressed */ Leds = (LED2_PIN | LED3_PIN); } else { /* Button is released */ Leds = (LED1_PIN | LED4_PIN); } /* LEDs ON */ GPIO_WriteHigh(LEDS_PORT, Leds); Delay((u16)60000); Delay((u16)60000); /* LEDs OFF */ GPIO_WriteLow(LEDS_PORT, Leds); Delay((u16)60000); Delay((u16)60000); } }
/******************************************************************************* * Function Name : gpio_read_port * Description : Read the input value of a specified GPIO port * Input : - Gpio: Select the GPIO port to be read * Output : None * Return : None *******************************************************************************/ u16 gpio_read_port(const _Gpio_Descriptor *Gpio) { if (!Gpio) return(0); #ifdef _GPIO_I2CIO_SUPPORT if (gpio_is_i2c(Gpio)) return(i2cio_read_register(Gpio->Port, I2CIO_REG_INPUT)); #endif return(GPIO_ReadInputData((GPIO_TypeDef *)Gpio->Port)); }
/******************************************************************************* * 函数名 : Key_Down_Scan * 描述 : 按键按下扫描 * 输入 : 无 * 输出 : 0:没有按键按下,1:按键按下 * 返回 : 无 * 说明 : KEY(1~2)的IO口分别是:PC10,PC11 *******************************************************************************/ u8 Key_Down_Scan(void) { u16 downflag=0; u8 value=0; downflag=GPIO_ReadInputData(KEY_PORT); if((downflag & 0x0c00) != 0x0c00) //检测是否有按键按下 { Delay_nMs(10); //延时消抖 downflag = GPIO_ReadInputData(KEY_PORT) & 0x0c00; if(downflag != 0x0c00 ) //检测是否有按键按下 { if((downflag & 0x0400) == 0) value |= 0x01; if((downflag & 0x0800) == 0) value |= 0x02; } } return value; }
void userTask(void *param) { //Endless loop while(1) { //WKUP button pressed? if(GPIO_ReadInputData(WKUP_GPIO) & WKUP_PIN) { //FTP client test routine ftpClientTest(); //Wait for the WKUP button to be released while(GPIO_ReadInputData(WKUP_GPIO) & WKUP_PIN); } //Loop delay osDelayTask(100); } }
/** * @brief Returns the level of a specified GPIO. * @param xGpio Specifies the GPIO to be read. * This parameter can be one of following parameters: * @arg M2S_GPIO_0: SPIRIT GPIO_0 * @arg M2S_GPIO_1: SPIRIT GPIO_1 * @arg M2S_GPIO_2: SPIRIT GPIO_2 * @arg M2S_GPIO_3: SPIRIT GPIO_3 * @retval FlagStatus Level of the GPIO. This parameter can be: * SET or RESET. */ FlagStatus SdkEvalSpiritGpioGetLevel(M2SGpioPin xGpio) { /* Gets the GPIO level */ uint16_t nDataPort = GPIO_ReadInputData(vectpxM2SGpioPort[xGpio]); if(nDataPort & s_vectnM2SGpioPin[xGpio]) return SET; else return RESET; }
static void rt_thread_entry1(void* parameter) { int temp; while (1) { key = GPIO_ReadInputData(KEY_PORT); if (key & KEY_PIN) { temp = key; rt_thread_delay(RT_TICK_PER_SECOND / 50); key = GPIO_ReadInputData(KEY_PORT); if (key == temp) rt_sem_release(&sem); } rt_thread_delay(RT_TICK_PER_SECOND/10); } }
void WaitBusy(void) //�ȴ�12864��æ״̬�����ĺ����� { IOInitIn(); //���������Ŷ���Ϊ�������룻 GPIO_ResetBits(DisIOB,RS); //RS = 0. GPIO_SetBits(DisIOB,RW); //RW = 1. GPIO_SetBits(DisIOB,EN); //EN = 1. while(GPIO_ReadInputData(DisIOA) & 0x0080); //ֻҪλ7��ֵ��λ7��æ��־λ�� GPIO_ResetBits(DisIOB,EN); //EN = 0; IOInitOut(); //���������Ŷ���Ϊ����� }
bool usbCableIsInserted(void) { bool result = false; #ifdef USB_CABLE_DETECTION result = (GPIO_ReadInputData(USB_DETECT_GPIO_PORT) & USB_DETECT_PIN) != 0; #endif return result; }
/*******读忙态函数********************************************/ void check_busy(){ DDRC_IN(); RS_CLR; RW_SET; EN_SET; //busy=GPIO_ReadInputData(GPIOC) & 0x0080; while(GPIO_ReadInputData(GPIOC)&0x0080); EN_CLR; DDRC_OUT(); }
/** * @brief This function returns the IRQout state * @param None * @retval Pin set : 1 * @retval Pin reset : 0 */ int8_t drv95HF_GetIRQOutState ( void ) { if ((GPIO_ReadInputData(EXTI_GPIO_PORT) & 0x0008) != 0x00) { return 0x01; } else { return 0x00; } }
/** * @brief Detect if SD card is correctly plugged in the memory slot. * @param None * @retval Return if SD is detected or not */ uint8_t SD_Detect(void) { __IO uint8_t status = SD_PRESENT; /*!< Check GPIO to detect SD */ if (GPIO_ReadInputData(SD_DETECT_GPIO_PORT) & SD_DETECT_PIN) { status = SD_NOT_PRESENT; } return status; }
u8 INPUT_Read(u8 cs_num) { u16 tmp = 0; u8 input = 0xFF; assert_param(IS_INPUT_CS(cs_num)); PDout(cs_num) = 0; //相应片选,低有效 tmp = GPIO_ReadInputData(GPIOE); PDout(cs_num) = 1; //相应片选,低有效 input = tmp >> 8; return input; }
Dio_PortLevelType Dio_ReadPort(Dio_PortType portId) { Dio_PortLevelType level = 0; VALIDATE_RV( DioGlobal.InitRun, DIO_READPORT_ID, DIO_E_UNINIT, (Dio_PortLevelType)0 ); /** @req SWS_Dio_00074 */ VALIDATE_RV( IS_VALID_PORT(portId), DIO_READPORT_ID, DIO_E_PARAM_INVALID_PORT_ID, (Dio_PortLevelType)0 ); level = GPIO_ReadInputData(GPIO_ports[portId]); return level; }
/* 1.没有按键的时候, ReadData = PINB^0xff=0xff^0xff=0x00 Trg = ReadData & (ReadData ^ Cont)=0x00&(0x00^0x00)=0x00 Cont = ReadData=0x00 2.第一次PB0按下的情况 ReadData = PINB^0xff=0xfe^0xff=0x01 Trg = ReadData & (ReadData ^ Cont)=0x01&(0x01^0x00)=0x01 Cont = ReadData=0x01 3. PB0按着不松(长按键)的情况 ReadData = PINB^0xff=0xfe^0xff=0x01 Trg = ReadData & (ReadData ^ Cont)=0x01&(0x01^0x01)=0x00 Cont = ReadData=0x01 4.按键松开的情况 ReadData = PINB^0xff=0xff^0xff=0x00 Trg = ReadData & (ReadData ^ Cont)=0x00&(0x00^0x01)=0x00 Cont = ReadData=0x00 // */ BUTTON_STATUS_t UB_Button_read(BUTTON_NAME_t btn_name) { u16 value; static u16 Trg,Cont,cnt_last; static u16 key_status; static u8 cnt_puls; //value = GPIO_ReadInputDataBit(BUTTON[btn_name].BUTTON_PORT,BUTTON[btn_name].BUTTON_PIN); cnt_last = Cont; value = (GPIO_ReadInputData(BUTTON[btn_name].BUTTON_PORT)&BUTTON[btn_name].BUTTON_MASK) ^BUTTON[btn_name].BUTTON_MASK; Trg = value & (value ^ Cont); Cont = value; if(Cont ==cnt_last ) cnt_puls++; else cnt_puls = 0; if (cnt_puls >25 && Cont!= 0 &&Trg == 0 ) { cnt_puls = 0; key_status = Cont & BUTTON[btn_name].BUTTON_MASK; switch(key_status) { // case BTN_RIGHT: return BTN_RIGHT_CON;//break; // case BTN_LEFT: return BTN_LEFT_CON;//break; // default: return BTN_NO_KEY;//break; case BTN_RIGHT: BTN_ENQueue(qBTNLink,BTN_RIGHT);break; case BTN_LEFT: BTN_ENQueue(qBTNLink,BTN_LEFT);break; default: break; } return BTN_NO_KEY; } key_status = Trg & BUTTON[btn_name].BUTTON_MASK; if (key_status) { switch(key_status) { case BTN_RIGHT: BTN_ENQueue(qBTNLink,BTN_RIGHT);break; case BTN_LEFT: BTN_ENQueue(qBTNLink,BTN_LEFT);break; case BTN_EN: BTN_ENQueue(qBTNLink,BTN_EN);break; case BTN_BACK: BTN_ENQueue(qBTNLink,BTN_BACK);break; default: break; } } return BTN_NO_KEY; }
/****读数据函数*************************************************/ unsigned char u8_Lcd12864ReadByte_f( void ) { unsigned char byReturnValue ; check_busy(); DDRC_IN(); RS_SET; RW_SET; EN_CLR; // Delay_nus(10); EN_SET; byReturnValue=(unsigned char)(GPIO_ReadInputData(GPIOC)&0x00ff); EN_CLR; DDRC_OUT(); return byReturnValue ; }
void w_4bit_INIT_LCD1602(unsigned char ucCMD) { uint16_t PORT_DATA, tmpCmd = 0; GPIO_ResetBits(LCD1602_RS_PORT, LCD1602_RS_PIN); //RS_L; //写入的是命令字 GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN); //RW_W; //置为写状态 PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT); PORT_DATA &= (~LCD1602_DB_MASK); tmpCmd = (uint16_t)(LCD_SWAP_High4Bits(ucCMD) & 0xf0) << 2; PORT_DATA |= tmpCmd; GPIO_Write(LCD1602_DB_PORT, PORT_DATA); // 写高四位 //P1 = (P1 & 0x0F) | (ucCMD & 0xF0); //注意不要改变P2低四位的状态 LCD_en_write(); //En_Toggle(); //产生使能脉冲,使之在下降沿开始执行指令 }
/** * Detect if a SD card is physically present in the memory slot. */ bool sdcard_isInserted(void) { bool result = true; #ifdef SDCARD_DETECT_PIN result = (GPIO_ReadInputData(SDCARD_DETECT_GPIO_PORT) & SDCARD_DETECT_PIN) != 0; #ifdef SDCARD_DETECT_INVERTED result = !result; #endif #endif return result; }
//读状态 void ReadStatusLCD(void) { unsigned char lcd_status; LCD_RS(0); LCD_RW(1); LCD_Data_In(); do { LCD_EN(1); Delay_us(1); lcd_status=GPIO_ReadInputData( LCD12864_GPIO); LCD_EN(0); } while (lcd_status&Busy); //检测忙信号 LCD_Data_Out(); }
/*void TIM2_IRQHandle(void) { }*/ void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); if (LogArrayIndex < LOGGING_ARRAY_SIZE) { aLoggedData[LogArrayIndex] = LogA_PortBits_Compactor(GPIO_ReadInputData(GPIOB), PORTBITS_DIGIN); LogArrayIndex++; } /* LED1 toggling with frequency = 73.24 Hz */ /*STM_EVAL_LEDToggle(LED1); capture = TIM_GetCapture1(TIM2); TIM_SetCompare1(TIM2, capture + CCR1_Val);*/ } /*else if (TIM_GetITStatus(TIM3, TIM_IT_CC2) != RESET) { TIM_ClearITPendingBit(TIM3, TIM_IT_CC2); // LED2 toggling with frequency = 109.8 Hz STM_EVAL_LEDToggle(LED2); capture = TIM_GetCapture2(TIM3); TIM_SetCompare2(TIM3, capture + CCR2_Val); } else if (TIM_GetITStatus(TIM3, TIM_IT_CC3) != RESET) { TIM_ClearITPendingBit(TIM3, TIM_IT_CC3); // LED3 toggling with frequency = 219.7 Hz STM_EVAL_LEDToggle(LED3); capture = TIM_GetCapture3(TIM3); TIM_SetCompare3(TIM3, capture + CCR3_Val); } else { TIM_ClearITPendingBit(TIM3, TIM_IT_CC4); // LED4 toggling with frequency = 439.4 Hz STM_EVAL_LEDToggle(LED4); capture = TIM_GetCapture4(TIM3); TIM_SetCompare4(TIM3, capture + CCR4_Val); }*/ }
int main(void){ GPIO_InitTypeDef LEDInitStruct; GPIO_InitTypeDef BtnStruct; //(1) enable peripher clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); //(2) configure pins GPIO_StructInit(&LEDInitStruct); LEDInitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8; LEDInitStruct.GPIO_Mode = GPIO_Mode_Out_PP; LEDInitStruct.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &LEDInitStruct); GPIO_StructInit(&BtnStruct); BtnStruct.GPIO_Pin = GPIO_Pin_0; BtnStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; BtnStruct.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOA, &BtnStruct); /*(3) Conigure sys timer*/ if(SysTick_Config(SystemCoreClock / 1000)) while(1); while(1) { //(4) static int ledval = 0; static int btnVal = 0; /*(4) toggle LED*/ GPIO_WriteBit(GPIOC, GPIO_Pin_9, (ledval) ? Bit_SET: Bit_RESET); ledval = 1 - ledval; btnVal = GPIO_ReadInputData(GPIOA) & GPIO_Pin_0; GPIO_WriteBit(GPIOC, GPIO_Pin_8, btnVal); Delay(250); } return 0; }
//------------------------------------------------------------------------------------------------- // 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; }