![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#1 |
Nhập môn đệ tử
Tham gia ngày: Nov 2009
Bài gửi: 8
: |
giúp đỡ về DS1307
chào các bạn mình mới học điện tử làm về con DS1307 hẹn giờ để xuất port .
Tuy nhiên mình gặp vấn đề như sau : khi mình dùng câu lệnh if (sec==giá trị) { output_low(PIN_B1); delay_ms(5000); output_high(PIN_B1); delay_ms(5000); } thì nó vẫn chạy đúng Còn khi mình hẹn thêm phút hoặc giờ vô là nó ko chạy . if ((sec==giá trị) &&( min == giatri)) { output_low(PIN_B1); delay_ms(5000); output_high(PIN_B1); delay_ms(5000); } thì nó ko hoạt động được. Mong các bạn chỉ cho mình . thanks các bạn /////////////////////////////////day là nguyen code cua no ///////////////////////////////// #include <18F4550.h> #device adc=8 #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL5, CPUDIV1, VREGEN #use delay(clock=20000000) #include <pic18_usb.h> #include <hid.h> #include <usb.c> #include <lcd_lib_4bit.c> ///#include <ds1307.c> #include <SHT71.c> #include <ds1307.h> int8 data[8]; void init_DS1307() { output_float(DS1307_SCL); output_float(DS1307_SDA); } void write_DS1307(byte address, BYTE data) { short int status; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_write(data); i2c_stop(); i2c_start(); status=i2c_write(0xd0); while(status==1) { i2c_start(); status=i2c_write(0xd0); } } BYTE read_DS1307(byte address) { BYTE data; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_start(); i2c_write(0xd1); data=i2c_read(0); i2c_stop(); return(data); } void main(void) { int8 sec,min,hour,day,date,month,year; /// delay_ms(50); init_ds1307(); // initial DS1307 sec=read_ds1307(0); write_ds1307(0,sec & 0x7F);// enable oscillator(bit 7 =0) min=read_ds1307(1); write_ds1307(0,min & 0x7F); usb_init_cs();//khoi tao khoi usb Lcd_init(); sec=read_ds1307(0); // read second min=read_ds1307(1); // read minute hour=read_ds1307(2); // read hour day=read_ds1307(3); // read day date=read_ds1307(4); // read date month=read_ds1307(5); // read month year=read_ds1307(6); // read year LCD_SetPosition(0); printf(LCD_putchar,"%02X:%02X:%02X",hour,min,sec); LCD_Setposition(40); printf(LCD_putchar,"%02X/%02X/20%02X",date,month,year); if ( sec==55) { output_low(PIN_B1); delay_ms(5000); output_high(PIN_B1); delay_ms(5000); } } } |
![]() |
![]() |
Ðiều Chỉnh | |
Xếp Bài | |
|
|