#include "stm32f10x.h"
void Delay_ms( uint16_t time_ms );
int main()
{
//打开led对应的引脚时钟 并进行初始化
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//ʹÄÜGPIOµÄÍâÉèʱÖÓ
{
//打开led对应的引脚时钟 并进行初始化
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//ʹÄÜGPIOµÄÍâÉèʱÖÓ
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_13;//Ñ¡ÔñÒªÓõÄGPIOÒý½Å
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÉèÖÃÒý½ÅÄ£Ê½ÎªÍÆÃâÊä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//ÉèÖÃÒý½ÅËÙ¶ÈΪ50MHZ
GPIO_Init(GPIOC, &GPIO_InitStructure);//µ÷Óÿ⺯Êý£¬³õʼ»¯GPIO
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÉèÖÃÒý½ÅÄ£Ê½ÎªÍÆÃâÊä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//ÉèÖÃÒý½ÅËÙ¶ÈΪ50MHZ
GPIO_Init(GPIOC, &GPIO_InitStructure);//µ÷Óÿ⺯Êý£¬³õʼ»¯GPIO
//打开按键对应的引脚时钟 并进行初始化 按键设置为输出模式 只需要设置模式和引脚 不需要设置速率
GPIO_InitTypeDef GPIO_InitStructure1;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//¿ªÆôGPIOCµÄÍâÉèʱÖÓ
GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_14;//Ñ¡ÔñÒªÓõÄGPIOÒý½Å
GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_IPU; //ÉèÖÃÒý½ÅģʽΪÉÏÀÊäÈëģʽ
GPIO_Init(GPIOB, &GPIO_InitStructure1); //µ÷Óÿ⺯Êý£¬³õʼ»¯GPIO
GPIO_InitTypeDef GPIO_InitStructure1;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//¿ªÆôGPIOCµÄÍâÉèʱÖÓ
GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_14;//Ñ¡ÔñÒªÓõÄGPIOÒý½Å
GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_IPU; //ÉèÖÃÒý½ÅģʽΪÉÏÀÊäÈëģʽ
GPIO_Init(GPIOB, &GPIO_InitStructure1); //µ÷Óÿ⺯Êý£¬³õʼ»¯GPIO
while(1)
{
//读取指定IO口的输入 来判断按键是否按下 此时不是中断模式
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14)==0)//ÅжÏ3¸ö°´¼üÊÇ·ñÓа´ÏÂ
{
//按下 点亮
Delay_ms(20);
GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);
}
else
{
//否则 熄灭
GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);
}
}
{
//读取指定IO口的输入 来判断按键是否按下 此时不是中断模式
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14)==0)//ÅжÏ3¸ö°´¼üÊÇ·ñÓа´ÏÂ
{
//按下 点亮
Delay_ms(20);
GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);
}
else
{
//否则 熄灭
GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);
}
}
}
void Delay_ms( uint16_t time_ms )
{
uint16_t i,j;
for( i=0;i<time_ms;i++ )
{
for( j=0;j<10309;j++ );//´óÔ¼1ms
}
}
{
uint16_t i,j;
for( i=0;i<time_ms;i++ )
{
for( j=0;j<10309;j++ );//´óÔ¼1ms
}
}