dvbbs
收藏本页
联系我们
论坛帮助
dvbbs

单片机在线编程网侃单片机-ISPSTM32系列芯片的ISP → stm32 IO操作函数MyPinOp:


  共有26048人关注过本帖树形打印

主题:stm32 IO操作函数MyPinOp:

帅哥哟,离线,有人找我吗?
McuIsp
  1楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 贴子:43 积分:626 威望:0 精华:1 注册:2009-05-13 03:09:30
stm32 IO操作函数MyPinOp:  发贴心情 Post By:2009-07-05 08:42:47

MyPinOp.h

 

#ifndef __MyPinOp_H
#define __MyPinOp_H

//#define LockPortEn

#define STM32PINA00  (0*16+0)
#define STM32PINA01  (0*16+1)
#define STM32PINA02  (0*16+2)
#define STM32PINA03  (0*16+3)
#define STM32PINA04  (0*16+4)
#define STM32PINA05  (0*16+5)
#define STM32PINA06  (0*16+6)
#define STM32PINA07  (0*16+7)
#define STM32PINA08  (0*16+8)
#define STM32PINA09  (0*16+9)
#define STM32PINA10  (0*16+10)
#define STM32PINA11  (0*16+11)
#define STM32PINA12  (0*16+12)
#define STM32PINA13  (0*16+13)
#define STM32PINA14  (0*16+14)
#define STM32PINA15  (0*16+15)

#define STM32PINB00  (1*16+0)
#define STM32PINB01  (1*16+1)
#define STM32PINB02  (1*16+2)
#define STM32PINB03  (1*16+3)
#define STM32PINB04  (1*16+4)
#define STM32PINB05  (1*16+5)
#define STM32PINB06  (1*16+6)
#define STM32PINB07  (1*16+7)
#define STM32PINB08  (1*16+8)
#define STM32PINB09  (1*16+9)
#define STM32PINB10  (1*16+10)
#define STM32PINB11  (1*16+11)
#define STM32PINB12  (1*16+12)
#define STM32PINB13  (1*16+13)
#define STM32PINB14  (1*16+14)
#define STM32PINB15  (1*16+15)

#define STM32PINC00  (2*16+0)
#define STM32PINC01  (2*16+1)
#define STM32PINC02  (2*16+2)
#define STM32PINC03  (2*16+3)
#define STM32PINC04  (2*16+4)
#define STM32PINC05  (2*16+5)
#define STM32PINC06  (2*16+6)
#define STM32PINC07  (2*16+7)
#define STM32PINC08  (2*16+8)
#define STM32PINC09  (2*16+9)
#define STM32PINC10  (2*16+10)
#define STM32PINC11  (2*16+11)
#define STM32PINC12  (2*16+12)
#define STM32PINC13  (2*16+13)
#define STM32PINC14  (2*16+14)
#define STM32PINC15  (2*16+15)

#define STM32PIND00  (3*16+0)
#define STM32PIND01  (3*16+1)
#define STM32PIND02  (3*16+2)
#define STM32PIND03  (3*16+3)
#define STM32PIND04  (3*16+4)
#define STM32PIND05  (3*16+5)
#define STM32PIND06  (3*16+6)
#define STM32PIND07  (3*16+7)
#define STM32PIND08  (3*16+8)
#define STM32PIND09  (3*16+9)
#define STM32PIND10  (3*16+10)
#define STM32PIND11  (3*16+11)
#define STM32PIND12  (3*16+12)
#define STM32PIND13  (3*16+13)
#define STM32PIND14  (3*16+14)
#define STM32PIND15  (3*16+15)

#define STM32PINE00  (4*16+0)
#define STM32PINE01  (4*16+1)
#define STM32PINE02  (4*16+2)
#define STM32PINE03  (4*16+3)
#define STM32PINE04  (4*16+4)
#define STM32PINE05  (4*16+5)
#define STM32PINE06  (4*16+6)
#define STM32PINE07  (4*16+7)
#define STM32PINE08  (4*16+8)
#define STM32PINE09  (4*16+9)
#define STM32PINE10  (4*16+10)
#define STM32PINE11  (4*16+11)
#define STM32PINE12  (4*16+12)
#define STM32PINE13  (4*16+13)
#define STM32PINE14  (4*16+14)
#define STM32PINE15  (4*16+15)

#define STM32PINF00  (5*16+0)
#define STM32PINF01  (5*16+1)
#define STM32PINF02  (5*16+2)
#define STM32PINF03  (5*16+3)
#define STM32PINF04  (5*16+4)
#define STM32PINF05  (5*16+5)
#define STM32PINF06  (5*16+6)
#define STM32PINF07  (5*16+7)
#define STM32PINF08  (5*16+8)
#define STM32PINF09  (5*16+9)
#define STM32PINF10  (5*16+10)
#define STM32PINF11  (5*16+11)
#define STM32PINF12  (5*16+12)
#define STM32PINF13  (5*16+13)
#define STM32PINF14  (5*16+14)
#define STM32PINF15  (5*16+15)

#define STM32PING00  (6*16+0)
#define STM32PING01  (6*16+1)
#define STM32PING02  (6*16+2)
#define STM32PING03  (6*16+3)
#define STM32PING04  (6*16+4)
#define STM32PING05  (6*16+5)
#define STM32PING06  (6*16+6)
#define STM32PING07  (6*16+7)
#define STM32PING08  (6*16+8)
#define STM32PING09  (6*16+9)
#define STM32PING10  (6*16+10)
#define STM32PING11  (6*16+11)
#define STM32PING12  (6*16+12)
#define STM32PING13  (6*16+13)
#define STM32PING14  (6*16+14)
#define STM32PING15  (6*16+15)
  //CRH/CRL:0 AIN;1 GPPO_10MHz;2 GPPO_2MHz;3 GPPO_50MHz
          //4 IN ;5 GOCO_10MHz;6 GOCO_2MHz;7 GOCO_50MHz
          //8 IPP;9 APPO_10MHz;a APPO_2MHz;b APPO_50MHz
          //c NA ;d AOCO_10MHz;e AOCO_2MHz;f AOCO_50MHz

typedef enum
{
  PinMode_AIN=0,
  PinMode_GPPO_10MHz=1,
  PinMode_GPPO_2MHz=2,
  PinMode_GPPO_50MHz=3,
  PinMode_IN=4,
  PinMode_GOCO_10MHz=5,
  PinMode_GOCO_2MHz=6,
  PinMode_GOCO_50MHz=7,
  PinMode_IPP=8,
  PinMode_APPO_10MHz=9,
  PinMode_APPO_2MHz=10,
  PinMode_APPO_50MHz=11,
  PinMode_NA=12,
  PinMode_AOCO_10MHz=13,
  PinMode_AOCO_2MHz=14,
  PinMode_AOCO_50MHz=15,
}TStmPinMode;

void SetPinMode(unsigned char Pin,TStmPinMode  mode);
unsigned long PinIdr(unsigned char Pin);
unsigned long  PinOdr(unsigned char Pin);
void SetPin(unsigned char Pin);
void ClrPin(unsigned char Pin);
void SpinPin(unsigned char Pin);
unsigned long  LockPin(unsigned char Pin);
unsigned long  UnlockPin(unsigned char Pin);
unsigned long  LockPort(unsigned char Pin);

#include "CortexM3_Bitband_DEF.h"
#define IDRBB(stm32pin) ((*((vu32 *) BITBAND_PERI((((stm32pin/16)*0x400+GPIOA_BASE)+0x08),stm32pin%16))))
#define ODRBB(stm32pin) ((*((vu32 *) BITBAND_PERI((((stm32pin/16)*0x400+GPIOA_BASE)+0x0c),stm32pin%16))))
#define EXTIPRBB(stm32pin) ((*((vu32 *) BITBAND_PERI(((EXTI_BASE)+0x14),stm32pin%16))))
#endif


 


支持(0中立(0反对(0单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
McuIsp
  2楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 贴子:43 积分:626 威望:0 精华:1 注册:2009-05-13 03:09:30
MyPinOp.C  发贴心情 Post By:2009-07-05 08:43:16

//--
#include "MyPinOp.h"
#define STM_GPIO_BASE_ADDRESS ((unsigned long  )0x40010800)
typedef struct
{
  volatile unsigned long CRL;
  volatile unsigned long  CRH;
  volatile unsigned long  IDR;
  volatile unsigned long  ODR;
  volatile unsigned long  BSRR;
  volatile unsigned long  BRR;
  volatile unsigned long  LCKR;
} MyGPIO_TypeDef;
//--
__root void SetPinMode(unsigned char Pin,TStmPinMode  mode)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  unsigned long   cr;
  unsigned long   crm=mode&0xf;
  crm=(crm<<((Pin&0x7)*4));
  unsigned long   crn=~((0x0fl)<<((Pin&0x7)*4));
  if((Pin&0xf)<8)
  {
    cr=gpio->CRL;
    cr&=crn;
    cr|=crm;
    gpio->CRL=cr;
  }
  else
  {
    cr=gpio->CRH;
    cr&=crn;
    cr|=crm;
    gpio->CRH=cr;
  }
}
//--
__root unsigned long   PinIdr(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  return (gpio->IDR&(0x1<<(Pin&0xf)));
}
//--
__root unsigned long   PinOdr(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  return (gpio->ODR&(0x1<<(Pin&0xf)));
}
//--
__root void SetPin(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  gpio->BSRR=(0x1<<(Pin&0xf));
}
//--
__root void ClrPin(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  gpio->BRR=(0x1<<(Pin&0xf));
}
//--
__root void SpinPin(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  if((gpio->ODR&(0x1<<(Pin&0xf)))==0)
  {
    gpio->BSRR=(0x1<<(Pin&0xf));
  }
  else
  {
    gpio->BRR=(0x1<<(Pin&0xf));
  }
}
//--
unsigned long   LockPin(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  if(gpio->LCKR&0x10000)return 0;
  gpio->LCKR|=(0x1<<(Pin&0xf));
  return 1;
}
//--
unsigned long   UnlockPin(unsigned char Pin)
{
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  if(gpio->LCKR&0x10000)return 0;
  gpio->LCKR&=(~(0x1<<(Pin&0xf)));
  return 1;
}
//--
unsigned long   LockPort(unsigned char Pin)
{
#ifdef LockPortEn
  MyGPIO_TypeDef *gpio;
  gpio=(MyGPIO_TypeDef*)(STM_GPIO_BASE_ADDRESS+(Pin/16*0x400l));
  if((gpio->LCKR&0x10000)!=0)return 1;
  unsigned long   lr=gpio->LCKR;
  lr&=0xffff;
  for(;;)
  {
    gpio->LCKR=lr|0x10000;
    gpio->LCKR=lr;
    gpio->LCKR=lr|0x10000;
    lr=gpio->LCKR;
    if((gpio->LCKR&0x10000)!=0)continue;
    lr=gpio->LCKR;
    if((gpio->LCKR&0x10000)!=0)break;
  }
#endif
  return 1;
}
//--

支持(0中立(0反对(0单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
McuIsp
  3楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 贴子:43 积分:626 威望:0 精华:1 注册:2009-05-13 03:09:30
CortexM3_Bitband_DEF.h  发贴心情 Post By:2009-07-05 08:43:52

#ifndef __CortexM3_Bitband_DEF_H
#define __CortexM3_Bitband_DEF_H

#define BITBAND_SRAM_REF   0x20000000
#define BITBAND_SRAM_BASE  0x22000000
#define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + (a-BITBAND_SRAM_REF)*32 + (b*4)))  // Convert SRAM address
#define BITBAND_PERI_REF   0x40000000
#define BITBAND_PERI_BASE  0x42000000
#define BITBAND_PERI(a,b) ((BITBAND_PERI_BASE + (a-BITBAND_PERI_REF)*32 + (b*4)))  // Convert PERI address
#endif


支持(0中立(0反对(0单帖管理 | 引用 | 回复 回到顶部

返回版面帖子列表

stm32 IO操作函数MyPinOp:








签名