PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

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
Prev Previous Post   Next Post Next
Old 06-07-2010, 05:48 AM   #1
conchocon
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);
}

}

}
conchocon vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 05:44 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam