音影先锋亚洲天堂网|电影世界尽头的爱完整版播放|国产 熟女 91|高清无码免费观看欧美日韩|韩国一区二区三区黄色录像|美女亚洲加勒比在线|亚洲综合网 开心五月|7x成人在线入口|成人网站免费日韩毛片区|国产黄片?一级?二级?三级

登錄 免費(fèi)注冊(cè) 首頁(yè) | 行業(yè)黑名單 | 幫助
維庫(kù)電子市場(chǎng)網(wǎng)
技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測(cè)控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng)
驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe

ds1307 的程序錯(cuò)在那

作者:CHUANDAOXY 欄目:單片機(jī)
DS1307.html">DS1307 的程序錯(cuò)在那
    /********************************************************************/
#include <REG51.H>         /* Prototypes for I/O functions       */
#include <STDIO.H>        /* Register declarations for DS5000   */
/***************************** Defines *****************************/
#define    ACK    0
#define    NACK    1
#define    ADDRTC    0xd0    /* I2C slave address */
#define    DS1307    /* compile directive, modify as required */
#define uCHAR unsigned CHAR
/************************* bit definitions *************************/
sbit scl = P0^0;            /* I2C pin definitions */
sbit sda = P0^1;
sbit sqw = P3^2;        /* pin function depends upon DEVICE */

/* GLOBAL variables */
uCHAR    sec, min, hr, dy, dt, mn, yr;

/* General Notes: Define one DEVICE to compile options for that DEVICE. */
/* Will not compile correctly if no DEVICE is defined.  Not all options */
/* for each DEVICE are supPORTed.  There is no error checking for data  */
/* entry.  Defines may not remove all code that is not relevant to the  */
/* DEVICE. This example was written for an 8051-type MICRO, the DS2250/ */
/* DS5000.  The program must be MODIFIED to work properly on typical    */
/* 8051 variants (i.e. assign I2C bus to unused PORT pins).  This       */
/* program is for example ONLY and is not supPORTed by DALLAS MAXIM     */

void    I2C_start();
void    I2C_stop();
void    I2C_write(unsigned CHAR d);
void    I2C_read(uCHAR);
void    readbyte();
void    writebyte();
void    initialize();
void    disp_clk_regs(uCHAR);
void    burstramwrite(uCHAR);
void    burstramread();
void    alrm_int();
void    alrm_read();
void    tc_setup();

void I2C_start()    /* ----------------------------------------------- */
{
    sda = 1;  scl = 1;    /* Initiate start condition */
    sda = 0;
}



void I2C_stop()        /* ----------------------------------------------- */
{
    sda = 0; sda = 0; sda = 0; sda = 0;    /* Initiate stop condition */
    scl = 1; scl = 1; sda = 1;
}



void I2C_write(uCHAR d)        /* ----------------------------- */
{
uCHAR i;

    scl = 0;
    for (i = 1; i <= 8; i++)
    {
        sda = (d >> 7);
        scl = 1;
        d = d << 1;    /* increase scl high time */
        scl = 0;
    }
    sda = 1;    /* Release the sda LINE */
    scl = 0;
    scl = 1;
    if(sda) printf("Ack bit missing  %02X",(unsigned int)d);
    scl = 0;
}


void I2C_read(uCHAR b)    /* ----------------------------------- */
{
uCHAR b, i;

    sda = 1;             /* Let go of sda LINE */
    scl = 0;
    for (i = 1; i <= 8; i++)    /* read the msb first */
    {
        scl = 1;
        b = b<< 1;
        b = b| (unsigned CHAR)sda;
        scl = 0;
    }
    sda = b;          /* Hold sda low for acknowledge */

    scl = 0;
    scl = 1;
    if(b == NACK)    sda = 1;    /* sda = 1 if next cycle is reset */
    scl = 0;

    sda = 1;          /* Release the sda LINE */
    return b;
}



void readbyte()    /* -- read one byte of data from the specified address -- */
{
uCHAR Add;
    printf("ADDRESS: ");    /* Get Address */
    scanf("%bx", &Add);
    I2C_start();
    I2C_write(ADDRTC);
    I2C_write(Add);
    I2C_start();
    I2C_write(ADDRTC | 1);
    printf("%2bx", I2C_read(NACK) );
    I2C_stop();
}
void writebyte()    /* -- write one byte of data to the specified address -- */
{
uCHAR Add;
uCHAR Data;
    printf("Address: ");    /* Get Address */
    scanf("%bx", &Add);
    printf("DATA: ");
    scanf("%bx", &Data);    /* and data */
    I2C_start();
    I2C_write(ADDRTC);
    I2C_write(Add);
    I2C_write(Data);
    I2C_stop();
}
void initialize()    /* -- initialize the time and date using entries from stdin -- */
/* Note: NO error checking is done on the user entries! */
{
uCHAR    yr, mn, dt, dy, hr, min, sec, day;

    I2C_start();        /* The following Enables the Oscillator */
    I2C_write(ADDRTC);    /* address the PART to write */
    I2C_write(0x00);    /* position the address pointer to 0 */
    I2C_write(0x00);    /* write 0 to the seconds register, clear the CH bit */
    I2C_stop();

    printf("Enter the year (0-99): ");
    scanf("%bx", &yr);
    printf("Enter the month (1-12): ");
    scanf("%bx", &mn);
    printf("Enter the date (1-31): ");
    scanf("%bx", &dt);
    printf("Enter the day (1-7): ");
    scanf("%bx", &dy);
   
2樓: >>參與討論
bc107
看錯(cuò)誤類型
TEXT1.C(79): error C231: 'b': redefinition
TEXT1.C(113): error C193: 'parameter': bad operand type
TEXT1.C(281): error C193: 'parameter': bad operand type
TEXT1.C(420): error C193: 'parameter': bad operand type

好像是 b 重復(fù)定義了
而且你定義的一個(gè) 參數(shù)  類型好像不對(duì)

那么長(zhǎng) 不能具體看,先看看 提示錯(cuò)誤的原因


3樓: >>參與討論
turmary
程序改成如下即正確
/********************************************************************/
#include <REG51.H>         /* Prototypes for I/O functions       */
#include <STDIO.H>        /* Register declarations for DS5000   */
/***************************** Defines *****************************/

#define    ACK    0
#define    NACK    1
#define    ADDRTC    0xd0    /* I2C slave address */
#define    DS1307    /* compile directive, modify as required */
#define uCHAR unsigned CHAR
/************************* bit definitions *************************/

sbit scl = P0^0;            /* I2C pin definitions */
sbit sda = P0^1;
sbit sqw = P3^2;        /* pin function depends upon DEVICE */

/* GLOBAL variables */
uCHAR    sec, min, hr, dy, dt, mn, yr;

/* General Notes: Define one DEVICE to compile options for that DEVICE. */
/* Will not compile correctly if no DEVICE is defined.  Not all options */
/* for each DEVICE are supPORTed.  There is no error checking for data  */
/* entry.  Defines may not remove all code that is not relevant to the  */
/* DEVICE. This example was written for an 8051-type MICRO, the DS2250/ */
/* DS5000.  The program must be MODIFIED to work properly on typical    */
/* 8051 variants (i.e. assign I2C bus to unused PORT pins).  This       */
/* program is for example ONLY and is not supPORTed by DALLAS MAXIM     */

void    I2C_start();
void    I2C_stop();
void    I2C_write(unsigned CHAR d);
uCHAR    I2C_read(uCHAR);
void    readbyte();
void    writebyte();
void    initialize();
void    disp_clk_regs(uCHAR);
void    burstramwrite(uCHAR);
void    burstramread();
void    alrm_int();
void    alrm_read();
void    tc_setup();

void I2C_start()    /* ----------------------------------------------- */
{
    sda = 1;  scl = 1;    /* Initiate start condition */
    sda = 0;
}



void I2C_stop()        /* ----------------------------------------------- */
{
    sda = 0; sda = 0; sda = 0; sda = 0;    /* Initiate stop condition */
    scl = 1; scl = 1; sda = 1;
}



void I2C_write(uCHAR d)        /* ----------------------------- */
{
uCHAR i;

    scl = 0;
    for (i = 1; i <= 8; i++)
    {
        sda = (d >> 7);
        scl = 1;
        d = d << 1;    /* increase scl high time */
        scl = 0;
    }
    sda = 1;    /* Release the sda LINE */
    scl = 0;
    scl = 1;
    if(sda) printf("Ack bit missing  %02X",(unsigned int)d);
    scl = 0;
}


uCHAR I2C_read(uCHAR b)    /* ----------------------------------- */
{
    uCHAR i;

    sda = 1;             /* Let go of sda LINE */
    scl = 0;
    for (i = 1; i <= 8; i++)    /* read the msb first */
    {
        scl = 1;
        b = b<< 1;
        b = b| (unsigned CHAR)sda;
        scl = 0;
    }
    sda = b;          /* Hold sda low for acknowledge */

    scl = 0;
    scl = 1;
    if(b == NACK)    sda = 1;    /* sda = 1 if next cycle is reset */
    scl = 0;

    sda = 1;          /* Release the sda LINE */
    return b;
}



void readbyte()    /* -- read one byte of data from the specified address -- */
{
uCHAR Add;
    printf("ADDRESS: ");    /* Get Address */
    scanf("%bx", &Add);
    I2C_start();
    I2C_write(ADDRTC);
    I2C_write(Add);
    I2C_start();
    I2C_write(ADDRTC | 1);
    printf("%2bx", I2C_read(NACK) );
    I2C_stop();
}
void writebyte()    /* -- write one byte of data to the specified address -- */
{
uCHAR Add;
uCHAR Data;
    printf("Address: ");    /* Get Address */
    scanf("%bx", &Add);
    printf("DATA: ");
    scanf("%bx", &Data);    /* and data */
    I2C_start();
    I2C_write(ADDRTC);
    I2C_write(Add);
    I2C_write(Data);
    I2C_stop();
}
void initialize()    /* -- initialize the time and date using entries from stdin -- */
/* Note: NO error checking is done on the user entries! */
{
uCHAR    yr, mn, dt, dy, hr, min, sec;

    I2C_start();        /* The following Enables the Oscillator */
    I2C_write(ADDRTC);    /* address the PART to write */
    I2C_write(0x00);    /* position the address pointer to 0 */
    I2C_write(0x00);    /* write 0 to the seconds register, clear the CH bit */
    I2C_stop();

    printf("Enter the year (0-99): ");
    scanf("%bx", &yr);
    printf("Enter the month (1-12): ");
    scanf("%bx", &mn);
    printf("Enter the date (1-31): ");
    scanf("%bx", &dt);
    printf("Enter the day (1-7): ");
    scanf("%bx", &dy);
  &nbs
參與討論
昵稱:
討論內(nèi)容:
 
 
相關(guān)帖子
還有一個(gè)問(wèn)題求助,關(guān)于時(shí)鐘芯片
請(qǐng)教一個(gè)多普勒效應(yīng)的問(wèn)題
轉(zhuǎn)換器
請(qǐng)教自動(dòng)升窗器的玻璃到位檢測(cè)問(wèn)題
我該選擇哪種總線控制
免費(fèi)注冊(cè)為維庫(kù)電子開發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入


Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號(hào)