?? hc595drv.c
字號(hào):
/**************** (c) 2007 **********************************************************
COMPILER : C compiler
FILE : Hc595Drv.c
VERSION : 1.0
DATE : 2007/2/12
Author : flydragon
************************************************************************************/
#define LEFT_MOVE /* if define LEFT ,data from right move to left,else to right */
//#define POSITIVE /*驅(qū)動(dòng)二極管,共陽定義POSITIVE,否則為共陰*/
//#define DELAYTIME 0 /* delay NOP counters */
#include "hc595drv.h"
/******************************************************************************
Function: DelayTime
Description: Delay time
Arguments: time is delay clock counter
Returns: none
Notes: none
*******************************************************************************/
void DelayTime(void)
{
asm NOP
asm NOP
asm NOP
}
/****************************************************************************
Function: Hc595drv
Description:
Arguments: address is output data start address ;
bitcounter is move bit counters;
Returns: none
Notes:
******************************************************************************/
void Hc595drv(unsigned char*inaddress,unsigned char bitcounter)
{
unsigned char i,bit;
unsigned char bitcnt = 0;
unsigned char Data[2];
unsigned char *address;
Data[1] = * inaddress;
Data[0] = *(inaddress - 1);
address = &Data[1];
HC595_LCLK = 0;
HC595_OE = 1;
for(i=0;i<bitcounter;i++)
{
#ifdef LEFT_MOVE
bit = *(address) & 0x80;
*(address) = (*(address)) << 1;
#else
bit = *(address) & 0x01;
*(address) = (*(address)) >> 1;
#endif
HC595_CLK = 0;
if(bit != 0)
{
#ifdef POSITIVE
HC595_DATA = 0;
#else
HC595_DATA = 1;
#endif
}
else
{
#ifdef POSITIVE
HC595_DATA = 1;
#else
HC595_DATA = 0;
#endif
}
bitcnt ++;
if(bitcnt >= 8)
{bitcnt = 0;address--;}
HC595_CLK = 1;
}
HC595_DATA = 0;
HC595_LCLK = 1;
HC595_OE = 0;
}
/****************************************************************************
Function: Hc595drv
Description:
Arguments: address is output data start address ;
bitcounter is move bit counters;
Returns: none
Notes:
******************************************************************************/
void Hc595drv_B(unsigned char*inaddress,unsigned char bitcounter)
{
unsigned char i,bit;
unsigned char bitcnt = 0;
unsigned char Data[2];
unsigned char *address;
Data[1] = * inaddress;
Data[0] = *(inaddress - 1);
address = &Data[1];
HC595_LCLK = 0;
HC595_DATA = 1; //OE
for(i=0;i<bitcounter;i++)
{
#ifdef LEFT_MOVE
bit = *(address) & 0x80;
*(address) = (*(address)) << 1;
#else
bit = *(address) & 0x01;
*(address) = (*(address)) >> 1;
#endif
HC595_CLK = 0;
if(bit != 0)
{
#ifdef POSITIVE
HC595_OE = 0;
#else
HC595_OE = 1;
#endif
}
else
{
#ifdef POSITIVE
HC595_OE = 1;
#else
HC595_OE = 0; //DATA
#endif
}
bitcnt ++;
if(bitcnt >= 8)
{bitcnt = 0;address--;}
HC595_CLK = 1;
}
HC595_OE = 0; //DATA
HC595_LCLK = 1;
HC595_DATA = 0; //OE
}
/******2007/2/24*(c)* ******End of file***********************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -