打印

DSA

[复制链接]
1732|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tomitomi|  楼主 | 2007-8-27 09:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
 bit time_over_flag;

unsigned char xdata dsa_time;

unsigned int DSA_read(void);
unsigned char DSA_write(unsigned char command,unsigned char parameter);

unsigned int DSA_read(void)
{
    unsigned int idata i = 0x0000;
    unsigned char idata j;

    DSA_CLK = 0;
    time_over_flag= 0;

    dsa_time = DSATIME;
    while((!DSA_DATA) && (!time_over_flag));        //wait data_dsa be high
    if(time_over_flag) goto read_exit;
    DSA_CLK = 1;

    for(j = 0; j < 16; j ++) {
        dsa_time = DSATIME;
        while(DSA_STB && (!time_over_flag));        //wait stb_dsa be low
        if(time_over_flag) goto read_exit;

        i *= 2;
        if(DSA_DATA) i++;

        DSA_CLK = 0;                        //get this bit

        dsa_time = DSATIME;
        while((!DSA_STB) && (!time_over_flag));    //wait stb_dsa be high
        if(time_over_flag) goto read_exit;

        DSA_CLK = 1;
    }

    dsa_time = DSATIME;
    while(DSA_CLK && (!time_over_flag));            //wait ack_dsa be low
    if(time_over_flag) goto read_exit;

    DSA_DATA = 1;                        //pull up data_dsa
    DSA_STB = 0;                            //pull down stb_dsa

    dsa_time = DSATIME;
    while((!DSA_CLK) && (!time_over_flag));        //wait ack_dsa be high
    if(time_over_flag) goto read_exit;

    DSA_STB = 1;                            //pull up stb_dsa
    return(i);

read_exit:
    DSA_DATA = 1;
    DSA_STB = 1;
    DSA_CLK = 1;
    return(0xaa);
}

unsigned char DSA_write(unsigned char command,unsigned char parameter)
{
    unsigned int i = command * 256 + parameter;
    unsigned char j;

    DSA_DATA = 0;
    time_over_flag = 0;

    dsa_time = DSATIME;
    while(DSA_CLK && (!time_over_flag));        //wait ack_dsa be low
    if(time_over_flag) goto write_exit;

    DSA_DATA = 1;

    dsa_time = DSATIME;
    while((!DSA_CLK) && (!time_over_flag));        //wait ack_dsa be high
    if(time_over_flag) goto write_exit;

    for(j = 0; j < 16; j ++) {
        DSA_DATA = (bit)(i & 0x8000);
        i <<= 1;
        DSA_STB = 0;

        dsa_time = DSATIME;
        while(DSA_CLK && (!time_over_flag));        //wait ack_dsa be low
        if(time_over_flag) goto write_exit;

        DSA_STB = 1;                        //pull up stb_dsa

        dsa_time = DSATIME;
        while((!DSA_CLK) && (!time_over_flag));    //wait ack_dsa be high
        if(time_over_flag) goto write_exit;
    }
    DSA_DATA = 1;
    DSA_CLK = 0;                            //pull down ack_dsa

    dsa_time = DSATIME;
    while(DSA_STB && (!time_over_flag));            //wait stb_dsa be low
    if(time_over_flag) goto write_exit;

    DSA_CLK = 1;                            //pull up ack_dsa

    dsa_time = DSATIME;
    while((!DSA_STB) && (!time_over_flag));        //wait stb_dsa be high
    if(time_over_flag) goto write_exit;

    return(0x01);

write_exit:
    DSA_DATA = 1;
    DSA_STB = 1;
    DSA_CLK = 1;
    return(0xaa);
}
//Check the DSA
    if(dsa_time)
        {
        dsa_time --;
        if(!dsa_time)
            time_over_flag = 1;
        }

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

17

帖子

0

粉丝