Gorgon_Meducer 发表于 2006-5-12 10:43:47

[古董贴][测试]用于OurRobotV1的端口输出扩展模块(使用595)

#ifndef _USE_SERIAL_TO_PARALLEL_H_

#define _USE_SERIAL_TO_PARALLEL_H_

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

*函数库说明:595串行转并行函数库                         *

*版本:      v1.10                                       *

*作者:      傻孩子                                    *

*创建日期:2006年2月9日                              *

* -------------------------------------------------------- *

*[支持库]                                                *

*库名称:    RD_UseBits.h                              *

*需要版本:v1.00                                       *

*函数库说明:系统位段操作函数库                        *

*                                                          *

*库名称:    RD_MacroAndConst.h                        *

*需要版本:v0.01 &abv                                  *

*函数库说明:系统常用宏定义库                            *

* -------------------------------------------------------- *

*修改:      傻孩子                                    *

*修改日期:2006年5月4日                              *

*版本:      v1.10                                       *

* -------------------------------------------------------- *

*[版本历史]                                              *

*   v1.10以下提供三线扩展端口的基本函数。支持595硬件级连 *

*            的传输模式。                              *

*       v1.10使用统一的位段定义头文件。去除了原先无用的*

*            查询式刷新函数。增加了虚拟端口的多种映射方*

*            式,如位映射,半字节映射,字节映射,字映射*

*            并允许用户在外部自定义虚拟端口映射模式。    *

* -------------------------------------------------------- *

*[使用说明]                                              *

*         1、该头文件使用时需要额外的两个支持库的支持。*

*            详见前面的说明。                            *

*         2、引用该头文件之前需要通过定义VRCK、VSI、VSCK *

*            来描述硬件的连接端口。                      *

*         3、经过以上的说明以后,可以像普通端口一样使用*

*            虚拟端口。但是记住,端口是只写的。并且在您*

*            修改过端口值之后,您需要通过调用函数      *

*            refreshVirtualPORT()来刷新虚拟端口。或者通*

*            过宏定义REFRESH_PORT来实现同样功能。      *

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

# include <RD_UseBITs.h>

# include <RD_MacroAndConst.h>



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

*   系 统 宏 定 义*

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



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

*   常 数 宏 定 义*

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

#ifdef _USE_VPORT_BIT8

    # define VIRTUAL_BIT_COUNT    8

#else

    #ifdef _USE_VPORT_BIT16

                  # define VIRTUAL_BIT_COUNT    16

                #else

                  #ifdef _USE_VPORT_BIT32

                          # define VIRTUAL_BIT_COUNT    32

                        #endif

                          #ifndef _USE_VPORT_USER_DEFINE

                                # define VIRTUAL_BIT_COUNT    16

                                #endif

                        #endif

                #endif

#endif



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

*   全局变量声明区*

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

#ifndef _USE_VPORT_USER_DEFINE

#if VIRTUAL_BIT_COUNT == 8

    char PORTV = 0;

                # define PORTV_BIT   SET_BIT8_FORMAT(VPORT)

                # define PORTV_HBYTE SET_BYTE_DIV_2(VPORT)

#endif

#if VIRTUAL_BIT_COUNT == 16

    unsigned int VPORT = 0;

    # define PORTV_BIT   SET_BIT16_FORMAT(VPORT)

                # define PORTV_HBYTE SET_WORD_DIV_4(VPORT)

                # define PORTV_BYTESET_WORD_DIV_2(VPORT)

#endif

#if VIRTUAL_BIT_COUNT == 32

    unsigned long VPORT = 0;

                # define PORTV_BIT SET_BIT32_FORMAT(VPORT)

                # define PORTV_HBYTE SET_DWORD_DIV_8(VPORT)

                # define PORTV_BYTESET_DWORD_DIV_4(VPORT)

                # define PORTV_WORDSET_DWORD_DIV_2(VPORT)

#endif

#endif



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

*   动 作 宏 定 义*

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

# define REFRESH_PORT refreshVirtualPORT();



#ifndef _USE_VPORT_USER_DEFINE

#if VIRTUAL_BIT_COUNT >= 8

    # define PORTV_BIT.BIT0    _PV0

    # define PORTV_BIT.BIT1    _PV1

    # define PORTV_BIT.BIT2    _PV2

    # define PORTV_BIT.BIT3    _PV3

    # define PORTV_BIT.BIT4    _PV4

    # define PORTV_BIT.BIT5    _PV5

    # define PORTV_BIT.BIT6    _PV6

    # define PORTV_BIT.BIT7    _PV7

               

                # define PORTV_HBYTE.BYTEAL _PVAL

                # define PORTV_HBYTE.BYTEAH _PVAH

#endif

#if VIRTUAL_BIT_COUNT >= 16

    # define PORTV_BIT.BIT8    _PV8

                # define PORTV_BIT.BIT9    _PV9

                # define PORTV_BIT.BIT10   _PV10

                # define PORTV_BIT.BIT11   _PV11

                # define PORTV_BIT.BIT12   _PV12

                # define PORTV_BIT.BIT13   _PV13

                # define PORTV_BIT.BIT14   _PV14

                # define PORTV_BIT.BIT15   _PV15

               

                # define PORTV_HBYTE.BYTEBL _PVBL

                # define PORTV_HBYTE.BYTEBH _PVBH

               

                # define PORTV_BYTE.BYTEA   _PVA

                # define PORTV_BYTE.BYTEB   _PVB

               

#endif

#if VIRTUAL_BIT_COUNT == 32

    # define PORTV_BIT.BIT16   _PV16

                # define PORTV_BIT.BIT17   _PV17

                # define PORTV_BIT.BIT18   _PV18

                # define PORTV_BIT.BIT19   _PV19

                # define PORTV_BIT.BIT20   _PV20

                # define PORTV_BIT.BIT21   _PV21

                # define PORTV_BIT.BIT22   _PV22

                # define PORTV_BIT.BIT23   _PV23

               

                # define PORTV_BIT.BIT24   _PV24

                # define PORTV_BIT.BIT25   _PV25

                # define PORTV_BIT.BIT26   _PV26

                # define PORTV_BIT.BIT27   _PV27

                # define PORTV_BIT.BIT28   _PV28

                # define PORTV_BIT.BIT29   _PV29

                # define PORTV_BIT.BIT30   _PV30

                # define PORTV_BIT.BIT31   _PV31

               

                # define PORTV_HBYTE.BYTECL _PVCL

                # define PORTV_HBYTE.BYTECH _PVCH

                # define PORTV_HBYTE.BYTEDL _PVDL

                # define PORTV_HBYTE.BYTEDH _PVDH

               

                # define PORTV_BYTE.BYTEC_PVC

                # define PORTV_BYTE.BYTED_PVD

               

                # define PORTV_WORD.WORDA_PVWA

                # define PORTV_WORD.WORDB_PVWB

#endif



#endif



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

* 硬 件 连 接 定 义 *

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

#ifndef VRCK

    # define VRCK       _PB1

#endif

#ifndef VSCK

    # define VSCK       _PB2

#endif

#ifndef VSI

    # define VSI      _PB3

#endif



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

*   函 数 声 明 区*

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

void refreshVirtualPORT(void);

void sendBITS(char Data);



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

*函数说明:刷新虚拟端口函数                              *

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

void refreshVirtualPORT(void)

{

       char n = 0;

       char TempData = 0;

       

       VRCK = Low;

       for (n=0;n<(VIRTUAL_BIT_COUNT>>3);n++)

       {

      TempData = (VPORT<<(n<<3))>>(VIRTUAL_BIT_COUNT-8);

                  sendBITS(TempData);

       }

       VRCK = High;

}



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

*函数说明:发送串行数据函数                              *

*输入:    要发送的字节                                  *

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

void sendBITS(char Data)

{

    char n = 0;

       for (n = 0;n<8;n++)

       {

             VSCK = Low;

             if (((Data<<n) & 0x80)==0)

                  {

                        VSI = Low;

                  }

                  else

                  {

                        VSI = High;

                  }

                  VSCK = High;                                        //下降延锁存信号

       }

}

#endif

Gorgon_Meducer 发表于 2006-5-12 10:45:57

当您觉得OurRobotV1的驱动接口不够用的时候,您可以简单的自己用595搭建一块驱动板,然后用这个头文件来扩展出最多32个输出。应该够用了哈。什么不够?您难道想做火星车么?

milo112 发表于 2013-3-26 15:58:22

mark。。。
页: [1]
查看完整版本: [古董贴][测试]用于OurRobotV1的端口输出扩展模块(使用595)