Example #1
0
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();
}
Example #2
0
void DisplayDigit( uint8_t digit, uint8_t value, uint8_t dp  )  //digit: melyik kijelzõre írjuk az adatot, értéke:0...5)
{                                                              //value:0,1,...,F kijelzendõ szám; dp:0->nincs tizedespont 1->van
	uint16_t portval;

	uint16_t select=digit<<13;           //shiftelés  7sel0,..,7sel2: PB13,..PB15; a 16 bites port felsõ 3 bitjét állítjuk, ezért select értéke 13-mal shiftelve van fölfele select: abcxxxxxxxxxxxxx a,b,c az értékes bit
	uint16_t data=SegmentTable[value];   //kiválasztjuk a tömbbõl a kiküldendõ adatot, a kijelzendõ szám(value) alapján
		     data<<=8;                           //shiftelés 0xab00 DB0..DB7->PE8..Pe15: E port felsõ 8 bitje, ezért shiftejük 8-cal az értéket

	 GPIO_ResetBits(GPIOB,GPIO_Pin_8);       //7seg_clk lefutó él (D flipflophoz)

	 portval=GPIO_ReadOutputData(GPIOB);     //kiolvassuk a B port jelenlegi értékét (select itt kerül a port lábaira
	 portval&=0x1FFF;                        //port többi bitjét ne piszkáljuk, ezért a felsõ 3 bitet(13,14,15) kinulázzuk, a többi értékénél marad
	 portval|=select;                        //select értékét átmentjük a port felsõ 3 bitjébe (select alsó 13 bitje 0)
	 GPIO_Write(GPIOB,portval);              //kiküldjük az adatot a B portra (7sel0,7sel1,7sel2 értéket kap, amik demuxon keresztül kiválasztanak egy db kijelzõt, amit meghajtunk)

	 portval=GPIO_ReadOutputData(GPIOE);    //hasonlóan az E portnál is
	 portval&=0x00FF;                       //alsó 8 bitet változatlanul kell visszaírni
	 portval|=data;                        //data értéke bekerül a port felsõ 8 bitjébe
	 GPIO_Write(GPIOE,portval);            //adatkiírás


	 if(dp) GPIO_SetBits(GPIOE,GPIO_Pin_15);   //ha kell tizedespont, állítjuk a megfelelõ lábat
	 else   GPIO_ResetBits(GPIOE,GPIO_Pin_15);

	 GPIO_SetBits(GPIOB,GPIO_Pin_8);              //7seg_clk felfutó él-> D-flipflop kimenetén megjelenik az adat
	 GPIO_ResetBits(GPIOE,GPIO_Pin_7);           //#7sen: engedélyezzük a demux-t és D-flipflop-ot (low active)

}
Example #3
0
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();
}
Example #4
0
//========================================
void GPIO_Configuration(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
	
	GPIO_InitStructure.GPIO_Pin = LED_CLK_PIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(LED_CLK_PORT, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = LED_LAT_PIN;
	GPIO_Init(LED_LAT_PORT, &GPIO_InitStructure);
/*	
#if DISPLAY_LED_STATIC	
	GPIO_InitStructure.GPIO_Pin = LED_OE_PIN;
	GPIO_Init(LED_OE_PORT, &GPIO_InitStructure);
#endif
*/
	if(hwConfig.ledType == SCAN_STATIC)
	{
		GPIO_InitStructure.GPIO_Pin = LED_OE_PIN;
		GPIO_Init(LED_OE_PORT, &GPIO_InitStructure);
	}
	// Config PORTA pins
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	// Config PORTB pins
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	// Config PORTB pins
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	// Config PORTB pins
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
	GPIO_Init(GPIOD, &GPIO_InitStructure);
	// Config PORTB pins
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
	GPIO_Init(GPIOE, &GPIO_InitStructure);
	// Set default value for control pins
	GPIO_Write(GPIOA,0x0000);
	GPIO_Write(GPIOB,0x0000);
	GPIO_Write(GPIOC,0x0000);
	GPIO_Write(GPIOD,0x0000);
	GPIO_Write(GPIOE,0x0000);

	// Configure USART1 Rx as input floating 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	// Configure USART1 Tx as alternate function push-pull 
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
}
Example #5
0
void iris_auto_motor_run(u8 mode)
{
    static u8 i=0;

	u16 temp = 0;

	
	switch(mode)
	{
	case 1:
    	temp = GPIO_ReadOutputData(IRIS_AUTO_PORT);
        temp &= 0xFFF0;
    	temp |= ((u16)iris_auto_table[i]);

		GPIO_Write(IRIS_AUTO_PORT, temp);

		i++;
		if(i>=4)
			i = 0;

        zoom_run_state_pre = zoom_run_state;
        zoom_run_state = 1;
		break;
	case 2:

    	temp = GPIO_ReadOutputData(IRIS_AUTO_PORT);
        temp &= 0xFFF0;
    	temp |= ((u16)iris_auto_table[i]);

		GPIO_Write(IRIS_AUTO_PORT, temp);
		//i--;
		 if(i == 0)
			i = 4-1;
		else
			i--;

        zoom_run_state_pre = zoom_run_state;
        zoom_run_state = 1;
		
		break;
	case 0:
	
        md127_keepmode();
        zoom_run_state_pre = zoom_run_state;
        zoom_run_state = 0;
      
		break;
	default:
		return;
	}

    md127_keepmode();
}
Example #6
0
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);

	}
}
Example #7
0
int main(void) {

    //    SystemCoreClockSet(MSI48M_CLOCKSRC, 0, 3, 0);

    GPIO_Init(0,LED_GREEN|LED_RED);

    GPIO_Write(LED_GREEN,LED_RED);

    for (;;) {
       ms_delay(500);
       GPIO_Write(LED_RED,LED_GREEN);
       ms_delay(500);
       GPIO_Write(LED_GREEN,LED_RED);
    }
}
/**
 * Initializes the analog input multiplexer, configuring the processor's peripherals and setting
 * the multiplexer to its default state.
 *
 * @param none
 * @retval none
 */
void InputMultiplexerInit(void) {
	GPIO_InitTypeDef GPIO_InitStructure;

	/* Enable the GPIO Clock */
	RCC_AHB1PeriphClockCmd(OCAL_CONTROL_GPIO_CLK, ENABLE);

	/* Configure the DEMUX GPIO pins */
	GPIO_InitStructure.GPIO_Pin = OCAL_CONTROL_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; /* At most the multiplexer can handle a few hundred Hz */
	GPIO_Init(OCAL_CONTROL_GPIO_PORT, &GPIO_InitStructure);
	GPIO_WriteBit(OCAL_CONTROL_GPIO_PORT, OCAL_CONTROL_PIN, OCAL_SELECT); /* TODO: This is temporary until the REV D boards arrive. Should be EXT_ANALOG_SELECT */

	/* Enable the DEMUX GPIO Clock */
	RCC_AHB1PeriphClockCmd(EXT_ANALOG_IN_GPIO_CLK, ENABLE);

	/* Configure the DEMUX GPIO pins */
	GPIO_InitStructure.GPIO_Pin = EXT_ANALOG_IN_MUX_PINS;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; /* At most the multiplexer can handle a few hundred Hz */
	GPIO_Init(EXT_ANALOG_IN_MUX_PORT, &GPIO_InitStructure);
	GPIO_Write(EXT_ANALOG_IN_MUX_PORT, (EXTERN_0 | (GPIO_ReadOutputData(EXT_ANALOG_IN_MUX_PORT ) & EXT_ANALOG_IN_BITMASK )));
}
Example #9
0
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
{
unsigned portSHORT usBit;

	vTaskSuspendAll();
	{
		if( uxLED < partstMAX_OUTPUT_LED )
		{
			usBit = partstFIRST_LED << uxLED;

			if( xValue == pdFALSE )
			{
				usBit ^= ( unsigned portSHORT ) 0xffff;
				usOutputValue &= usBit;
			}
			else
			{
				usOutputValue |= usBit;
			}

			GPIO_Write( GPIOB, usOutputValue );
		}	
	}
	xTaskResumeAll();
}
Example #10
0
/**
**===========================================================================
**
**  Abstract: main program
**
**===========================================================================
*/
int main(void)
{
  int i = 0;
  unsigned int ledState=0x1000;
  unsigned int portState;
  /**
  *  IMPORTANT NOTE!
  *  The symbol VECT_TAB_SRAM needs to be defined when building the project
  *  if code has been located to RAM and interrupts are used.
  *  Otherwise the interrupt table located in flash will be used.
  *  See also the <system_*.c> file and how the SystemInit() function updates
  *  SCB->VTOR register.
  *  E.g.  SCB->VTOR = 0x20000000;
  */

  GPIO_Config();

  GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
  /* Infinite loop */
  while (1)
  {
	if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) {
		portState=GPIO_ReadOutputData(GPIOD);
		portState&=0x0FFF;
		GPIO_Write(GPIOD, portState | ledState);
		ledState=ledState<<1;
		if (ledState>0x8000)
			ledState=0x1000;
		for(i=0; i<200000; i++) __NOP();
	}
  }
}
Example #11
0
File: lcd.c Project: maxk9/etro_new
//-------------------------------------------------------------------------------------------------
// 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++;
}
Example #12
0
//***********点使能第几路红外发射管
void  Light(u8 port_num)
{
    u8  kk,led_light=0;
    if(port_num&BIT0) led_light|=BIT7;
    if(port_num&BIT1) led_light|=BIT6;
    if(port_num&BIT2) led_light|=BIT5;
    kk =GPIO_ReadOutputData(GPIOC)&0x1f;
    GPIO_Write(GPIOC,  kk|led_light);
}
void otpravka(uint32_t kill) // ОТПРАВКА ДАННЫХ НА LCD
{
 GPIO_Write(GPIOC,kill);
	delay(0x000F);
GPIO_SetBits( GPIOC,  GPIO_Pin_9);
	delay(0x000F);
	GPIO_ResetBits( GPIOC,  GPIO_Pin_9);
	delay(0x000F);
}
Example #14
0
void static_smg_display()	//静态数码管显示
{	
	u8 i;
	for(i=0;i<16;i++)
	{
		GPIO_Write(GPIOC,(u16)(~smgduan[i]));
		delay_ms(1000);	
	}			
}
Example #15
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif

  /* System Clocks Configuration */
  RCC_Configuration();   

  /* Configure GPIO_LED pin 6, pin 7, pin 8 and pin 9 as Output push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIO_LED, &GPIO_InitStructure);

  /* Turn on Leds connected to GPIO_LED pin 6 and pin 8 */
  GPIO_Write(GPIO_LED, GPIO_Pin_6 | GPIO_Pin_8);

  /* NVIC configuration */
  NVIC_Configuration();

  /* SysTick end of count event each 1ms with input clock equal to 9MHz (HCLK/8, default) */
  SysTick_SetReload(9000);

  /* Enable SysTick interrupt */
  SysTick_ITConfig(ENABLE);

  while (1)
  {
    /* Toggle leds connected to GPIO_LED pin 6, GPIO_LED pin 7, GPIO_LED pin 8
       and GPIO_LED pin 9 pins */
    GPIO_Write(GPIO_LED, (u16)~GPIO_ReadOutputData(GPIO_LED));

    /* Insert 500 ms delay */
    Delay(500);

    /* Toggle leds connected to GPIO_LED pin 6, pin 7, pin 8 and pin 9 */
    GPIO_Write(GPIO_LED, (u16)~GPIO_ReadOutputData(GPIO_LED));

    /* Insert 300 ms delay */
    Delay(300);
  }
}
Example #16
0
void Dio_WritePort(Dio_PortType portId, Dio_PortLevelType level)
{
    VALIDATE( DioGlobal.InitRun, DIO_READCHANNELGROUP_ID, DIO_E_UNINIT );
    /** @req SWS_Dio_00074 */
    VALIDATE( IS_VALID_PORT(portId), DIO_WRITEPORT_ID, DIO_E_PARAM_INVALID_PORT_ID );

	GPIO_Write(GPIO_ports[portId], level);

	return;
}
Example #17
0
static void ssd1306_gpio_init(void)
{
#if (OLED_DEVICE_INTERFACE == INTERFACE_8BIT_80XX)
    GPIO_InitTypeDef GPIO_InitStructure;

    /* Config GPIO */
    RCC_APB2PeriphClockCmd(MINISTM32_OLED_DATA_CLOCK | \
        MINISTM32_OLED_CTRL_CLOCK | RCC_APB2Periph_AFIO, ENABLE);
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin   = \
        GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | \
        GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_Init(MINISTM32_OLED_DATA_PORT, &GPIO_InitStructure);
    GPIO_Write(MINISTM32_OLED_DATA_PORT, GPIO_InitStructure.GPIO_Pin);

    GPIO_InitStructure.GPIO_Pin   = \
        MINISTM32_OLED_CS_PIN | MINISTM32_OLED_DC_PIN | \
        MINISTM32_OLED_WR_PIN | MINISTM32_OLED_RD_PIN;
    GPIO_Init(MINISTM32_OLED_CTRL_PORT, &GPIO_InitStructure);
    GPIO_Write(MINISTM32_OLED_CTRL_PORT, GPIO_InitStructure.GPIO_Pin);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

#elif (OLED_DEVICE_INTERFACE == INTERFACE_4WIRE_SPI)
    /* Config chip slect pin */
    GPIO_InitTypeDef gpio_init;

    RCC_APB2PeriphClockCmd(OLED_CS_CLOCK, ENABLE);
    RCC_APB2PeriphClockCmd(OLED_DC_CLOCK, ENABLE);
    gpio_init.GPIO_Speed        = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode         = GPIO_Mode_Out_PP;
    gpio_init.GPIO_Pin          = OLED_CS_PIN;
    GPIO_Init(OLED_CS_PORT, &gpio_init);
    GPIO_SetBits(OLED_CS_PORT, OLED_CS_PIN);
    gpio_init.GPIO_Pin          = OLED_DC_PIN;
    GPIO_Init(OLED_DC_PORT, &gpio_init);
    GPIO_SetBits(OLED_DC_PORT, OLED_DC_PIN);

#endif
}
Example #18
0
File: Sensor.c Project: yguo89/RTOS
// *************** Sensor_WriteGPIO *************** 
int Sensor_WriteGPIO( PORT_T *port, SENSOR_GPIO_T pin, unsigned char val )
{
	unsigned char byte = 0;

	if( 1 == val )
	{
		byte = port->gpio_pin[pin];
	}
	GPIO_Write( port->gpio_port[pin], port->gpio_pin[pin], byte );
	return SENSOR_SUCCESS;
}	 
Example #19
0
/*----------------------------------------------------------------------------*/
static void DATA(uint8_t d)
{
  uint32_t port;
  port = GPIO_ReadOutputData(GPIOA);
  port &= ~(LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7);
  port |= (d & 1) ? LCD_D4 : 0;
  port |= (d & 2) ? LCD_D5 : 0;
  port |= (d & 4) ? LCD_D6 : 0;
  port |= (d & 8) ? LCD_D7 : 0;
  GPIO_Write(GPIOA, port);
}
Example #20
0
void md127_keepmode(void)//保持上一输入状态函数
{
    u16 temp;

    temp = GPIO_ReadOutputData(IRIS_AUTO_PORT);
    temp &= 0xFFF0;
	temp |= ((u16)0X0F);

	GPIO_Write(IRIS_AUTO_PORT, temp);

}
/**
 * Initialisation for the Motor_Left package.
 * This will be called from Tasks_Init by default.
 */
void Motor_Left_Init(void)
{
	/* Task initialisation */
	Left_motor_direction_G = Off;
	Left_motor_speed_G = 0;
	Motor_Lf_Enc_Track = 0;

	GPIO_Set_Direction(LED_Pin_LfFd, GPIO_OUTPUT);
	GPIO_Write(LED_Pin_LfFd, GPIO_LOW);
	GPIO_Set_Direction(LED_Pin_LfBd, GPIO_OUTPUT);
	GPIO_Write(LED_Pin_LfBd, GPIO_LOW);
	GPIO_Set_Direction(Left_SW, GPIO_INPUT);

	Segment_Enable(displayC);
	Segment_Write(displayC, 0x0);
	Segment_Clear_Decimal(displayC);
	Segment_Enable(displayD);
	Segment_Write(displayD, 0x0);
	Segment_Clear_Decimal(displayD);
}
Example #22
0
File: Sensor.c Project: yguo89/RTOS
// *************** Sensor_WriteSPI_CS *************** 
// Chip select used by SPI to indicate bus target
int Sensor_WriteSPI_CS( PORT_T *port, unsigned char val )
{
	unsigned char byte = 0;

	if( 1 == val )
	{
		byte = port->spi_ss_pin;
	}
	GPIO_Write( port->spi_ss_port, port->spi_ss_pin, byte );
	return SENSOR_SUCCESS;
}	 
Example #23
0
int main()
{
    int pins[3]= {PIN4, PIN5, PIN6};
    int i;
    int c;
    int j;

    for (i=0; i<(sizeof(pins) / sizeof(int)); i++)
        if (setGPIO_Out(pins[i]))
            return -1;
    for(i=0; i<100; i++) {
        GPIO_Write(PIN4, (i+0)%3);
        GPIO_Write(PIN5, (i+1)%3);
        GPIO_Write(PIN6, (i+2)%3);
        //	sleep(1);
    }


    return 0;
}
Example #24
0
void init_GPIO(void){
	RCC_AHBPeriphClockCmd((RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB),ENABLE);
	GPIO_InitTypeDef GPIOA_struct,GPIOB_struct,GPIOAUSART,GPIOAADC,GPIOA_TIM3,GPIOB_TIM2;
	//GPIOA Init PA0-PA3 Input
	GPIOA_struct.GPIO_Mode=GPIO_Mode_IN;
	GPIOA_struct.GPIO_OType=GPIO_OType_PP;
	GPIOA_struct.GPIO_Pin=(GPIO_Pin_0|GPIO_Pin_1);
	GPIOA_struct.GPIO_PuPd=GPIO_PuPd_UP;
	GPIOA_struct.GPIO_Speed=GPIO_Speed_Level_2;
	GPIO_Init(GPIOA,&GPIOA_struct);
	// PA7 TIM3CH2 AF1
	GPIOA_TIM3.GPIO_Mode=GPIO_Mode_AF;
	GPIOA_TIM3.GPIO_OType=GPIO_OType_PP;
	GPIOA_TIM3.GPIO_Pin=GPIO_Pin_7;
	GPIOA_TIM3.GPIO_PuPd=GPIO_PuPd_NOPULL;
	GPIOA_TIM3.GPIO_Speed=GPIO_Speed_Level_3;
	GPIO_Init(GPIOA,&GPIOA_TIM3);
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_1);
	// PA5 ADC1IN5
	GPIOAADC.GPIO_Mode=GPIO_Mode_AN;
	GPIOAADC.GPIO_OType=GPIO_OType_PP;
	GPIOAADC.GPIO_Pin=GPIO_Pin_5;
	GPIOAADC.GPIO_PuPd=GPIO_PuPd_UP;
	GPIOAADC.GPIO_Speed=GPIO_Speed_Level_3;
	GPIO_Init(GPIOA,&GPIOAADC);
	//PA9-PA10 USART RX/TX
	GPIOAUSART.GPIO_Mode=GPIO_Mode_AF;
	GPIOAUSART.GPIO_OType=GPIO_OType_PP;
	GPIOAUSART.GPIO_Pin=(GPIO_Pin_9|GPIO_Pin_10);
	GPIOAUSART.GPIO_PuPd=GPIO_PuPd_NOPULL;
	GPIOAUSART.GPIO_Speed=GPIO_Speed_Level_3;
	GPIO_Init(GPIOA,&GPIOAUSART);
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
	GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
	//GPIOB PB0-PB7 Outputs Init
	GPIOB_struct.GPIO_Mode=GPIO_Mode_OUT;
	GPIOB_struct.GPIO_OType=GPIO_OType_PP;
	GPIOB_struct.GPIO_Pin=(GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|
			GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);
	GPIOB_struct.GPIO_PuPd=GPIO_PuPd_NOPULL;
	GPIOB_struct.GPIO_Speed=GPIO_Speed_Level_2;
	GPIO_Init(GPIOB,&GPIOB_struct);
	GPIO_Write(GPIOB,0x00);
	//GPIOB PB10-PB11 TIM2CH3&TIM2CH4 PWM Outputs AF2 for both
	GPIOB_TIM2.GPIO_Mode=GPIO_Mode_AF;
	GPIOB_TIM2.GPIO_OType=GPIO_OType_PP;
	GPIOB_TIM2.GPIO_Pin=(GPIO_Pin_10|GPIO_Pin_11);
	GPIOB_TIM2.GPIO_PuPd=GPIO_PuPd_NOPULL;
	GPIOB_TIM2.GPIO_Speed=GPIO_Speed_Level_2;
	GPIO_Init(GPIOB,&GPIOB_TIM2);
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_2);
	GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_2);
}
Example #25
0
/***************************************************************************//**
 * @brief  Write 4-bits to LCD controller
 ******************************************************************************/
void Lcd_Write_4bits(uc8 byte)
{
    uint16_t u16Temp=0;
    GPIO_WriteBit(GPIOA, RW, Bit_RESET);
    GPIO_WriteBit(GPIOA, EN, Bit_SET);
    u16Temp = GPIO_ReadOutputData(GPIOB)&0xFFF0;
    u16Temp |=  SWAP_DATA[byte&0x0F];
    GPIO_Write(GPIOB, u16Temp);
    Delay(10000);
    GPIO_WriteBit(GPIOA, EN, Bit_RESET);
    Delay(10000);
}
Example #26
0
/**
  * @brief  Main program.
  * @param  None
  * @retval : None
  */
int main(void)
{
  /* System Clocks Configuration */
  RCC_Configuration();

  /* Configure GPIO_LED pin 6, pin 7, pin 8 and pin 9 as Output push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIO_LED, &GPIO_InitStructure);

  /* Turn on Leds connected to GPIO_LED pin 6 and pin 8 */
  GPIO_Write(GPIO_LED, GPIO_Pin_6 | GPIO_Pin_8);

  /* NVIC configuration */
  NVIC_Configuration();

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemFrequency / 1000))
  { 
    /* Capture error */ 
    while (1);
  }
  
  while (1)
  {
    /* Toggle leds connected to GPIO_LED pin 6, GPIO_LED pin 7, GPIO_LED pin 8
       and GPIO_LED pin 9 pins */
    GPIO_Write(GPIO_LED, (uint16_t)~GPIO_ReadOutputData(GPIO_LED));

    /* Insert 500 ms delay */
    Delay(500);

    /* Toggle leds connected to GPIO_LED pin 6, pin 7, pin 8 and pin 9 */
    GPIO_Write(GPIO_LED, (uint16_t)~GPIO_ReadOutputData(GPIO_LED));

    /* Insert 300 ms delay */
    Delay(300);
  }
}
Example #27
0
pio_type platform_pio_op( unsigned port, pio_type pinmask, int op )
{
  GPIO_TypeDef* base = ( GPIO_TypeDef* )port_data[ port ];
  GPIO_InitTypeDef data;
  pio_type retval = 1;
  
  GPIO_StructInit( &data );
  switch( op )
  {
    case PLATFORM_IO_PORT_SET_VALUE:    
      GPIO_Write( base, ( u8 )pinmask );
      break;
      
    case PLATFORM_IO_PIN_SET:
      GPIO_WriteBit( base, ( u8 )pinmask, Bit_SET );
      break;
      
    case PLATFORM_IO_PIN_CLEAR:
      GPIO_WriteBit( base, ( u8 )pinmask, Bit_RESET );
      break;
      
    case PLATFORM_IO_PORT_DIR_OUTPUT:
      pinmask = 0xFF;     
    case PLATFORM_IO_PIN_DIR_OUTPUT:
      data.GPIO_Direction = GPIO_PinOutput;
      data.GPIO_Type = GPIO_Type_PushPull ;
      data.GPIO_Alternate=GPIO_OutputAlt1;
      data.GPIO_Pin = ( u8 )pinmask;
      GPIO_Init(base, &data);
      break;
      
    case PLATFORM_IO_PORT_DIR_INPUT:
      pinmask = 0xFF;     
    case PLATFORM_IO_PIN_DIR_INPUT:
      data.GPIO_Pin = ( u8 )pinmask;
      GPIO_Init(base, &data);
      break;    
            
    case PLATFORM_IO_PORT_GET_VALUE:
      retval = GPIO_Read( base );
      break;
      
    case PLATFORM_IO_PIN_GET:
      retval = GPIO_ReadBit( base, ( u8 )pinmask );
      break;
      
    default:
      retval = 0;
      break;
  }
  return retval;
}
void key_init(){
	GPIO_InitTypeDef GPIO_InitStructure;
  //GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);  //  ʹ�÷���������ʱ���������δ˾�

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;  // ѡ�����н�
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //���ó�����ʽ����, ��������ģʽ���ٶ�
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //����ģʽ�� I/O�����ٶ� 50M HZ
  GPIO_Init(GPIOB, &GPIO_InitStructure);  //��ʼ��PB��


	//дһ�������ݵ�PB��
	GPIO_Write(GPIOB, 0xff00);
}
Example #29
0
/**
* led 与 key的实验逻辑
*/
void do_led_key(void){
	key1 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0);
	key2 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1);
		
		if(key2 == 0) 
		{
			Delay(0x2A200);
			key2 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1);
			if(key2 == 0)
			{
						while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) == 0);
				    if(appFlag == 0){
							jump();
							appFlag = 1;
						}else{
							jump();
							appFlag = 0;
						}
			}
		}
		
		
		if(key1 == 0){
			Delay(0x2A200); 
	
			key1 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0);
			if(key1 == 0){
				while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0);
				if(pressFlag == 0){
					GPIO_Write(GPIOB, 0xff00); //写一个字数据到PB口
					pressFlag = 1;
				}else{
					GPIO_Write(GPIOB, 0x00ff); //写一个字数据到PB口
					pressFlag = 0;
				}
			}
		}
}
void visualsLf(void)
{
	if(System_Mode_G == Game_Over)
	{
		Segment_Set_Decimal(displayC);
		Segment_Set_Decimal(displayD);
	}
	else
	{
		Segment_Clear_Decimal(displayC);
		Segment_Clear_Decimal(displayD);
	}

	if(
		Left_motor_direction_G == Forwards
		&& Left_motor_speed_G != 0
		)
	{
		GPIO_Write(LED_Pin_LfFd, GPIO_HIGH);
	}
	else
	{
		GPIO_Write(LED_Pin_LfFd, GPIO_LOW);
	}

	if((Left_motor_direction_G == Reverse && Left_motor_speed_G != 0	) || (Course_correction_Lf == True))
	{
		GPIO_Write(LED_Pin_LfBd, GPIO_HIGH);
	}
	else
	{
		GPIO_Write(LED_Pin_LfBd, GPIO_LOW);
	}

//	Segment_Write(displayC, (Motor_Lf_Enc_Track & 0x000F) >> 0);
//	Segment_Write(displayD, (Motor_Lf_Enc_Track & 0x00F0) >> 4);

}