你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

[复制链接]
林子的海角 提问时间:2012-8-6 21:06 /
用stm32的pc0-pc3连接四个led灯,让这四个led灯成流水形式亮,之后在pa9接一个中断,只要按下按键pa9就会产生中断并且所有的灯全部熄灭,经过四秒之后有的灯恢复流水灯模式,请问这样的程序怎么写?怎么做呢?谢谢大家!
收藏 评论20 发布时间:2012-8-6 21:06

举报

20个回答
yjwpm 回答时间:2012-8-6 22:21:11

RE:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!

不知道楼主会51不,会51就一定能写出来,如果不会那就要另说了,
看来楼主的变通能力不强呀...
林子的海角 回答时间:2012-8-6 23:42:27

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!

回复第 2 楼 于2012-08-06 22:21:11发表:
不知道楼主会51不,会51就一定能写出来,如果不会那就要另说了,
看来楼主的变通能力不强呀.
不会呢,麻烦你帮帮忙吧,给我解说下呢,谢谢哈,急用呢。学的不是很好呢,现在要做实验没办法呢,谢谢你哈。
cx032302 回答时间:2012-8-8 12:00:23

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

主程序循环执行流水灯,按键中断执行灯熄灭延时,楼主要多动手练习
火木 回答时间:2012-8-8 13:52:13

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

找个GPIO的程序认真学习下,相信你应该能搞定
yjwpm 回答时间:2012-8-8 14:00:59

RE:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

同意楼上的方案..
另一种方案是 开一个定时器做计时使用,主循环中查看变量
int  timerled = 0;
int  ledCount = 1;//1代表灯亮 0代表等灭
int  i = 0;
char ledoff = 0;
int  timerkey = 0;

while(1)
{
    if(!ledoff)  
    {
      ledCount = 1;
      for(i = 0;i < 16;i++)
      {
            GPIOA->ODR = ledCount;
            ledCount
航天航海 回答时间:2012-8-8 17:35:39

RE:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

可以在网上找个流水灯程序学习学习。
家园-376789 回答时间:2012-8-9 13:28:08

RE:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

这是,什么样的一个,程序?
zykzyk-93033 回答时间:2012-8-9 20:48:20

RE:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;

void RCC_Configuration(void);
void Delay(__IO uint32_t nCount);
int main(void)
{
  //uint16_t a;
  /* System Clocks Configuration **********************************************/
  
  RCC_Configuration();   
  
  //
  /* Configure all unused GPIO port pins in Analog Input mode (floating input
     trigger OFF), this will reduce the power consumption and increase the device
     immunity against EMI/EMC *************************************************/
  
/*  RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
                         RCC_APB2Periph_GPIOE, ENABLE);
*/
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD,ENABLE);

  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;                                     //D1  D2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);                                         
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_13;                 //D3, D4
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  while (1)
  {
  
  
    GPIO_SetBits(GPIOC, GPIO_Pin_6);// D1亮                  
    Delay(0xAFFFF);
    GPIO_SetBits(GPIOC, GPIO_Pin_7 );        //D2亮         
    GPIO_ResetBits(GPIOC, GPIO_Pin_6);        //D1灭
    Delay(0xAFFFF);
    GPIO_SetBits(GPIOD, GPIO_Pin_13 );        //D3亮         
    GPIO_ResetBits(GPIOC, GPIO_Pin_7);        //D2灭
    Delay(0xAFFFF);
    GPIO_SetBits(GPIOD, GPIO_Pin_6 );        //D4亮         
    GPIO_ResetBits(GPIOD, GPIO_Pin_13);        //D3灭
    Delay(0xAFFFF);
    GPIO_ResetBits(GPIOD, GPIO_Pin_6);        //D4灭
  }
}

void RCC_Configuration(void)
{   
  /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
  SystemInit();
}

void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval : None
  */

void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while (1)
  {
  }
}
#endif
林子的海角 回答时间:2012-8-11 22:56:09

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

回复第 4 楼 于2012-08-08 12:00:23发表:
主程序循环执行流水灯,按键中断执行灯熄灭延时,楼主要多动手练习
 

谢谢你哈。我会好好努力的。
林子的海角 回答时间:2012-8-11 22:57:45

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

回复第 5 楼 于2012-08-08 13:52:13发表:
找个GPIO的程序认真学习下,相信你应该能搞定 

谢谢提醒呢,我会的哈,我会努力的呢。
林子的海角 回答时间:2012-8-11 22:59:39

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

<div style="border-right: #ccc 1px dashed; padding-right: 5px; border-top: #ccc 1px dashed; padding-left: 5px; padding-bottom: 5px; border-left: #ccc 1px dashed; padding-top: 5px; border-bottom: #ccc 1px dashed">回复第 6 楼 于2012-08-08 14:00:59发表:
同意楼上的方案..
另一种方案是 开一个定时器做计时使用,主循环中查看变量
int timerled = 0;
int ledCount = 1;//1代表灯亮 0代表等灭
int i = 0;
char ledoff = 0;
int timerkey = 0;

while(1)
{
if(!ledoff)
{
ledCount = 1;
for(i = 0;i < 16;i++)
{
GPIOA->ODR = ledCount;
ledCount
林子的海角 回答时间:2012-8-11 23:02:06

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

回复第 7 楼 于2012-08-08 17:35:39发表:
可以在网上找个流水灯程序学习学习。 

谢谢哈。
林子的海角 回答时间:2012-8-11 23:08:30

回复:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

回复第 9 楼 于2012-08-09 20:48:20发表:
#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;

void RCC_Configuration(void);
void Delay(__IO uint32_t nCount);
int main(void)
{
//uint16_t a;
/* System Clocks Configuration **********************************************/

RCC_Configuration();

//
/* Configure all unused GPIO port pins in Analog Input mode (floating input
trigger OFF), this will reduce the power consumption and increase the device
immunity against EMI/EMC *************************************************/

/* RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, ENABLE);
*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD,ENABLE);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; //D1 D2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_13; //D3, D4
GPIO_Init(GPIOD, &GPIO_InitStructure);
while (1)
{


GPIO_SetBits(GPIOC, GPIO_Pin_6);// D1亮
Delay(0xAFFFF);
GPIO_SetBits(GPIOC, GPIO_Pin_7 ); //D2亮
GPIO_ResetBits(GPIOC, GPIO_Pin_6); //D1灭
Delay(0xAFFFF);
GPIO_SetBits(GPIOD, GPIO_Pin_13 ); //D3亮
GPIO_ResetBits(GPIOC, GPIO_Pin_7); //D2灭
Delay(0xAFFFF);
GPIO_SetBits(GPIOD, GPIO_Pin_6 ); //D4亮
GPIO_ResetBits(GPIOD, GPIO_Pin_13); //D3灭
Delay(0xAFFFF);
GPIO_ResetBits(GPIOD, GPIO_Pin_6); //D4灭
}
}

void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
}

void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/

void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif 

谢谢哈,真的是非常的谢谢呢。万分的感谢呢。
蓝调街口-366393 回答时间:2012-8-13 10:23:30

RE:请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

建议楼主下载stm32 的GPIO例程,结合相关技术文档仔细耐心研究,这样针对性的学习相信会有很大收获

AN2569_STM32F10xxx GPIO应用示例.pdf

下载

178.84 KB, 下载次数: 10

12下一页

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版