|
#ifndef _hc595_165_h_
#define _hc595_165_h_
#define SETBIT(x,y) (x |= y)
#define CLRBIT(x,y) (x &= ~y)
#define CHKBIT(x,y) (x & y)
#define CPLBIT(x,y) (x ^= y)
#define DeSelect595 CLRBIT(HC595_165_PORT,HC595_165_595CS)
#define Select595 CLRBIT(HC595_165_PORT,HC595_165_595CS);SETBIT(HC595_165_PORT,HC595_165_595CS);CLRBIT(HC595_165_PORT,HC595_165_595CS)
#define Select165 SETBIT(HC595_165_PORT,HC595_165_165CS)
#define DeSelect165 CLRBIT(HC595_165_PORT,HC595_165_165CS)
#define HC595_165_SetClock SETBIT(HC595_165_PORT,HC595_165_Clock)
#define HC595_165_ClrClock CLRBIT(HC595_165_PORT,HC595_165_Clock)
#define SetMOSI_595 SETBIT(HC595_165_PORT,HC595_165_595DataOut)
#define ClrMOSI_595 CLRBIT(HC595_165_PORT,HC595_165_595DataOut)
/*
****************************************************************************************************
HC595_165接口初始化
****************************************************************************************************
*/
void HC595_165_Init(void)
{
SETBIT(HC595_165_DDR,HC595_165_Clock);
#ifdef Per_HC595
SETBIT(HC595_165_DDR,HC595_165_595CS);
SETBIT(HC595_165_DDR,HC595_165_595DataOut);
DeSelect595;
#endif
#ifdef Per_HC165
SETBIT(HC595_165_DDR,HC595_165_165CS);
CLRBIT(HC595_165_DDR,HC595_165_165DataIn);
DeSelect165;
#endif
HC595_165_SetClock;
}
/*
****************************************************************************************************
从165读取1字节数据
****************************************************************************************************
*/
#ifdef Per_HC165
uint8 HC595_165_Read165Byte(void)
{
uint8 i,j,indata;
indata=0;
for(i=0;i<8;i++)
{
if(CHKBIT(HC595_165_PIN,HC595_165_165DataIn)) indata|=(0x80>>i);
HC595_165_ClrClock;
for(j=0;j<=10;j++);
HC595_165_SetClock;
}
return indata;
}
#endif
/*
****************************************************************************************************
向595写1字节数据
****************************************************************************************************
*/
#ifdef Per_HC595
void HC595_165_Write595Byte(uint8 u8_OutData)
{
uint8 i,j;
for(i=0;i<8;i++)
{
if(CHKBIT(u8_OutData,0x80>>i))
{
SetMOSI_595;
}
else
{
ClrMOSI_595;
}
HC595_165_ClrClock;
for(j=0;j<=10;j++);
HC595_165_SetClock;
for(j=0;j<=10;j++);
}
HC595_165_ClrClock;
}
#endif
#endif
疑问:1、#define SETBIT(x,y) (x |= y)
#define CLRBIT(x,y) (x &= ~y)
#define CHKBIT(x,y) (x & y)
#define CPLBIT(x,y) (x ^= y)
我觉得应该改为:
#define SETBIT(x,y) (x |= (1<<y))
#define CLRBIT(x,y) (x &= ~(1<<y))
#define CHKBIT(x,y) (x & (1<<y))
#define CPLBIT(x,y) (x ^= (1<<y))
但那样写的操作结果好像和下面的写法操作结果一样,大家都在使用这个文件,也没发现什么问题,想不通???
2、595,165的操作中使用了过多的宏,看起来意思很不明朗(我是这么认为的),大家怎么看啊??
对齐的不是很好,大家凑合着看吧
大家有什么好的操作595的方法也可以晒晒啊,谢谢了 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|