|
|||||||||||
| 技術(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ī) |
/********************************************************************/ #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 于 2007/3/10 16:46:00 發(fā)布:
看錯(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 于 2007/3/10 22:26:00 發(fā)布:
程序改成如下即正確 /********************************************************************/ #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 |
|
|
|
| 免費(fèi)注冊(cè)為維庫(kù)電子開發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號(hào) |