搜索
bottom↓
回复: 21

[共享]LPC231X系列的位操作支持库

[复制链接]

出0入296汤圆

发表于 2006-4-2 18:06:54 | 显示全部楼层 |阅读模式
#ifndef __Use_RD_LPC213X_H_

#define __Use_RD_LPC213X_H_

/**************************************************************

*  函数库说明:ARM LPC213x系列操作辅助函数库                  *

*  版本:      v1.0                                           *

*  平台:      LPC213X系列                                    *

*  作者:      傻孩子                                         *

*  日期:      2006年3月30日                                  *

*  修改:      傻孩子                                         *

*  修改日期:  2006年3月30日                                  *

*                                                             *

*  [说明]                                                     *

*              1、支持端口位操作。                            *

**************************************************************/



/************************

*     结 构 体 定 义    *

************************/



/*----------------------*

*     8位变量位映射     *

*----------------------*/

typedef struct BYTE_BIT

{

    unsigned BIT0:1;

    unsigned BIT1:1;

    unsigned BIT2:1;

    unsigned BIT3:1;

    unsigned BIT4:1;

    unsigned BIT5:1;

    unsigned BIT6:1;

    unsigned BIT7:1;

}BYTEBIT;



/*----------------------*

*     16位变量位映射    *

*----------------------*/

typedef struct WORD_BIT

{

    unsigned BIT0:1;

    unsigned BIT1:1;

    unsigned BIT2:1;

    unsigned BIT3:1;

    unsigned BIT4:1;

    unsigned BIT5:1;

    unsigned BIT6:1;

    unsigned BIT7:1;

   

    unsigned BIT8:1;

    unsigned BIT9:1;

    unsigned BIT10:1;

    unsigned BIT11:1;

    unsigned BIT12:1;

    unsigned BIT13:1;

    unsigned BIT14:1;

    unsigned BIT15:1;

}WORDBIT;



/*----------------------*

*     32位变量位映射    *

*----------------------*/

typedef struct DWORD_BIT

{

    unsigned BIT0:1;

    unsigned BIT1:1;

    unsigned BIT2:1;

    unsigned BIT3:1;

    unsigned BIT4:1;

    unsigned BIT5:1;

    unsigned BIT6:1;

    unsigned BIT7:1;

   

    unsigned BIT8:1;

    unsigned BIT9:1;

    unsigned BIT10:1;

    unsigned BIT11:1;

    unsigned BIT12:1;

    unsigned BIT13:1;

    unsigned BIT14:1;

    unsigned BIT15:1;

   

    unsigned BIT16:1;

    unsigned BIT17:1;

    unsigned BIT18:1;

    unsigned BIT19:1;

    unsigned BIT20:1;

    unsigned BIT21:1;

    unsigned BIT22:1;

    unsigned BIT23:1;

   

    unsigned BIT24:1;

    unsigned BIT25:1;

    unsigned BIT26:1;

    unsigned BIT27:1;

    unsigned BIT28:1;

    unsigned BIT29:1;

    unsigned BIT30:1;

    unsigned BIT31:1;

}DWORDBIT;



/*----------------------*

*    32位变量4分映射    *

*----------------------*/

typedef struct DWORD_DIV4

{

    unsigned BYTEA:8;

    unsigned BYTEB:8;

    unsigned BYTEC:8;

    unsigned BYTED:8;

}DWORDPORT8;



typedef struct DWORD_DIV2

{

    unsigned WORDA:16;

    unsigned WORDB:16;

}DWORDPORT16;



/*----------------------*

*    16位变量2分映射    *

*----------------------*/

typedef struct WORD_DIV2

{

    unsigned BYTEA:8;

    unsigned BYTEB:8;

}WORDPORT8;



/*----------------------*

*    8位变量2分映射     *

*----------------------*/

typedef struct BYTE_DIV2

{

    unsigned BYTEL:4;

    unsigned BYTEH:4;

}WORDHBYTE;



/************************

*     系 统 宏 定 义    *

************************/



/*----------------------*

*     系统常数宏定义    *

*----------------------*/



/************************

*     动 作 宏 定 义    *

************************/



# define P0    (*((volatile DWORDBIT *)0xE0028000))

# define DIR0  (*((volatile DWORDBIT *)0xE0028008))

# define P1    (*((volatile DWORDBIT *)0xE0028010))

# define DIR1  (*((volatile DWORDBIT *)0xE0028018))



# define PORT0 (*((volatile DWORDPORT8 *)0xE0028000))

# define PORT1 (*((volatile DWORDPORT8 *)0xE0028010))



# define WPORT0 (*((volatile DWORDPORT16 *)0xE0028000))

# define WPORT1 (*((volatile DWORDPORT16 *)0xE0028010))



# define PORT0A    PORT0.BYTEA

# define PORT0B    PORT0.BYTEB

# define PORT0C    PORT0.BYTEC

# define PORT0D    PORT0.BYTED



# define PORT1A    PORT1.BYTEA

# define PORT1B    PORT1.BYTEB

# define PORT1C    PORT1.BYTEC

# define PORT1D    PORT1.BYTED



# define WPORTA    WPORT0.WORDA

# define WPORTB    WPORT0.WORDB

# define WPORTC    WPORT1.WORDA

# define WPORTD    WPORT1.WORDB



# define P00        P0.BIT0

# define P01        P0.BIT1

# define P02        P0.BIT2

# define P03        P0.BIT3

# define P04        P0.BIT4

# define P05        P0.BIT5

# define P06        P0.BIT6

# define P07        P0.BIT7



# define P08        P0.BIT8

# define P09        P0.BIT9

# define P010       P0.BIT10

# define P011       P0.BIT11

# define P012       P0.BIT12

# define P013       P0.BIT13

# define P014       P0.BIT14

# define P015       P0.BIT15



# define P016       P0.BIT16

# define P017       P0.BIT17

# define P018       P0.BIT18

# define P019       P0.BIT19

# define P020       P0.BIT20

# define P021       P0.BIT21

# define P022       P0.BIT22

# define P023       P0.BIT23



# define P024       P0.BIT24

# define P025       P0.BIT25

# define P026       P0.BIT26

# define P027       P0.BIT27

# define P028       P0.BIT28

# define P029       P0.BIT29

# define P030       P0.BIT30

# define P031       P0.BIT31



# define P10        P1.BIT0

# define P11        P1.BIT1

# define P12        P1.BIT2

# define P13        P1.BIT3

# define P14        P1.BIT4

# define P15        P1.BIT5

# define P16        P1.BIT6

# define P17        P1.BIT7



# define P18        P1.BIT8

# define P19        P1.BIT9

# define P110       P1.BIT10

# define P111       P1.BIT11

# define P112       P1.BIT12

# define P113       P1.BIT13

# define P114       P1.BIT14

# define P115       P1.BIT15



# define P116       P1.BIT16

# define P117       P1.BIT17

# define P118       P1.BIT18

# define P119       P1.BIT19

# define P120       P1.BIT20

# define P121       P1.BIT21

# define P122       P1.BIT22

# define P123       P1.BIT23



# define P124       P1.BIT24

# define P125       P1.BIT25

# define P126       P1.BIT26

# define P127       P1.BIT27

# define P128       P1.BIT28

# define P129       P1.BIT29

# define P130       P1.BIT30

# define P131       P1.BIT31





# define DIR00        DIR0.BIT0

# define DIR01        DIR0.BIT1

# define DIR02        DIR0.BIT2

# define DIR03        DIR0.BIT3

# define DIR04        DIR0.BIT4

# define DIR05        DIR0.BIT5

# define DIR06        DIR0.BIT6

# define DIR07        DIR0.BIT7



# define DIR08        DIR0.BIT8

# define DIR09        DIR0.BIT9

# define DIR010       DIR0.BIT10

# define DIR011       DIR0.BIT11

# define DIR012       DIR0.BIT12

# define DIR013       DIR0.BIT13

# define DIR014       DIR0.BIT14

# define DIR015       DIR0.BIT15



# define DIR016       DIR0.BIT16

# define DIR017       DIR0.BIT17

# define DIR018       DIR0.BIT18

# define DIR019       DIR0.BIT19

# define DIR020       DIR0.BIT20

# define DIR021       DIR0.BIT21

# define DIR022       DIR0.BIT22

# define DIR023       DIR0.BIT23



# define DIR024       DIR0.BIT24

# define DIR025       DIR0.BIT25

# define DIR026       DIR0.BIT26

# define DIR027       DIR0.BIT27

# define DIR028       DIR0.BIT28

# define DIR029       DIR0.BIT29

# define DIR030       DIR0.BIT30

# define DIR031       DIR0.BIT31





# define DIR10        DIR1.BIT0

# define DIR11        DIR1.BIT1

# define DIR12        DIR1.BIT2

# define DIR13        DIR1.BIT3

# define DIR14        DIR1.BIT4

# define DIR15        DIR1.BIT5

# define DIR16        DIR1.BIT6

# define DIR17        DIR1.BIT7



# define DIR18        DIR1.BIT8

# define DIR19        DIR1.BIT9

# define DIR110       DIR1.BIT10

# define DIR111       DIR1.BIT11

# define DIR112       DIR1.BIT12

# define DIR113       DIR1.BIT13

# define DIR114       DIR1.BIT14

# define DIR115       DIR1.BIT15



# define DIR116       DIR1.BIT16

# define DIR117       DIR1.BIT17

# define DIR118       DIR1.BIT18

# define DIR119       DIR1.BIT19

# define DIR120       DIR1.BIT20

# define DIR121       DIR1.BIT21

# define DIR122       DIR1.BIT22

# define DIR123       DIR1.BIT23



# define DIR124       DIR1.BIT24

# define DIR125       DIR1.BIT25

# define DIR126       DIR1.BIT26

# define DIR127       DIR1.BIT27

# define DIR128       DIR1.BIT28

# define DIR129       DIR1.BIT29

# define DIR130       DIR1.BIT30

# define DIR131       DIR1.BIT31



#endif
-----此内容被Gorgon Meducer于2006-04-02,18:10:57编辑过

出0入296汤圆

 楼主| 发表于 2006-4-2 18:08:09 | 显示全部楼层
比方说,让P1.18变为低电平

只需要

DIR118 = 1;  //输出状态

P118 = 0;    //P1.18设为低电平

出0入0汤圆

发表于 2006-4-2 18:32:39 | 显示全部楼层
能不能出个S64的呢?

出0入296汤圆

 楼主| 发表于 2006-4-3 23:38:33 | 显示全部楼层
其实原理大家看得都很明白了哈,自己做嘛

出0入0汤圆

发表于 2006-5-30 08:18:19 | 显示全部楼层
好人...谢谢.

出0入0汤圆

发表于 2007-10-5 10:10:05 | 显示全部楼层
好东西啊,正是我需要的,谢谢傻孩子!

出0入0汤圆

发表于 2008-3-17 16:29:47 | 显示全部楼层
能不能整个直接和位同时好操作的
如:       P1.DIR.BIT.B18 = 1;  //输出状态 ==P1.DIR.BYTE=(1<<18);

出0入0汤圆

发表于 2008-3-21 21:14:11 | 显示全部楼层
谢谢!

出0入0汤圆

发表于 2009-7-5 14:43:23 | 显示全部楼层
不够全

出0入0汤圆

发表于 2009-7-6 22:14:58 | 显示全部楼层
不知道这个代码测试过没有,
                “比方说,让P1.18变为低电平
                 只需要
                 DIR118 = 1;  //输出状态
                 P118 = 0;    //P1.18设为低电平”
中的P118 是映射到 IO1PIN寄存器,地址为:0xE0028010,这个是一个只读的吧,P118 = 0;行吗?有空我测一下试试

出0入0汤圆

发表于 2009-7-7 00:36:19 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-6-1 12:51:18 | 显示全部楼层
比较好

出0入0汤圆

发表于 2010-6-10 00:12:24 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-6-25 13:10:21 | 显示全部楼层
好东西 顶起来

出0入0汤圆

发表于 2010-8-18 10:48:07 | 显示全部楼层
位域好东西

出0入0汤圆

发表于 2010-10-29 21:32:58 | 显示全部楼层
IOxPIN是可读可写的,推荐用IOxSET、IOxCLR置1,置0。

出0入0汤圆

发表于 2010-11-1 21:34:30 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-11-29 10:16:15 | 显示全部楼层
位域滥用。。。

出0入9汤圆

发表于 2011-3-29 22:11:39 | 显示全部楼层
谢谢!

出0入296汤圆

 楼主| 发表于 2011-3-30 09:53:51 | 显示全部楼层
to 【17楼】 qqsdlpz
     对当时我一个大二的学生来说,不用又怎知滥呢……

出0入0汤圆

发表于 2011-10-15 19:02:34 | 显示全部楼层
MARK

出0入0汤圆

发表于 2011-11-27 08:51:14 | 显示全部楼层
mark!!!!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-1 05:58

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表