PIC Vietnam

Go Back   PIC Vietnam > Truyền thông > Giao tiếp USB, CAN, I2C, SPI, USART...

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

Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 16-11-2012, 03:56 AM   #1
dt03
Nhập môn đệ tử
 
Tham gia ngày: Feb 2012
Bài gửi: 2
:
Cần tìm giúp lỗi lập trình kết nối với DS1307

Chào các bác, em code cho DS1307 kết nối 16f877a với 3 nút bấm 3 chân rb4->rb6 để chọn chế độ setup, down, up và khi build nó mắc lỗi rất lại. Đây là code của em.

#define <16f877a.h>
#define <def_877a.h>
#include <LCD.c>
#device *=16 ADC=8
#include <DS1307.c>
#use delay(clock=20000000)
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use i2c(Master, sda = PIN_C4, scl=PIN_C3)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
#use fast_io (B)
#define select rb4
#define up rb5
#define down rb6
int8 sec, min, hour, date, month, year;//Luu tru gia tri ngay, thang , nam
int8 count=0; //Bien luu tru trang thai set up
//Chuong trinh ngat
#int_RB
void ngat_RB()
{
if(rb4==0){
delay_ms(10);//chong nay phim
count++; //Bien luu tru trang thai setup
if(count=7) count=0;
}
if(rb5==0){
delay_ms(10);
switch(count){
case 0: update_time();
case 1: {sec++; if(sec==60) sec=0; break;}
case 2: {min++; if(min==60) min=0; break;}
case 3: {hour++; if(hour==24) hour=0; break;}
case 4: {date++; if(date==32) date=1; break;}
case 5: {month++; if(month==13) month=1; break;}
case 6: {year++; if(year==100) year=0;break;}
}
}
if(rb6==0){
delay_ms(10);
switch(count){
case 0: update_time();
case 1: {sec--; if(sec==-1) sec=59; break;}
case 2: {min--; if(min==-1) min=59; break;}
case 3: {hour--; if(hour==-1) hour=23; break;}
case 4: {date--; if(date==0) date=31; break;}
case 5: {month--; if(month==0) month=12; break;}
case 6: {year--; if(year==0) year=99;break;}
}
}
}
void update_time(){ //Ham cap nhat thoi gian
sec=read_ds1307(0);
min=read_ds1307(1);
hour=read_ds1307(2);
date=read_ds1307(4);
month=read_ds1307(5);
year=read_ds1307(6);
}
void show_LCD(){ //Ham hien thi len LCD
//Dua con tro ve vi tri cot 8 dong 1 va xuat ra giay, phut, gio
lcd_gotoxy(1,8);
prinft(lcd_puts,"%02D:%02D:%02D",sec,min,hour);
//Dua con tro ve vi tri cot 8 dong 2 va xuat ra ngay, thang, nam
lcd_gotoxy(2,8);
printf(lcd_puts,"%02D:%02D:%02D",date,month,hour);
}
void man(){ //Chuong trinh chinh
set_tris_d(0); //Tin hieu ra o Port D
set_tris_b(0xff); //tin hieu vai o Port B
portb=0xff; //Khoi tao tin hieu o port B la muc cao
enable_interrupts(global);//Cho phep ngat toan cuc
enable_interrupts(int_RB);//Cho phep ngat tu Rb4-Rb7
while(1){
update_time();
ext_int_edge(H_to_L);//Ngat xay ra khi tu high->low
show_LCD();
}
}

Còn lỗi em gửi ảnh đính kèm. Mong các bác giúp đỡ em đang cần gấp.
Hình Kèm Theo
File Type: png PCW_2012-11-16_02-52-15.png (3.8 KB, 9 lần tải)
dt03 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 17-11-2012, 04:32 PM   #2
dt03
Nhập môn đệ tử
 
Tham gia ngày: Feb 2012
Bài gửi: 2
:
Ko ai giúp mình ah?
dt03 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lờ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:49 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