原创 点亮智林测控开发板的发光二极管

2008-7-27 18:08 1981 9 9 分类: MCU/ 嵌入式

      智林测控的开发板,制板精良,特别是它带有真彩屏1.8寸,格外引人注目。


今天我弄了一块。


      发现他的说明书特别短小精焊,适合初学者快速入门


     /*


                                            \\\|///
                                         \\  - -  //
                                        (  @ @  )
+---------------------oOOo-(_)-oOOo-------------------------+
|                 智林STM32开发板试验程序                                 |
|                    GPIO 输出方式试验                                            |
|                 刘笑然 by Xiaoran Liu                                             |
|                        2008.4.16                                                           |
|                                                                                                   |
|           智林测控技术研究所 ZERO research group                |
|          www.the0.net      http://shop35738797.taobao.com/          |
|                                              Oooo                                            |
+-----------------------oooO--(   )------------------------------+
                                        (   )   ) /
                                         \ (   (_/
                                          \_)    


*/
/*----------------------------------------------------------*\
 |  引入相关芯片的头文件                                    |
\*----------------------------------------------------------*/
#include <stm32f10x_lib.h>                        // STM32F10x Library Definitions
#include "STM32_Init.h"                           // STM32 Initialization
/*----------------------------------------------------------*\
 | HARDWARE DEFINE                                          |
\*----------------------------------------------------------*/
#define LED             ( 1 << 5 )                // PB5: LED D2
/*----------------------------------------------------------*\
 |  Delay                                                   |
 |  延时 Inserts a delay time.                              |
 |  nCount: 延时时间                                        |
 |  nCount: specifies the delay time length.                |
\*----------------------------------------------------------*/
void Delay(vu32 nCount) {
  for(; nCount != 0; nCount--);
  }
/*----------------------------------------------------------*\
 | MIAN ENTRY                                               |
\*----------------------------------------------------------*/
int main (void) {
  stm32_Init ();                                  // STM32 setup
  for(;;) {
    GPIOB->ODR &= ~LED;                           // switch on LED
 Delay(2000000);
    GPIOB->ODR |=  LED;                           // switch off LED
 Delay(2000000);
    }
  }
/*----------------------------------------------------------*\
 | END OF FILE                                              |
\*----------------------------------------------------------*/


上述我想最不容易理解的地方就是ODR,还加了个->,我这个人一见结构体就晕,没有办法还得硬着头皮查,


typedef struct
{
  vu32 CRL;
  vu32 CRH;
  vu32 IDR;
  vu32 ODR;
  vu32 BSRR;
  vu32 BRR;
  vu32 LCKR;
} GPIO_TypeDef;


而用哪个端口在#include "STM32_Init.h"                           // STM32 Initialization


已经说明用的是B口,780b8ba5-6d4a-4b86-935d-f2b68be24575.JPG


我又在数据手册上查 ODR为


端口输出数据寄存器(GPIOx_ODR)


这下我明白了,其余设置不变只改变端口方向寄存器的值就可以了


下面的绿灯就是点亮的发光二极管


bea26359-bec0-4996-ad22-7b795cc53cfa.jpg



点击图片即可查看更多文章


点击查看更多文章

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
9
关闭 站长推荐上一条 /3 下一条