![]() |
![]() |
#1 |
Đệ tử 6 túi
Tham gia ngày: Jul 2007
Bài gửi: 154
: |
đồng hồ đếm thời gian thực
bác nào đã làm đồng hồ đếm thời gian thực bằng pic chỉ cho tôi với. để đếm được thời gian thực thì cần giao tiếp pic với ic đếm thời gian thực. thế đó là con ic gì hả các bác.
|
![]() |
![]() |
![]() |
#2 | |
Trưởng lão PIC bang
|
Trích:
"real time clock site:www.picvietnam.com" hoặc "đồng hồ thời gian thực site:www.picvietnam.com" Có nhiều vi mạch loại này đã được đề cập ở PIC Vietnam. Thân,
__________________
Biển học mênh mông, sức người có hạn. Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau: http://www.picvietnam.com/forum/showthread.php?t=1263 |
|
![]() |
![]() |
![]() |
#3 |
Đệ tử 2 túi
Tham gia ngày: Dec 2006
Nơi Cư Ngụ: HN
Bài gửi: 39
: |
Em thấy thông dụng ds1307, ds12887 và các anh em liên quan
![]() Dùng PIC không cần RTC khác cũng được, miễn là thạch anh cho PIC ngon ![]() |
![]() |
![]() |
![]() |
#4 |
Nhập môn đệ tử
Tham gia ngày: Mar 2009
Bài gửi: 3
: |
em đang làm đồng hồ báo thức bằng pic6f877a.hien thi ra led 7 doan .su huynh nào đã làm rùi thì giúp đỡ đệ đệ zoi.nếu có sơ đồ nguyên lí va code thì còn gì bằng.MONG CÁC SƯ HUYNH GIÚP ĐỠ.
|
![]() |
![]() |
![]() |
#5 |
Đệ tử 6 túi
Tham gia ngày: Jul 2007
Bài gửi: 154
: |
ds1037
cái này minh chưa làm mạch thật nhưng chạy mô phỏng tốt. bạn xem tạm nhé
#include<16F877a.h> #fuses NOLVP,NOWDT,PUT,hs,NOPROTECT,NOBROWNOUT #device 16F877a*=16 ADC=10 #include <math.h> #use delay(clock=20000000) //#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #use fast_io(a) #byte porta=0x05 #use fast_io(b) #byte portb=0x06 #use fast_io(c) #byte portc=0x07 #use fast_io(d) #byte portd=0x08 #use fast_io(e) #byte porte=0x09 #define RTC_SCL PIN_B0 #define RTC_SDA PIN_B1 #bit RS = portA.0 #bit RW = portA.1 #bit E = portA.2 //#define RTC_RST PIN_B2 #use i2c(master, fast, sda=RTC_SDA, scl=RTC_SCL) //================================================ int sec,min,hour,date,month,year,a,b; unsigned char so[] = "0123456789"; // unsigned int led[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80}; void write_RTC(int add, BYTE data) { short int status; i2c_start(); // bao hieu bat dau giao tiep i2c i2c_write(0xd0); // dia chi thiet bi nhan i2c_write(add); // dia chi thanh ghi i2c_write(data); //gui data vao dia chi thanh ghi cua thiet bi nhan i2c_stop(); // bao hieu ngung ghi i2c_start(); // bao hieu bat dau giao tiep status=i2c_write(0xd0); // kiem tra trang thai cua thiet bi nhan while(status==1) // lap lai cho den khi thiet bi da nhan xong (No Ack) { i2c_start(); status=i2c_write(0xd0); } delay_us(10); } BYTE read_RTC(int add) { BYTE data; i2c_start(); i2c_write(0xd0); i2c_write(add); i2c_start(); i2c_write(0xd1); data=i2c_read(0); // No Ack i2c_stop(); delay_ms(10); return(data); } void init_RTC() // ham khoi tao eeprom { i2c_start(); // bao hieu bat dau giao tiep i2c i2c_write(0xd0); // dia chi thiet bi nhan i2c_write(0x00); // enable RTC i2c_write(0x01);// sec // dia chi thanh ghi i2c_write(0x00);// min //gui data vao dia chi thanh ghi cua thiet bi nhan i2c_write(0x08);// hur i2c_write(0x04);//day i2c_write(0x11);// date i2c_write(0x02);// month i2c_write(0x09);// year i2c_stop(); // bao hieu ngung ghi i2c_start(); // bao hieu bat dau giao tiep } int rm_bcd(BYTE data) // CHUYEN BCD SANG SO NGUYEN { int i; i=data; data=(i>>4)*10; data=data+(i<<4>>4); return data; } //////////////////////////////////////////////////////////// /*Ham yeu cau goi lenh dieu khien LCD*/ void command() { RS = 0; RW = 0; E = 1; E = 0; delay_ms(1); } /*Ham yeu cau goi du lieu hien thi len LCD*/ void display() { RS = 1; RW = 0; E = 1; E = 0; delay_ms(1); } void main() { set_tris_b(0); set_tris_a(0); set_tris_c(0); set_tris_e(0); set_tris_d(0); init_RTC(); while(true) {//write_RTC(addsec,0); // sec = read_RTC(addsec); // doc thoi gian tu RTC // min = read_RTC(addmin); // hour = read_RTC(addhour); portd = 0x38; // Hai hang, ma tran dot 5*7, 8 bit interface command(); portd = 0x0C; // Bat hien thi, tat con tro command(); ////////////////////////////////////////////////// hour = rm_bcd(read_RTC(0x02)); min = rm_bcd(read_RTC(0x01)); sec = rm_bcd(read_RTC(0x00)); date = rm_bcd(read_RTC(0x04)); month = rm_bcd(read_RTC(0x05)); year = rm_bcd(read_RTC(0x06)); ////////////////////////////////////////////////////////////////// a = sec/10; b = sec-a*10; portd = 0x8b; command(); portd = so[a]; display(); portd = 0x8c; command(); portd = so[b]; display(); portd = 0x8a; command(); portd = ':'; display(); ///// hien thi min len LCD //////// a = min/10; b = min-a*10; portd = 0x88; command(); portd = so[a]; display(); portd = 0x89; command(); portd = so[b]; display(); portd = 0x87; command(); portd = ':'; display(); ///// hien thi sec len LCD //////// a = hour/10; b = hour-a*10; portd = 0x85; command(); portd = so[a]; display(); portd = 0x86; command(); portd = so[b]; display(); /////////////////////////////////// a = year/10; b = year-a*10; portd = 0xcb; command(); portd = so[a]; display(); portd = 0xcc; command(); portd = so[b]; display(); portd = 0xca; command(); portd = '-'; display(); ///// hien thi min len LCD //////// a = month/10; b = month-a*10; portd = 0xc8; command(); portd = so[a]; display(); portd = 0xc9; command(); portd = so[b]; display(); portd = 0xc7; command(); portd = '-'; display(); ///// hien thi sec len LCD //////// a = date/10; b = date-a*10; portd = 0xc5; command(); portd = so[a]; display(); portd = 0xc6; command(); portd = so[b]; display(); } } |
![]() |
![]() |
![]() |
#6 |
Nhập môn đệ tử
Tham gia ngày: Mar 2009
Bài gửi: 3
: |
em cảm ơn anh nhiều lắm.nhưng anh oi.không co nút nhấn và loa làm sao báo thức và chỉnh giờ.nếu được thì anh giúp em với.sắp tới ngày nộp đồ án rùi mà em suy nghĩ hoài mà viết code hok được.mong anh chi bảo thêm.
|
![]() |
![]() |
![]() |
#7 |
Nhập môn đệ tử
Tham gia ngày: May 2010
Bài gửi: 3
: |
em đang làm đồ án đồng hồ lịch vạn niên dùng pic6F877A hiển thị led 7seg nhưng viết code gặp vấn đề mô pổng không đọc được ds1307 mong các cao thủ về pic chỉ bảo em với. em cần rất gấp xin cảm ơn trước. đây là đoạn code của em.
(dùng led catot chung phương pháp quét led dung npn). #include <16F877A.h> #include <def_877a.h> #fuses NOPROTECT,HS,NOWDT,NOLVP,NODEBUG,NOPUT #use delay(clock =20000000) #use i2c(master,fast,sda=PIN_C4,scl=PIN_C3) unsigned char sec,min,hour,day,date,month,year,set,luu; unsigned char day1,day2,month1,month2,year1,year2,hour1,hour2,mi n1,min2,sec1,sec2; int led[10]={0b00111111,0b00000110,0b01011011,0b01001111,0b01 100110,0b01101101,0b01111101,0b00000111,0b01111111 ,0b01101111}; void khoi_tao() { SET_TRIS_B(0x00); //SET_TRIS_C(0x00); SET_TRIS_D(0x00); } void set_DS1307() { I2C_Start(); I2C_Write(0xD0); I2C_Write(0x00); I2C_Write(0x00); I2C_Write(0x00); I2C_Write(0x07); I2C_Write(0x12); I2C_Write(0x06); I2C_Write(0x19); I2C_Write(0x07); I2C_Write(0x08); I2C_Write(0x90); I2C_Write(0x55); I2C_Stop(); } void READ_DS() { I2C_Start(); I2C_Write(0xD0); I2C_Write(0x00); I2C_Start(); I2C_Write(0xD1); sec = I2C_Read(1); min = I2C_Read(1); hour = I2C_Read(1); day = I2C_Read(1); date = I2C_Read(1); month = I2C_Read(1); year = I2C_Read(1); set = I2C_Read(1); luu = I2C_Read(0); I2C_Stop(); } void XULY_DS() { sec1 = sec & 0x0F; sec2 = (sec & 0xF0)>>4; min1 = min & 0x0F; min2 = (min & 0xF0)>>4; hour1 = hour & 0x0F; hour2 = (hour & 0xF0)>>4; date = date & 0x0F; day1 = day & 0x0F ; day2 = (day & 0xF0)>>4; month1 = month & 0x0F ; month2 = (month & 0xF0)>>4; year1 = year & 0x0F ; year2 = (year & 0xF0)>>4; } void Dislays() { PORTD = led[sec1] ;Pin_C0==1 ; delay_ms(850); Pin_C6==0 ; PORTD = led[sec2] ;Pin_C5==1 ; delay_ms(850); Pin_C5==0 ; PORTD = led[min1] ;Pin_C2==1 ; delay_ms(850); Pin_C2==0 ; PORTD = led[min2] ;Pin_C1==1 ; delay_ms(850); Pin_C1==0 ; PORTD = led[hour1] ;Pin_B7==1 ; delay_ms(850); Pin_B7==0 ; PORTD = led[hour2] ;Pin_B0==1 ; delay_ms(850); Pin_B0==0 ; PORTD = led[date] ;Pin_B2==1 ; delay_ms(850); Pin_B2==0 ; PORTD = led[day1] ;Pin_B1==1 ; delay_ms(850); Pin_B1==0 ; PORTD = led[day2] ;Pin_B4==1 ; delay_ms(850); Pin_B4==0 ; PORTD = led[month1];Pin_B3==1 ; delay_ms(850); Pin_B3==0 ; PORTD = led[month2];Pin_B6==1 ; delay_ms(850); Pin_B6==0 ; PORTD = led[year1] ;Pin_B5==1 ; delay_ms(850); Pin_B5==0 ; } void main() { set_DS1307(); READ_DS(); XULY_DS(); khoi_tao(); while(1) { Dislays(); } } |
![]() |
![]() |
![]() |
#8 |
Nhập môn đệ tử
Tham gia ngày: Dec 2009
Bài gửi: 1
: |
các bác, cho em hỏi câu với
làm sao để tính chính xác thời gian delay ví dụ delay_ms(1000); khi mô phỏng thì nó không trễ đúng 1s thì sửa bằng cách nào ạ? |
![]() |
![]() |
![]() |
#9 |
Đệ tử 7 túi
Tham gia ngày: May 2005
Bài gửi: 258
: |
[quote=thanhliem20;36722]em đang làm đồ án đồng hồ lịch vạn niên dùng pic6F877A hiển thị led 7seg nhưng viết code gặp vấn đề mô pổng không đọc được ds1307 mong các cao thủ về pic chỉ bảo em với. em cần rất gấp xin cảm ơn trước. đây là đoạn code của em.
(dùng led catot chung phương pháp quét led dung npn). #include <16F877A.h> #include <def_877a.h> #fuses NOPROTECT,HS,NOWDT,NOLVP,NODEBUG,NOPUT #use delay(clock =20000000) #use i2c(master,fast,sda=PIN_C4,scl=PIN_C3) unsigned char sec,min,hour,day,date,month,year,set,luu; unsigned char day1,day2,month1,month2,year1,year2,hour1,hour2,mi n1,min2,sec1,sec2; int led[10]={0b00111111,0b00000110,0b01011011,0b01001111,0b01 100110,0b01101101,0b01111101,0b00000111,0b01111111 ,0b01101111}; void khoi_tao() { SET_TRIS_B(0x00); //SET_TRIS_C(0x00); SET_TRIS_D(0x00); } void set_DS1307() { I2C_Start(); I2C_Write(0xD0); I2C_Write(0x00); I2C_Write(0x00); I2C_Write(0x00); I2C_Write(0x07); I2C_Write(0x12); I2C_Write(0x06); I2C_Write(0x19); I2C_Write(0x07); I2C_Write(0x08); I2C_Write(0x90); I2C_Write(0x55); I2C_Stop(); } void READ_DS() { I2C_Start(); I2C_Write(0xD0); I2C_Write(0x00); I2C_Start(); I2C_Write(0xD1); sec = I2C_Read(1); min = I2C_Read(1); hour = I2C_Read(1); day = I2C_Read(1); date = I2C_Read(1); month = I2C_Read(1); year = I2C_Read(1); set = I2C_Read(1); luu = I2C_Read(0); I2C_Stop(); } void XULY_DS() { sec1 = sec & 0x0F; sec2 = (sec & 0xF0)>>4; min1 = min & 0x0F; min2 = (min & 0xF0)>>4; hour1 = hour & 0x0F; hour2 = (hour & 0xF0)>>4; date = date & 0x0F; day1 = day & 0x0F ; day2 = (day & 0xF0)>>4; month1 = month & 0x0F ; month2 = (month & 0xF0)>>4; year1 = year & 0x0F ; year2 = (year & 0xF0)>>4; } void Dislays() { PORTD = led[sec1] ;Pin_C0==1 ; delay_ms(850); Pin_C6==0 ; PORTD = led[sec2] ;Pin_C5==1 ; delay_ms(850); Pin_C5==0 ; PORTD = led[min1] ;Pin_C2==1 ; delay_ms(850); Pin_C2==0 ; PORTD = led[min2] ;Pin_C1==1 ; delay_ms(850); Pin_C1==0 ; PORTD = led[hour1] ;Pin_B7==1 ; delay_ms(850); Pin_B7==0 ; PORTD = led[hour2] ;Pin_B0==1 ; delay_ms(850); Pin_B0==0 ; PORTD = led[date] ;Pin_B2==1 ; delay_ms(850); Pin_B2==0 ; PORTD = led[day1] ;Pin_B1==1 ; delay_ms(850); Pin_B1==0 ; PORTD = led[day2] ;Pin_B4==1 ; delay_ms(850); Pin_B4==0 ; PORTD = led[month1];Pin_B3==1 ; delay_ms(850); Pin_B3==0 ; PORTD = led[month2];Pin_B6==1 ; delay_ms(850); Pin_B6==0 ; PORTD = led[year1] ;Pin_B5==1 ; delay_ms(850); Pin_B5==0 ; } void main() { set_DS1307(); READ_DS(); XULY_DS(); khoi_tao(); while(1) { Dislays();//trong vòng lặp bạn thiếu CT cậP nhập thời gian của ds } } ***************** bạn sửa lai như sau: void main() { set_DS1307(); READ_DS(); XULY_DS(); khoi_tao(); while(1) { READ_DS(); XULY_DS(); Dislays();// } }
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề. |
![]() |
![]() |
![]() |
|
|