(Tiểu luận) bài tập lớn vi xử lý đề tài thiết kế mạch đồng hồ thời gian thực sử dụng ds1307 và pic16f877a và hiển thị lên lcd

26 9 0
(Tiểu luận) bài tập lớn vi xử lý đề tài  thiết kế mạch đồng hồ thời gian thực sử dụng ds1307 và pic16f877a và hiển thị lên lcd

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI VIỆN ĐIỆN TỬ VIỄN THÔNG BÀI TẬP LỚN VI XỬ LÝ Đề tài : Thiết kế mạch đồng hồ thời gian thực sử dụng DS1307 PIC16F877A hiển thị lên LCD Giáo viên hướng dẫn : Vũ Song Tùng Sinh viên thực : Nguyễn Văn Trường 20082842 (A) Nguyễn Văn Trường 20083543 (B) Đỗ Đức Cường 20083278 Nguyễn Ngọc Vinh 20083169 Lớp :Điện tử 3-K53 c Mục Lục 1.Lời nói đầu :…………………………………………………………………………………1 2.Giới thiệu nhóm timeline cơng việc : Mô tả hệ thống : Sơ đồ mô PROTEUS Tổng quan khối : a Tổng quan PIC16F877A : b Khối thời gian thực DS1307: c Khối hình LCD1602 11 Sơ đồ chân LCD 1602a .12 d Code chương trình mơ : 14 Kết mô : 22 Mức độ hồn thành cơng việc : .24 Các phần mềm sử dụng q trình mơ : 23 Tài liệu tham khảo : 25 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd LỜI NÓI ĐẦU Ngày nay, hệ thống nhúng trở nên phổ biến đóng vai trị quan trọng đời sống người Ví dụ quanh ta có nhiều sản phẩm nhúng lị vi sóng, nồi cơm điện, điều hịa, điện thoại di động, tơ, máy bay, tàu thủy, đầu đo, cấu chấp hành thơng minh, robot v.v… ta thấy hệ thống nhúng có mặt lúc nơi sống Qua môn học Kỹ thuật Vi xử lý, chúng em hiểu thêm hệ thống nhúng thực tế, đặc điểm, tính ưu việt tính ứng dụng chúng người Với mong muốn làm rõ kiến thức học giới thiệu ứng dụng hệ thống nhúng, nhóm chúng em đưa mơ hình thiết kế đồng hồ thời gian thực – sản phẩm quen thuộc cần thiết đời sống Do thời gian thực kiến thức cịn hạn chế nên cịn nhiều sai sót trình thực đề tài, mong bổ sung đóng góp thầy bạn Chúng em xin chân thành cảm ơn thầy cô Viện Điện tử Viễn thông, cảm ơn thầy Vũ Song Tùng tận tình hướng dẫn giúp đỡ chúng em thực hoàn thành đề tài c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 2.Giới thiệu nhóm timeline cơng việc: Nhóm chúng em gồm thành viên sau : Nguyễn Văn Trường SHSV:20082842 (A) ( trưởng nhóm) Nguyễn Văn Trường 20083543 (B) Đỗ Đức Cường 20083278 Nguyễn Ngọc Vinh 20083169 3.Timeline cơng việc nhóm: Cơng việc Phân cơng Nghiên cứu đề tài,tìm hiểu tài liệu Cả nhóm Vẽ mạch Orcad, Mơ Proteus Cường + Vinh Thiết kế mạch tay Trường A Giao tiếp với máy tính Trường B Viết báo cáo Cường c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 4.Mô tả hệ thống : Đề tài nhằm thiết kế đồng hồ thời gian thực đảm bảo tự cập nhật thời gian hệ thống hiển thị giá trị lên LCD Với thiết kế sử dụng nguồn PIN VBat làm cho hệ thống hoạt động điện hệ thống thời gian thực hoạt động Ngồi đề tài cịn có tương tác với phím bấm nhằm Reset hệ thống 5.Sơ đồ mô PROTEUS R3 R4 R5 4.7k 4.7k 1k U2 LED-YELLOW D1 SCL SDA X1 X1 CRYSTAL SOUT VBAT X2 DS1307 LM016L R1 R2 4.7k 33 34 35 36 37 38 39 40 19 20 21 22 27 28 29 30 10 PIC16F887 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd D0 D1 D2 D3 D4 D5 D6 D7 10 11 12 13 14 15 16 17 18 23 24 25 26 RS RW E RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RA0/AN0/ULPWU/C12IN0RC2/P1A/CCP1 RA1/AN1/C12IN1RC3/SCK/SCL RA2/AN2/VREF-/CVREF/C2IN+ RC4/SDI/SDA RA3/AN3/VREF+/C1IN+ RC5/SDO RA4/T0CKI/C1OUT RC6/TX/CK RA5/AN4/SS/C2OUT RC7/RX/DT RA6/OSC2/CLKOUT RA7/OSC1/CLKIN RD0 RD1 RB0/AN12/INT RD2 RB1/AN10/C12IN3RD3 RB2/AN8 RD4 RB3/AN9/PGM/C12IN2RD5/P1B RB4/AN11 RD6/P1C RB5/AN13/T1G RD7/P1D RB6/ICSPCLK RB7/ICSPDAT RE0/AN5 RE1/AN6 RE2/AN7 6 14 13 RE3/MCLR/VPP U1 VSS VDD VEE 4.7k LCD1 (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd Tổng quan khối : a Tổng quan PIC16F877A : Sơ đồ chân Pic16f877a : Pic16f877a có cổng vào ra: PortA(RA0-RA5), PortB(RB0-RB7), PortC(RC0RC7), PortD(RD0-RD7), PortE(RE0-RE2) Có định thời: Timer0, Timer1, Timer2 8K nhớ chương trình flash Tổ chức nhớ : c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd Có khối nhớ pic16F877A: nhớ chương trình ,bộ nhớ liệu khối nhớ EEPROM Bộ nhớ chương trình nhớ liệu có đường bus riêng truy cập vào nhớ cách riêng rẽ Bộ đếm chương trình có 13 bit khơng gian địa 8k word x 8bit Truy cập vùng không gian gây lỗi Bộ nhớ liệu chia thành bank (Bank0÷Bank3) ,trong bank chứa ghi thường ghi chức đặc biệt Bank chọn phụ thuộc vào bit RP1 RP0 (bit thứ bit thứ 5) ghi trạng thái status RP1:RP0 Bank 00 01 10 11 Các ghi chức đặc biệt CPU ngoại vi sử dụng để điều khiển thiết bị Các ghi hoạt động RAM tĩnh Thanh ghi trạng thái chứa trạng thái số học ALU,trạng thái Reset bit chọn bank nhớ liệu Các cổng vào pic: + Port A: có bit (tương ứng với chân RA0÷RA5) chân cổng A có tích hợp số chức ngoại vi, thiết bị ngoại vi enable cổng khơng hoạt động cổng vào c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd Bình thường Port A cổng vào chiều Thanh ghi xác đinh chiều tương ứng chân port A ghi TrisA Các bit ghi TrisA xác định chân port A đầu vào ngược lại đầu + Port B: rộng bit(tương ứng với chân RB0÷RB7), cổng vào chiều Thanh ghi qui đinh chiều cổng B ghi Tris B Thiết lập bit ghi TrisB làm cho cổng B cổng vào ngược lại cổng + Port C: rộng bit(tương ứng với chân RC0÷RC7), bình thường cổng vào chiều, ghi qui định chiều cổng ghi TrisC Các chân RC3,RC4 dùng để kết nối truyền nhân thông tin với thiết bị ngoại vi + Port D: rộng bit (RD0÷RD7),nó cổng vào cổng Port D cấu cổng vi xử lý rộng bit (cổng slave song song) cách thiêt lập bit điều khiển PSPSTATUS (TrisE.4) Ở chế độ đầu vào la tín hiệu TTL + Port E: rộng bit(RE0÷RE2), cấu hình đầu đầu vào Port E đầu vào điều khiển I/O bit PSPSTATUS (TrisE.4) thiết lập Từ hình vẽ ta thấy, pic16F877A có chân Vcc chân GND, để pic hoạt động ta phải cấp nguồn cho tất chân Ngoài cấp nguồn cung cấp ta phải cấp nguồn xung dao động vi điều khiển hoạt động ta dùng thạch anh 20MHz để cấp xung dao động nguồn dao động cấp thông qua chân 13 14 pic Mạch reset cho vi điều khiển công tắc để hở thông qua chân MCLR vi điều khiển mạch thực reset chân từ mức logic xuống logic cơng tắc để hở chân mang mức logic nối với nguồn thơng qua điện trở hạn dịng R1, điện trở phải có giá trị nhỏ 10k để đảm bảo điện áp cung cấp cho vi điều khiển c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd b Khối thời gian thực DS1307: DS1307 chip thời gian thực hay RTC (Read time clock) Ðây IC tích hợp cho thời gian tính xác thời gian tuyệt đối cho thời gian : Thứ, ngày,tháng, nãm, giờ, phút, giây Chip có ghi bit ghi chứa : Thứ , ngày, tháng, nãm, , phút, giây Ngồi DS1307 cịn chứa ghi điều khiển ngõ phụ 56 ghi trống ghi dùng RAM DS1307 đọc thông qua chuẩn truyền thông I2C nên để đọc ghi từ DS1307 thơng qua chuẩn truyền thơng Do giao tiếp chuẩn I2C nên cấu tạo bên ngồi đơn giản R3 R4 R5 4.7k 4.7k 1k U2 SCL SDA X1 X1 CRYSTAL SOUT VBAT X2 D1 DS1307 LED-YELLOW - DS1307 IC thời gian thực với nguồn cung cấp nhỏ, dùng để cập nhật thời gian ngày tháng với 56 bytes SRAM Địa liệu truyền nối tiếp qua đường bus chiều Nó cung cấp thông tin giờ, phút, giây, thứ, ngày, tháng, c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd năm.Ngày cuối tháng tự động điều chỉnh với tháng nhỏ 31 ngày, bao gồm việc tự động nhảy năm Đồng hồ hoạt động dạng 24h 12h với thị AM/PM DS1307 có mạch cảm biến điện áp dùng để dị điện áp lỗi tự động đóng ngắt với nguồn pin cung cấp - DS 1307 hoạt động với vai trò slave đường bus nối tiếp Việc truy cập thi hành với thị START mã thiết bị định cung cấp địa ghi Tiếp theo ghi truy cập liên tục đến thị STOP thực thi Mô tả hoạt động chân: + X1 X2 đầu vào dao động cho DS1307 Cần dao động thạch anh 32.768Khz Vbat nguồn nuôi cho chip Nguồn từ ( 2V- 3.5V) ta lấy pin có nguồn 3V Ðây nguồn cho chip hoạt động liên tục khơng có nguồn Vcc mà DS1307 hoạt động theo thời gian + Vcc nguồn cho giao tiếp I2C Ðiện áp cung cấp 5V chuẩn dùng chung với vi điều khiển Nếu Vcc khơng có mà Vbat có DS1307 hoạt động bình thường mà khơng ghi đọc liệu +) GND nguồn MASS chung cho Vcc VBAT + SCL(serial clock input): SCL sử dụng để đồng chuyển liệu đường dây nối tiếp + SDA(serial data input/out): chân vào cho đường dây nối tiếp Chân SDA thiết kế theo kiểu cực máng hở , địi hỏi phải có điện trở kéo hoạt động + SQW/OUT(square wave/output driver)- kích hoạt bit SQWE thiết lập 1, chân SQW/OUT phát tần số (1Hz,4kHz,8kHz,32kHz) Chân thiết kế theo kiểu cực máng hở 10 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd Sơ đồ chân LCD 1602a Chức chân: Chân số Tên Chức Chân nối đất cho LCD, thiết kế mạch ta nối chân với Vss GND mạch điều khiển Vdd Chân cấp nguồn cho LCD, thiết kế mạch ta nối chân với VCC=5V mạch điều khiển Vee Chân dùng để điều chỉnh độ tương phản LCD RS Chân chọn ghi (Register select) Nối chân RS với logic “0” (GND) logic“1” (VCC) để chọn ghi + Logic “0”: Bus DB0-DB7 nối với ghi lệnh IR LCD (ở chế độ “ghi” -write) nối với đếm địa LCD (ở chế độ “đọc” - read) 12 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd + Logic “1”: Bus DB0-DB7 nối với ghi liệu DR bên LCD R/W Chân chọn chế độ đọc/ghi (Read/Write) Nối chân R/W với logic “0” để LCD hoạt động chế độ ghi, nối với logic “1” để LCD chế độ đọc E Chân cho phép (Enable) Sau tín hiệu đặt lên bus DB0-DB7, lệnh chấp nhận có xung cho phép chân E + Ở chế độ ghi: Dữ liệu bus LCD chuyển vào(chấp nhận) ghi bên phát xung (high-tolow transition) tín hiệu chân E + Ở chế độ đọc: Dữ liệu LCD xuất DB0-DB7 phát cạnh lên (low-to-high transition) chân E LCD giữ bus đến chân E xuống mức thấp 7-14 DB0- Tám đường bus liệu dùng để trao đổi thông tin với MPU DB7 Có chế độ sử dụng đường bus : + Chế độ bit : Dữ liệu truyền đường, với bit MSB bit DB7 + Chế độ bit : Dữ liệu truyền đường từ DB4 tới DB7, bit MSB DB7 15 Lamp+ Đèn LCD 16 Lamp- Đèn LCD 13 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd d Code chương trình mơ : #define W #define F // register files #byte INDF #byte TMR0 #byte PCL #byte STATUS 10 #byte FSR 11 #byte PORTA 12 #byte PORTB 13 #byte PORTC 14 #byte PORTD 15 #byte PORTE =0x00 =0x01 =0x02 =0x03 =0x04 =0x05 =0x06 =0x07 =0x08 =0x09 16 17 #byte 18 #byte 19 #byte 20 #byte 21 #byte 22 #byte 23 #byte 24 #byte EEDATA EEADR EEDATH EEADRH ADCON0 ADCON1 ADRESH ADSESL =0x10C =0x10D =0x10E =0x10F =0x1F =0x9F =0x9F =0x9F 25 26 #byte 27 #byte 28 #byte 29 #byte 30 #byte 31 #byte PCLATH INTCON PIR1 PIR2 PIE1 PIE2 =0x0a =0x0b =0x0c =0x0d =0x8c =0x8d 32 33 #byte 34 #byte 35 #byte 36 #byte 37 #byte OPTION_REG TRISA TRISB TRISC TRISD =0x81 =0x85 =0x86 =0x87 =0x88 14 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 38 #byte TRISE =0x89 39 40 #byte EECON1 41 #byte EECON2 =0x18C =0x18D 42 43 //DINH 44 #bit 45 #bit 46 #bit 47 #bit 48 #bit 49 #bit NGHIA BIT ra5 =0x05.5 ra4 =0x05.4 ra3 =0x05.3 ra2 =0x05.2 ra1 =0x05.1 ra0 =0x05.0 50 51 #bit 52 #bit 53 #bit 54 #bit 55 #bit 56 #bit 57 #bit 58 #bit rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 =0x06.7 =0x06.6 =0x06.5 =0x06.4 =0x06.3 =0x06.2 =0x06.1 =0x06.0 rC7 rC6 rC5 rC4 rC3 rC2 rC1 rC0 =0x07.7 =0x07.6 =0x07.5 =0x07.4 =0x07.3 =0x07.2 =0x07.1 =0x07.0 rD7 rD6 rD5 rD4 rD3 rD2 rD1 rD0 =0x08.7 =0x08.6 =0x08.5 =0x08.4 =0x08.3 =0x08.2 =0x08.1 =0x08.0 59 60 #bit 61 #bit 62 #bit 63 #bit 64 #bit 65 #bit 66 #bit 67 #bit 68 69 #bit 70 #bit 71 #bit 72 #bit 73 #bit 74 #bit 75 #bit 76 #bit 15 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 77 78 #bit rE2 79 #bit rE1 80 #bit rE0 =0x09.2 =0x09.1 =0x09.0 81 82 83 #bit 84 #bit 85 #bit 86 #bit 87 #bit 88 #bit trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 =0x85.5 =0x85.4 =0x85.3 =0x85.2 =0x85.1 =0x85.0 trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 =0x86.7 =0x86.6 =0x86.5 =0x86.4 =0x86.3 =0x86.2 =0x86.1 =0x86.0 89 90 #bit 91 #bit 92 #bit 93 #bit 94 #bit 95 #bit 96 #bit 97 #bit 98 99 #bit 100 101 102 103 104 105 106 trisc7 =0x87.7 #bit trisc6 =0x87.6 #bit trisc5 =0x87.5 #bit trisc4 =0x87.4 #bit trisc3 =0x87.3 #bit trisc2 =0x87.2 #bit trisc1 =0x87.1 #bit trisc0 =0x87.0 107 108 109 110 111 112 113 114 115 #bit #bit #bit #bit #bit #bit #bit #bit trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 =0x88.7 =0x88.6 =0x88.5 =0x88.4 =0x88.3 =0x88.2 =0x88.1 =0x88.0 16 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 116 117 118 119 #bit trise2 #bit trise1 #bit trise0 =0x89.2 =0x89.1 =0x89.0 120 121 122 123 124 125 126 127 128 129 // INTCON Bits for C #bit gie = 0x0b.7 #bit peie = 0x0b.6 #bit tmr0ie = 0x0b.5 #bit int0ie = 0x0b.4 #bit rbie = 0x0b.3 #bit tmr0if = 0x0b.2 #bit int0if = 0x0b.1 #bit rbif = 0x0b.0 130 131 132 133 134 135 136 137 138 139 // PIR1 for C #bit pspif = 0x0c.7 #bit adif = 0x0c.6 #bit rcif = 0x0c.5 #bit txif = 0x0c.4 #bit sspif = 0x0c.3 #bit ccp1if = 0x0c.2 #bit tmr2if = 0x0c.1 #bit tmr1if = 0x0c.0 140 141 142 143 144 145 //PIR2 for C #bit cmif = 0x0d.6 #bit eeif = 0x0d.4 #bit bclif = 0x0d.3 #bit ccp2if = 0x0d.0 146 147 148 149 150 151 152 153 154 // PIE1 for C #bit adie = 0x8c.6 #bit rcie = 0x8c.5 #bit txie = 0x8c.4 #bit sspie = 0x8c.3 #bit ccp1ie = 0x8c.2 #bit tmr2ie = 0x8c.1 #bit tmr1ie = 0x8c.0 17 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 155 156 157 158 159 //PIE2 for C #bit osfie = 0x8d.7 #bit cmie = 0x8d.6 #bit eeie = 0x8d.4 160 161 162 163 164 165 166 167 168 169 // OPTION Bits #bit not_rbpu = #bit intedg #bit t0cs #bit t0se #bit psa #bit ps2 #bit ps1 #bit ps0 0x81.7 = 0x81.6 = 0x81.5 = 0x81.4 = 0x81.3 = 0x81.2 = 0x81.1 = 0x81.0 // EECON1 Bits #bit eepgd = #bit free = #bit wrerr = #bit wren = #bit wr = #bit rd = 0x18c.7 0x18C.4 0x18C.3 0x18C.2 0x18C.1 0x18C.0 170 171 172 173 174 175 176 177 178 179 180 181 182 //ADCON0 #bit CHS0 #bit CHS1 #bit CHS2 =0x1F.3 =0x1F.4 =0x1F.5 183 184 185 186 187 188 189 190 191 192 193 void write_DS1307(int8 address,int8 data) { short int status; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_write(data); i2c_stop(); i2c_start(); status=i2c_write(0xd0); 18 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 while(status==1) { i2c_start(); status=i2c_write(0xd0); } } //========================== // read data one byte from DS1307 //========================== int8 read_DS1307(int8 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 ds1307_int(void) { int temp; temp=read_DS1307(0x00); temp=temp&0x80; if(temp==0x80) write_DS1307(0x00,0x00); temp=read_DS1307(0x07); temp=temp&0x90; if(temp!=0x90) write_DS1307(0x07,0x90); } 228 229 #include 230 231 232 #define LCD_RS //#define LCD_RW PIN_D2 PIN_A1 19 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 233 #define LCD_EN PIN_D3 #define #define #define #define LCD_D4 LCD_D5 LCD_D6 LCD_D7 PIN_D4 PIN_D5 PIN_D6 PIN_D7 // misc #define #define #define display definesLine_1 0x80 Line_2 0xC0 Clear_Scr 0x01 234 235 236 237 238 239 240 241 242 243 244 245 246 // prototype statements #separate void LCD_Init ( void );// ham khoi tao LCD #separate void LCD_SetPosition ( unsigned int cX );//Thiet lap vi tri tro 248 #separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD 249 #separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD 250 #separate void LCD_PulseEnable ( void );// Xung kich hoat 251 #separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data 252 // D/n Cong 253 #use standard_io (C) 254 #use standard_io (D) 247 255 //khoi tao LCD********************************************** 257 #separate void LCD_Init ( void ) 258 { 259 LCD_SetData ( 0x00 ); 260 delay_ms(200); /* wait enough time after Vdd rise >> 15ms */ 261 output_low ( LCD_RS );// che gui lenh 262 LCD_SetData ( 0x03 ); /* init with specific nibbles to start 4-bit mode */ 256 20 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 263 264 265 266 LCD_PulseEnable(); LCD_PulseEnable(); LCD_PulseEnable(); LCD_SetData ( 0x02 ); /* set 4-bit interface */ LCD_PulseEnable(); hereafter, MSN first */ 268 LCD_PutCmd ( 0x2C ); lines, 5x7 characters) */ 269 LCD_PutCmd ( 0x0C ); off, no blink */ 270 LCD_PutCmd ( 0x06 ); increment & scroll left */ 271 LCD_PutCmd ( 0x01 ); 272 } 267 /* send dual nibbles /* function set (all /* display ON, cursor /* entry mode set, /* clear display */ 273 #separate void LCD_SetPosition ( unsigned int cX ) 275 { 276 /* this subroutine works specifically for 4-bit Port A */ 277 LCD_SetData ( swap ( cX ) | 0x08 ); 278 LCD_PulseEnable(); 279 LCD_SetData ( swap ( cX ) ); 280 LCD_PulseEnable(); 281 } 274 282 #separate void LCD_PutChar ( unsigned int cX ) 284 { 285 /* this subroutine works specifically for 4-bit Port A */ 286 output_high ( LCD_RS ); 287 LCD_PutCmd( cX ); 288 output_low ( LCD_RS ); 289 } 283 290 #separate void LCD_PutCmd ( unsigned int cX ) 292 { 293 /* this subroutine works specifically for 4-bit Port A */ 291 21 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 294 LCD_SetData ( swap ( cX ) ); /* send high LCD_PulseEnable(); LCD_SetData ( swap ( cX ) ); /* send low nibble */ 295 296 nibble */ 297 298 299 300 301 302 303 304 305 LCD_PulseEnable(); } #separate void LCD_PulseEnable ( void ) { output_high ( LCD_EN ); delay_us ( ); // was 10 output_low ( LCD_EN ); delay_ms ( ); // was } 306 307 308 309 310 311 312 313 #separate void { output_bit output_bit output_bit output_bit } LCD_SetData ( unsigned int cX ) ( ( ( ( LCD_D4, LCD_D5, LCD_D6, LCD_D7, cX cX cX cX & & & & 0x01 0x02 0x04 0x08 ); ); ); ); 6.Kết mô : 22 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd R3 R4 R5 4.7k 4.7k 1k U2 LED-YELLOW D1 SCL SDA X1 X1 CRYSTAL SOUT VBAT X2 DS1307 LM016L R1 R2 4.7k 33 34 35 36 37 38 39 40 19 20 21 22 27 28 29 30 10 PIC16F887 Mạch in : 23 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd D0 D1 D2 D3 D4 D5 D6 D7 15 16 17 18 23 24 25 26 10 11 12 13 14 RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RA0/AN0/ULPWU/C12IN0RC2/P1A/CCP1 RA1/AN1/C12IN1RC3/SCK/SCL RA2/AN2/VREF-/CVREF/C2IN+ RC4/SDI/SDA RA3/AN3/VREF+/C1IN+ RC5/SDO RA4/T0CKI/C1OUT RC6/TX/CK RA5/AN4/SS/C2OUT RC7/RX/DT RA6/OSC2/CLKOUT RA7/OSC1/CLKIN RD0 RD1 RB0/AN12/INT RD2 RB1/AN10/C12IN3RD3 RB2/AN8 RD4 RB3/AN9/PGM/C12IN2RD5/P1B RB4/AN11 RD6/P1C RB5/AN13/T1G RD7/P1D RB6/ICSPCLK RB7/ICSPDAT RE0/AN5 RE1/AN6 RE2/AN7 RS RW E RE3/MCLR/VPP 6 14 13 U1 VSS VDD VEE 4.7k LCD1 (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 7.Mức độ hồn thành cơng việc : Nhìn chung dự án hồn thành mạch mơ chạy ổn định khâu tập lớn 8.Các phần mềm sử dụng q trình mơ : MPlab Ver 8.4 , Proteus ver 7.7 , Visual Studio 2010, Orcad 10.5 24 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd 25 c (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd (Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd(Tieu.luan).bai.tap.lon.vi.xu.ly.de.tai thiet.ke.mach.dong.ho.thoi.gian.thuc.su.dung.ds1307.va.pic16f877a.va.hien.thi.len.lcd

Ngày đăng: 30/12/2023, 05:25

Tài liệu cùng người dùng

Tài liệu liên quan