PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và 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

Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 25-04-2009, 01:41 AM   #1
giangk9a
Đệ tử 1 túi
 
Tham gia ngày: Apr 2009
Bài gửi: 12
:
giup em nhe

Code:
/////////////////////////////////////////////////////////////////////////
////                           EX_RTCLK.C                            ////
////                                                                 ////
////  This program reads and writes to an external Real Time Clock.  ////
////  It communicates to the user using the LCD and keypad.          ////
////                                                                 ////
////  Configure the CCS prototype card as follows:                   ////
////      Install the LCD and keypad.                                ////
////                                                                 ////
////  Jumpers:                                                       ////
////     PCB        pin A2 to RS232 RX, pin A3 to RS232 TX           ////
////     PCM,PCH    pin C7 to RS232 RX, pin C6 to RS232 TX           ////
////                                                                 ////
////  This example will work with the PCB, PCM and PCH compilers.    ////
////  The following conditional compilation lines are used to        ////
////  include a valid device for each compiler.  Change the device,  ////
////  clock and RS232 pins for your hardware if needed.              ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////



//#elif defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)



#include <ds1302.c>
#include <lcd.c>
#include <kbd.c>

byte get_number() {
  char first,second;

  do {
    first=kbd_getc();
  } while ((first<'0') || (first>'9'));
  lcd_putc(first);
  first-='0';

  do {
    second=kbd_getc();
  } while ((second<'0') || (second>'9'));
  lcd_putc(second);
  second-='0';

  return((first*10)+second);
}

void set_clock(){
   byte day,mth,year,dow,hour,min;

   lcd_putc("\fYear 20: ");
   year=get_number();
   lcd_putc("\fMonth: ");
   mth=get_number();
   lcd_putc("\fDay: ");
   day=get_number();
   lcd_putc("\fWeekday 1-7: ");
   dow=get_number();
   lcd_putc("\fHour: ");
   hour=get_number();
   lcd_putc("\fMin: ");
   min=get_number();

   rtc_set_datetime(day,mth,year,dow,hour,min);
}

void main() {
   char cmd;
   byte day,mth,year,dow,hour,min,sec;

   rtc_init();
   lcd_init();
   kbd_init();

   lcd_putc("\f1: Change, 2: Display");

   do {
      cmd=kbd_getc();
   } while ((cmd!='1')&&(cmd!='2'));

   if(cmd=='1')
     set_clock();

   while (1) {
      lcd_putc('\f');
      rtc_get_date( day, mth, year, dow);
      rtc_get_time( hour, min, sec );
      printf(lcd_putc,"%2u/%2u/%2u\n%2u:%2u:%2u",mth,day,year,hour,min,sec);
      delay_ms(250);
   }
}
em không hiểu doạn này" printf(lcd_putc,"%2u/%2u/%2u\n%2u:%2u:%2u",mth,day,year,hour,min,sec);"ch "lcd_putc, " là the nào đấy ạ
cho em hỏi luôn muôn hoiển thi môt số thay đổi theo thời gian lên lcd thi câu lênh sẽ thế nào.ví dụ như hiển thị giờ , phút giây ấy
các cao thủ giúp em với nhé
thanks

thay đổi nội dung bởi: namqn, 25-04-2009 lúc 02:55 AM. Lý do: định dạng code
giangk9a 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à 02:46 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