Code PIC18F4550 với IC thời gian thực DS1307 hiển thị LCD1602




Mô phỏng

Chương trình trên Mikro C

unsigned char seconds,minute,hour,weekday, days, month, years;

sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
void settime (void);
void Read_Time(void) 
  seconds =I2C1_Rd(1);       //seconds   //convert bcd to ascii for lcd
  minute =I2C1_Rd(1);     //minute       //convert bcd to ascii for lcd
  hour=I2C1_Rd(1);        //hour        //convert bcd to ascii for lcd
  weekday =I2C1_Rd(1);  //weekday ex-monday=2   //convert bcd to ascii for lcd
  days =I2C1_Rd(1);       //day         //convert bcd to ascii for lcd
  month =I2C1_Rd(1);        //month       //convert bcd to ascii for lcd
  years =I2C1_Rd(0);      //year         //convert bcd to ascii for lcd

  // LCD_Out(1,1,"Date:");
   LCD_Chr(1,1,((days&0xf0)>>4)+0x30);//convert bcd to ascii for lcd
   LCD_Chr_cp((days&0x0f)+0x30);  //convert bcd to ascii for lcd
   LCD_Chr_cp(((month&0xf0)>>4)+0x30); //convert bcd to ascii for lcd
   LCD_Chr_cp((month&0x0f)+0x30);   //convert bcd to ascii for lcd
  LCD_Chr_cp(((years&0xf0)>>4)+0x30);  //convert bcd to ascii for lcdii
   LCD_Chr_cp((years&0x0f)+0x30);      //convert bcd to ascii for lcd

 // LCD_Out(2,1,"Time:");

void main() 
  Lcd_Init();                // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);       // Clear LCD display
  Lcd_Cmd(_LCD_CURSOR_OFF);  // Turn cursor off
settime ();                                           // perform initialization
  while (1) {
    Read_Time();      // read time from RTC(DS1307)

void settime (void)
I2C1_Init(100000);     // initialize full master mode
   I2C1_Start();          // issue start signal
   I2C1_Wr(0xD0);         // address DS1307
   I2C1_Wr(0);            // start from word at address (REG0)
   I2C1_Wr(0x80);         // write $80 to REG0. (pause counter + 0 sec)
   I2C1_Wr(0x25);            // write 0 to minutes word to (REG1)
   I2C1_Wr(0x16);         // write 17 to hours word (24-hours mode)(REG2)
   I2C1_Wr(0x02);         // write 2 - Monday (REG3)
   I2C1_Wr(0x24);         // write 4 to date word (REG4)
   I2C1_Wr(0x04);         // write 5 (May) to month word (REG5)
   I2C1_Wr(0x15);         // write 01 to year word (REG6)
   I2C1_Stop();           // issue stop signal

   I2C1_Start();          // issue start signal
   I2C1_Wr(0xD0);         // address DS1307
   I2C1_Wr(0);            // start from word at address 0
   I2C1_Wr(0);            // write 0 to REG0 (enable counting + 0 sec)
   I2C1_Stop();           // issue stop signal


Code+Mô phỏng:


  1. Attractive section of content. I simply stumbled upon your web site and
    in accession capital to say that I get in fact loved account your weblog posts.

    Any way I will be subscribing on your augment or even I
    fulfillment you access consistently rapidly.

  2. Hey I know this is off topic but I was wondering if you knew of
    any widgets I could add to my blog that automatically tweet my
    newest twitter updates. I’ve been looking for a plug-in like this for quite some time and
    was hoping maybe you would have some experience with something
    like this. Please let me know if you run into anything. I truly enjoy reading
    your blog and I look forward to your new updates.

  3. When I originally commented I appear to have clicked on the -Notify me when new comments are added-
    checkbox and from now on every time a comment is added I get 4 emails
    with the exact same comment. There has to be
    a way you can remove me from that service? Cheers!

  4. What i don’t understood is in reality how you are now not
    really a lot more smartly-favored than you might be right now.

    You’re very intelligent. You recognize thus considerably on the subject
    of this subject, made me in my view believe it from so
    many numerous angles. Its like men and women aren’t involved unless
    it’s something to do with Girl gaga! Your own stuffs excellent.
    Always maintain it up!

  5. Admiring the commitment you put into your
    blog and in depth information you offer. It’s nice to
    come across a blog every once in a while that isn’t the same old rehashed information. Wonderful read!
    I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.

  6. Oh my goodness! Impressive article dude! Thanks, However I am having problems
    with your RSS. I don’t understand why I am unable to join it.
    Is there anybody having similar RSS issues?
    Anybody who knows the answer will you kindly respond?

  7. Greetings! I know this is kinda off topic but I’d figured
    I’d ask. Would you be interested in trading links or maybe guest
    authoring a blog post or vice-versa? My website addresses a lot of the same topics as yours and I believe we could greatly benefit from each other.
    If you’re interested feel free to shoot me an email. I look forward to hearing from
    you! Awesome blog by the way!

  8. My coder is trying to convince me to move to .net from
    PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am worried about switching to another
    platform. I have heard fantastic things about
    Is there a way I can transfer all my wordpress posts
    into it? Any help would be greatly appreciated!

  9. Greetіngs from Ohio! I’m bored at work so I decided to browse your websіte
    on my iⲣhone during lunch break. I love the knowledge you presеnt here
    and can’t wasit to take a look when I get home.
    I’m shocked att һow fаst your blog loaded on my phone ..I’m not evеn uѕing WIFI, just
    3G .. Anyhοw, vеry good sitе!

  10. Hey I am so happy I found your site, I really found you by accident, while
    I was researching on Digg for something else, Anyways
    I am here now and would just like to say thank you for a marvelous post and a all
    round entertaining blog (I also love the theme/design), I don’t have time to go through it all at the moment but I have saved it
    and also included your RSS feeds, so when I have time I will be back to read more,
    Please do keep up the fantastic job.

    My blog post joker slot online

  11. Awesome blog you have here but I was curious if you knew of any
    discussion boards that cover the same topics discussed in this article?
    I’d really love to be a part of community where I can get
    suggestions from other knowledgeable people
    that share the same interest. If you have any recommendations, please let me know.

    Review my page –

  12. Yoᥙ’re so aweѕome! I don’t ssuppose I’ᴠe read anything lіke this before.
    So wonderfսl tto ԁiscover ѕomeone with a ffew unique thoughts on this subject.

    Really.. many thanks for starting this սp.

    This site is something that’s nedeԀ on the intеrnet, ѕomeone with sone originalіty!

  13. I hardly drop responses, but after browsing through a ton of
    comments on Code PIC18F4550 với IC thời gian thực DS1307 hiển thị LCD1602 – Điện Tử Hello.
    I do have 2 questions for you if you do not mind.
    Could it be simply me or does it look as if like some of these remarks appear as if they are left by brain dead individuals?
    😛 And, if you are writing on other online sites, I’d like to keep up with you.
    Would you make a list of the complete urls of your social
    community sites like your linkedin profile, Facebook page or twitter

    My website

  14. Hmm it appears like your site ate my first
    comment (it was super long) so I guess I’ll just sum it up what I wrote
    and say, I’m thoroughly enjoying your blog. I too am an aspiring
    blog blogger but I’m still new to everything. Do you have any tips for beginner blog writers?
    I’d definitely appreciate it.

    Here is my webpage;

  15. First of all I would like to say great blog!
    I had a quick question which I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear your mind before writing.
    I have had a difficult time clearing my mind in getting my thoughts out there.

    I do enjoy writing but it just seems like the first 10 to 15 minutes are usually lost simply just trying to figure out how to begin. Any
    ideas or tips? Thanks!

    Here is my web-site: 3дмастер.xn--p1ai

  16. I know this if off topic but I’m looking into starting my own weblog and was curious what all is needed to get setup?

    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet smart so I’m not 100% certain. Any suggestions or advice
    would be greatly appreciated. Thank you

    Feel free to surf to my blog: deposit pulsa

  17. You really make it seem so easy with your presentation but I find this topic to be really something
    that I think I would never understand. It seems too complex and
    extremely broad for me. I am looking forward for
    your next post, I will try to get the hang of it!

  18. Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog blogger but I’m still new to everything.
    Do you have any suggestions for inexperienced blog writers?
    I’d definitely appreciate it.

  19. Thank you for sharing superb informations. Your site is very cool.
    I am impressed by the details that you have on this site.
    It reveals how nicely you perceive this subject. Bookmarked this web
    page, will come back for more articles. You, my pal, ROCK!
    I found just the info I already searched all over the place and just
    couldn’t come across. What a great site.

    Feel free to visit my webpage –

  20. Thanks for your personal marvelous posting! I seriously enjoyed reading it, you will be a great author.I will make certain to
    bookmark your blog and will come back in the foreseeable future.
    I want to encourage yourself to continue your great writing, have a nice evening!

    Review my web page ::

  21. Heya! I realize this is somewhat off-topic
    but I had to ask. Does running a well-established blog such as yours take a lot of work?
    I’m brand new to blogging however I do write in my journal everyday.
    I’d like to start a blog so I can easily share my own experience and views
    online. Please let me know if you have any suggestions or
    tips for new aspiring bloggers. Appreciate it!

    Visit my web blog …

  22. Greetings from Carolina! I’m bored to death at work
    so I decided to check out your website on my iphone during lunch break.
    I really like the information you provide here and can’t wait
    to take a look when I get home. I’m amazed at how quick your blog loaded
    on my cell phone .. I’m not even using WIFI, just 3G .. Anyhow, awesome blog!

    Feel free to visit my web blog;

  23. I am really loving the theme/design of your
    blog. Do you ever run into any internet browser compatibility problems?
    A few of my blog visitors have complained about my website not operating correctly in Explorer but looks great in Opera.

    Do you have any ideas to help fix this problem?

  24. Have you ever thought about writing an ebook or guest authoring on other sites?
    I have a blog based upon on the same information you
    discuss and would love to have you share some stories/information.
    I know my viewers would value your work. If you are
    even remotely interested, feel free to send
    me an e-mail.


Please enter your comment!
Please enter your name here