| 
              【程序】#include "stm32f10x.h"
 #define _BV(n) (1 << (n))
 #define K1 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0)
 // 延时函数
 void delay()
 {
 uint32_t i;
 for (i = 0; i < 20000; i++);
 }
 int main(void)
 {
 GPIO_InitTypeDef init;
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // 开启PB时钟
 // PB8~15为输出
 init.GPIO_Pin = 0xff00;
 init.GPIO_Speed = GPIO_Speed_50MHz;
 init.GPIO_Mode = GPIO_Mode_Out_OD;
 GPIO_Init(GPIOB, &init);
 // PB0~7为输入
 init.GPIO_Pin = 0x00ff;
 init.GPIO_Mode = GPIO_Mode_IPD;
 GPIO_Init(GPIOB, &init);
 while (1)
 {
 // 当按键1按下时
 if (!K1)
 {
 delay();
 if (!K1)
 {
 GPIOB->ODR ^= _BV(8); // 反转继电器所在引脚的电平
 while (!K1);
 }
 }
 }
 }
 
 
 |