درود . چون I2C هست ميتونيد راحت اين كد رو تبديل به بسكام كنيد . سخت افزارش هم چیزی نداره و من همونی که توی کاتالوگش هست رو بستم و راحت کار میکرد . سورس سی :
/* CodeVisionAVR C Compiler (C) 1998-2005 Pavel Haiduc, HP InfoTech S.R.L.
Dallas Semiconductors DS1307 I2C Bus Real Time Clock functions */
#include <i2c.h> #include <bcd.h>
unsigned char rtc_read(unsigned char address) { unsigned char data; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_start(); i2c_write(0xd1); data=i2c_read(0); i2c_stop(); return data; }
void rtc_write(unsigned char address,unsigned char data) { i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_write(data); i2c_stop(); }
void rtc_init(unsigned char rs,unsigned char sqwe,unsigned char out) { rs&=3; if (sqwe) rs|=0x10; if (out) rs|=0x80; i2c_start(); i2c_write(0xd0); i2c_write(7); i2c_write(rs); i2c_stop(); }
void rtc_get_time(unsigned char *hour,unsigned char *min,unsigned char *sec) { i2c_start(); i2c_write(0xd0); i2c_write(0); i2c_start(); i2c_write(0xd1); *sec=bcd2bin(i2c_read(1)); *min=bcd2bin(i2c_read(1)); *hour=bcd2bin(i2c_read(0)); i2c_stop(); }
void rtc_set_time(unsigned char hour,unsigned char min,unsigned char sec) { i2c_start(); i2c_write(0xd0); i2c_write(0); i2c_write(bin2bcd(sec)); i2c_write(bin2bcd(min)); i2c_write(bin2bcd(hour)); i2c_stop(); }
void rtc_get_date(unsigned char *date,unsigned char *month,unsigned char *year) { i2c_start(); i2c_write(0xd0); i2c_write(4); i2c_start(); i2c_write(0xd1); *date=bcd2bin(i2c_read(1)); *month=bcd2bin(i2c_read(1)); *year=bcd2bin(i2c_read(0)); i2c_stop(); }
void rtc_set_date(unsigned char date,unsigned char month,unsigned char year) { i2c_start(); i2c_write(0xd0); i2c_write(4); i2c_write(bin2bcd(date)); i2c_write(bin2bcd(month)); i2c_write(bin2bcd(year)); i2c_stop(); }
_______________________________________________________________________ پروژه های حرفه ای الکترونیک و کامپیوتر در www.khazama.com
مجموعه متن باز نامهای اصیل ایرانی
وبلاگ نوشته های شخصی من
|