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 01-07-2010, 01:41 PM   #8
tdm
Đệ 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 đề.
tdm 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à 05:32 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