LED 流水灯闪烁

来源:互联网 发布:三菱fx 2n编程手册 编辑:程序博客网 时间:2024/04/28 11:36
/****************************************************************************#include "stm32f10x.h"GPIO_InitTypeDef GPIO_InitStructure;#define LED1_ON GPIO_SetBits(GPIOB, GPIO_Pin_5);  #define LED1_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_5); #define LED2_ON GPIO_SetBits(GPIOD, GPIO_Pin_6);  #define LED2_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_6); #define LED3_ON GPIO_SetBits(GPIOD, GPIO_Pin_3);  #define LED3_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_3);  void RCC_Configuration(void);void LED_Config(void);void Delay(__IO uint32_t nCount);/***************************************************************************** 名    称:void LED_Config(void)* 功    能:LED 控制初始化函数* 入口参数:无* 出口参数:无* 说    明:* 调用方法:无 ****************************************************************************/ void LED_Config(void){  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD , ENABLE);  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;     //LED1  V6   //将V6,V7,V8 配置为通用推挽输出    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口线翻转速度为50MHz  //GPIOB->CRL |= 0x05<<20;        //GPIOB_InitStruct->GPIO_Speed=3;  GPIO_Init(GPIOB, &GPIO_InitStructure);   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_3; //LED2, LED3 V7 V8  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  GPIO_Init(GPIOD, &GPIO_InitStructure); // GPIO_Init(GPIOD, &GPIO_InitStructure);  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;       //LCD背光控制  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  GPIO_Init(GPIOD, &GPIO_InitStructure);  GPIO_ResetBits(GPIOD, GPIO_Pin_13);              //LCD背光关闭}/***************************************************************************** 名    称:int main(void)* 功    能:主函数* 入口参数:无* 出口参数:无* 说    明:* 调用方法:无 ****************************************************************************/ int main(void){   RCC_Configuration();   //系统时钟配置  // LED_Config();    //LED控制配置 //1////////////////////////////////////////////////////////////////////// //直接使用ODR进行设置//  RCC->APB2ENR|=1<<3;//  GPIOB->CRL&=0XFFF0FFFF;//  GPIOB->CRL|=0X00030000;//  GPIOB->ODR|=1<<5; ////  RCC->APB2ENR|=1<<5; //  GPIOD->CRL&=0XFF0FF0FF;//  GPIOD->CRL|=0X00300300;//  GPIOD->ODR|=1<<3;//  GPIOD->ODR|=1<<6;//   while(1); //////////////////////////////////////////////////////////////////////////////     while (1)  {///2///////////////////////////////////////////////////////////////通过位设置/清除寄存器(GPIO_BSRR)和清除寄存器(GPIO_BRR)进行设置//     GPIOB->BSRR = (0x01 <<5);//   GPIOD->BRR= 0x01<<6;//   GPIOD->BRR= 0x01<<3;////////////////////////////////////////////////////////////////// GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);///3//////////////////////////////////////////////////////////////直接对端口输出数据寄存器进行设置://GPIO_WriteBit(GPIOB,GPIO_Pin_5,Bit_RESET);//GPIO_WriteBit(GPIOD,GPIO_Pin_6,Bit_SET);//GPIO_WriteBit(GPIOB,GPIO_Pin_3,Bit_RESET);////////////////////////////////////////////////////////////////   Delay(0xAFFFF);// GPIOB->BRR= (0x01<<5);// GPIOD->BSRR= 0x01<<6;// GPIOD->BRR= 0x01<<3;    Delay(0xAFFFF);// GPIOB->BRR=(0x01<<5);// GPIOD->BRR=0x01<<6;// GPIOD->BSRR=0x01<<3; Delay(0xAFFFF); //  LED1_ON; LED2_OFF; LED3_OFF;//LED1亮  LED2,LED3灭(LED2,LED3 仅V5  V3,V2,V2.1板有)//    //LED1_OFF; LED2_ON; LED3_OFF;//LED2亮  LED1,LED3灭(LED2,LED3 仅V5  V3,V2,V2.1板有)//Delay(0xAFFFF);//LED1_OFF; LED2_OFF; LED3_ON;//LED3亮  LED1,LED2灭(LED2,LED3 仅V5  V3,V2,V2.1板有)//Delay(0xAFFFF);     }}/***************************************************************************** 名    称:void RCC_Configuration(void)* 功    能:系统时钟配置为72MHZ* 入口参数:无* 出口参数:无* 说    明:* 调用方法:无 ****************************************************************************/ void RCC_Configuration(void){     SystemInit();}/***************************************************************************** 名    称:void Delay(__IO uint32_t nCount)* 功    能:延时函数* 入口参数:无* 出口参数:无* 说    明:* 调用方法:无 ****************************************************************************/ void Delay(__IO uint32_t nCount){   for(; nCount != 0; nCount--);}

0 0
原创粉丝点击