Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10592
  • 博文数量: 8
  • 博客积分: 320
  • 博客等级: 一等列兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-06 09:19
文章分类
文章存档

2011年(1)

2009年(7)

我的朋友
最近访客

分类: C/C++

2009-08-06 18:41:07

#define uchar unsigned char
#define uint unsigned int
#define SET_BIT(io,bit) ( io |= (1<#define CLR_BIT(io,bit) ( io &= ~(1<#define NOT_BIT(io ,bit) (io ^=   (1<#define GET_BIT(io ,bit) ( (io & (1<>bit ) //example: GET_BIT
int Led_Shift=0;

void Delayus(uint US)
{
    uint i;
    US=US*5/4;            //5/4是在8MHz晶振下,通过软件仿真反复实验得到的数值
    for ( i=0;i}

//精确定义毫秒
void Delayms(uint MS)
{
    uint i,j;
    for ( i=0;i        for (j=0;j<1141;j++);   //1141是在8MHz晶振下,通过软件仿真反复实验得到的数值
}

//定义函数,设置寄存器某一位的值,返回修改后的寄存器的值
uchar Set_Value(uchar Byte_Data,uchar Bit_Num,uchar Value)
{

    if (Value==1)
    {
        SET_BIT(Byte_Data,Bit_Num);
    }

    if (Value==0)
    {
        CLR_BIT(Byte_Data,Bit_Num);
    }
    return Byte_Data;
}

uint DtRisePulse(volatile uchar *ByteVal,unsigned char BitVal,unsigned char *exitflag)//检测某字节某位0-1的变化,第一个参数为地址类型
{
char tmp;
//while ((tmp=GET_BIT(*ByteVal,BitVal))==1)
//{if (*exitflag==1) return 0;}

while ((tmp=GET_BIT(*ByteVal,BitVal))==0)
{if (*exitflag==1) return 0;}

return 1;
}

uint DtDownPulse(volatile uchar *ByteVal,unsigned char BitVal,unsigned char *exitflag)//检测某字节某位1-0的变化,第一个参数为地址类型
{
char tmp;
//while ((tmp=GET_BIT(*ByteVal,BitVal))==0)
//{if (*exitflag==1) return 0;}

while ((tmp=GET_BIT(*ByteVal,BitVal))==1)
{if (*exitflag==1) return 0;}

return 1;
}

阅读(486) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~