林子的海角 发表于 2012-8-6 21:06:09

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

用stm32的pc0-pc3连接四个led灯,让这四个led灯成流水形式亮,之后在pa9接一个中断,只要按下按键pa9就会产生中断并且所有的灯全部熄灭,经过四秒之后有的灯恢复流水灯模式,请问这样的程序怎么写?怎么做呢?谢谢大家!

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做一个流水灯实验程序怎么写?谢谢!【悬赏问答】

主程序循环执行流水灯,按键中断执行灯熄灭延时,楼主要多动手练习

shahexu 发表于 2012-8-8 13:52:13

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

找个GPIO的程序认真学习下,相信你应该能搞定

yjwpm 发表于 2012-8-8 14:00:59

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

同意楼上的方案..
另一种方案是 开一个定时器做计时使用,主循环中查看变量
inttimerled = 0;
intledCount = 1;//1代表灯亮 0代表等灭
inti = 0;
char ledoff = 0;
inttimerkey = 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;                                     //D1D2
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--);
}
#ifdefUSE_FULL_ASSERT
/**
* @briefReports 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:D

林子的海角 发表于 2012-8-11 22:56:09

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

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

谢谢你哈。我会好好努力的。
页: [1] 2
查看完整版本: 请问怎样用STM32做一个流水灯实验程序怎么写?谢谢!【悬赏问答】