PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

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

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 10-12-2012, 11:27 PM   #2
qloi
Đệ tử 3 túi
 
Tham gia ngày: Sep 2010
Bài gửi: 55
:
Trích:
Nguyên văn bởi tienrau2 View Post
mình mới học VDK về Pic, làm đồ án mạch đồng hồ số dùng PIC 16F887A và DS1307. Viết được đoạn code nhận thời gian từ DS1307 và hiển thị lên Led, nhưng sao cái mô phỏng nó chạy chậm quá. Không đúng với đồng hồ mình so sánh ở máy tính. Mấy bạn xem giùm mình với nha. Có thể sữa ở chỗ nào?
Code:
#include <16F877A.h>
#FUSES NOWDT, HS, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP
#use delay(clock=20000000)
#use i2c(master,fast,sda=pin_d7,scl=pin_d6)

unsigned char sec,min,hour,day,month,year,date;
unsigned char a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
unsigned char sec1,sec2,min1,min2,hour1,hour2,day1,day2,month1,m onth2,year1,year2;
///////////define//////
void update_time();
void display1();
void main()
{
while (1) {
update_time();
display1();
}
}
void update_time() {
i2c_start();
i2c_write(0xD0); //Gui dia chi cua slave
i2c_write(0x00); //thiet lap lai con tro - set register pointer
i2c_stop();
I2C_start();
I2C_write(0xD1); /* gui lenh doc du lieu */
sec = i2c_read(1);
min = i2c_read(1);
hour = i2c_read(1);
date =i2c_read(1);
day = i2c_read(1);
month = i2c_read(1);
year = i2c_read(0);

i2c_stop();
sec1=sec & 0x0F;
sec2=(sec & 0x70)>>4;
min1=min & 0x0F;
min2=(min & 0x70)>>4;
hour1=hour & 0x0F;
hour2=(hour & 0x30)>>4;
day1=day & 0x0F;
day2=(day & 0x30)>>4;
month1=month & 0x0F;
month2=(month & 0x10)>>4;
year1=year & 0x0F;
year2=(year & 0xF0)>>4;
}
void display1()
{
output_b(a[sec1]); output_high(pin_c0);//SEC1
delay_us(400); output_low(pin_c0);
output_b(a[sec2]); output_high(pin_c1);//SEC2
delay_us(400); output_low(pin_c1);
output_b(a[min1]); output_high(pin_c2);//SEC1
delay_us(400); output_low(pin_c2);
output_b(a[min2]); output_high(pin_c3);//SEC2
delay_us(400); output_low(pin_c3);
output_b(a[hour1]); output_high(pin_c4);//SEC1
delay_us(400); output_low(pin_c4);
output_b(a[hour2]); output_high(pin_c5);//SEC2
delay_us(400); output_low(pin_c5);
output_b(a[day1]); output_high(pin_c6);//SEC1
delay_us(400); output_low(pin_c6);
output_b(a[day2]); output_high(pin_c7);//SEC2
delay_us(400); output_low(pin_c7);
output_b(a[month1]); output_high(pin_d0);//SEC1
delay_us(400); output_low(pin_d0);
output_b(a[month2]); output_high(pin_d1);//SEC2
delay_us(400); output_low(pin_d1);
output_b(a[2]); output_high(pin_d2);//SEC1
delay_us(400); output_low(pin_d2);
output_b(a[0]); output_high(pin_d3);//SEC2
delay_us(400); output_low(pin_d3);
output_b(a[year1]); output_high(pin_d4);//SEC1
delay_us(400); output_low(pin_d4);
output_b(a[year2]); output_high(pin_d5);//SEC2
delay_us(400); output_low(pin_d5);
}
Còn đây là file mô phỏng và code:
Mấy cái này không mô phỏng được đâu , test trực tiếp trên mạch thiệt là được thoy.
__________________
heart.touching.2010@gmail.com!
qloi vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


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à 12:31 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