PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > PIC - Thiết kế và Ứng dụng

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

PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 22-06-2012, 01:14 AM   #8
nghong
Nhập môn đệ tử
 
Tham gia ngày: Jun 2012
Bài gửi: 1
:
Doc Ds1307

minh dang viet ct doc ds1307 bang mikro C 5.61 cho pic16f877a. khong biet sao m lam giong huong dan trong thu vien cua mikro C. ma doc RTC k duoc chi hien thi tren LCD toan la so 0. Duoi day la code va file mo phong cua m co ai hieu li do sao k giup m voi.



//define pin LCD
sbit lcd_rs at rd0_bit;
sbit lcd_en at rd1_bit;
sbit lcd_d4 at rd2_bit;
sbit lcd_d5 at rd3_bit;
sbit lcd_d6 at rd4_bit;
sbit lcd_d7 at rd5_bit;
// define tris register
sbit LCD_RS_Direction at TRISD0_BIT;
sbit LCD_EN_Direction at TRISD1_BIT;
sbit LCD_D4_Direction at TRISD2_BIT;
sbit LCD_D5_Direction at TRISD3_BIT;
sbit LCD_D6_Direction at TRISD4_BIT;
sbit LCD_D7_Direction at TRISD5_BIT;

char buff,seconds,minutes;
char read_ds1307(char address)
{
i2c1_start();
i2c1_wr(0xd0);
i2c1_wr(address);
i2c1_repeated_start();
i2c1_wr(0xd1);
buff = i2c1_rd(0);
i2c1_stop();
return(buff);
}
char write(char address,char data1)
{
i2c1_start();
i2c1_wr(0xd0);
i2c1_wr(address);
i2c1_wr(data1);
i2c1_stop();
return (0x01);
}
void main()
{
trisd = 0; trisc = 0;
portb = 0;
lcd_init();
i2c1_init(100000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
lcd_out(1,3,"giao tiep ds1307");
minutes = write(0x00,0x53);
minutes = write(0x01,0x03);
minutes = write(0x02,0x02);
while(1)
{
seconds = read_ds1307(0);
buff = seconds & 0x0F;
LCD_Chr(3,15,buff + 48 );
buff =seconds >> 4 ;
LCD_Chr(3,14,buff + 48);


seconds = read_ds1307(1);
buff = seconds & 0x0F;
LCD_Chr(3,11,buff + 48 );
buff =seconds >> 4 ;
LCD_Chr(3,10,buff + 48);


seconds = read_ds1307(2);
buff = seconds & 0x0F;
LCD_Chr(3,7,buff + 48 );
buff =seconds >> 4 ;
LCD_Chr(3,6,buff + 48);
}
}
nghong 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à 06:30 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