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

107
1622

[BÀI VIẾT SƯU TẦM CODE]

  • COMPILER – MIKRO C PRO 6.6.1
  • SIMULATOR -PROTEUS 8.1

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) 
{
  I2C1_Start();
  I2C1_Wr(0xD0);
  I2C1_Wr(0);
  I2C1_Repeated_Start();
  I2C1_Wr(0xD1);
  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
  I2C1_Stop();

  // 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(':');
   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(':');
  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:");
   LCD_Chr(2,1,((hour&0xf0)>>4)+0x30);
   LCD_Chr_cp((hour&0x0f)+0x30);
   LCD_Chr_cp(':');
   LCD_Chr_cp(((minute&0xf0)>>4)+0x30);
   LCD_Chr_cp((minute&0x0f)+0x30);
    LCD_Chr_cp(':');
   LCD_Chr_cp(((seconds&0xf0)>>4)+0x30);
   LCD_Chr_cp((seconds&0x0f)+0x30);
}

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

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
     delay_ms(500);

}

Code+Mô phỏng: https://drive.google.com/file/d/1sTA6KdSnMwU0HfvZyNrmbbZ47acB572c/view?usp=sharing

107 COMMENTS

  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?
    Thanks!!

  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 blogengine.net.
    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.
    Kudos!

    Review my page – http://www.gdaca.com

  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
    feed?

    My website http://www.sixfigureclassifieds.com

  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; muonlinebrazilian.com

  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 – qiurom.com

  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 :: ads.wealthxo.com

  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 … kebe.top

  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; http://prahacom.cz/

  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.

  25. Greetings! Quick question that’s completely off topic.
    Do you know how to make your site mobile friendly? My weblog looks weird when viewing from my apple iphone.
    I’m trying to find a template or plugin that might be able to fix this problem.
    If you have any suggestions, please share.
    With thanks!

  26. I am extremely impressed along with your writing
    talents as neatly as with the structure on your weblog.
    Is this a paid topic or did you modify it your self?

    Anyway keep up the nice high quality writing, it is rare to see a great
    weblog like this one nowadays..

  27. Hey! I know this is kind of off topic but I was wondering if you knew
    where I could locate a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

  28. Hello, Neat post. There is a problem along with your site in internet explorer, could check this?
    IE nonetheless is the market leader and a good component to people will omit your
    excellent writing due to this problem.

    My web-site … xe88

  29. I am also commenting to let you know of the helpful experience our daughter
    gained visiting your blog. She learned some pieces, with the
    inclusion of how it is like to possess a very effective helping style to make the others without hassle learn chosen very confusing topics.
    You undoubtedly exceeded readers’ expectations.
    Thank you for giving those beneficial, healthy, informative and easy
    guidance on this topic to Lizeth.

    Have a look at my homepage; http://www.petdelico.com

  30. First of all I would like to say superb blog! I had a quick question that I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear
    your head prior to writing. I have had a difficult time clearing my thoughts in getting my
    thoughts out. I do take pleasure in writing however it just seems like the
    first 10 to 15 minutes tend to be lost just trying to figure out how to
    begin. Any ideas or hints? Thanks!

  31. Magnificent beat ! I would like to apprentice at the same
    time as you amend your web site, how could i subscribe for a weblog website?
    The account aided me a applicable deal. I were a little
    bit familiar of this your broadcast offered brilliant transparent idea

  32. Hi, I do think this is a great web site. I
    stumbledupon it 😉 I will return once again since i have book-marked it.
    Money and freedom is the best way to change, may
    you be rich and continue to help other people.

  33. Whats up very nice blog!! Guy .. Excellent .. Superb ..
    I will bookmark your blog and take the feeds additionally?
    I am satisfied to seek out so many helpful information here
    in the post, we’d like develop more strategies on this regard,
    thank you for sharing. . . . . .

    Feel free to visit my web-site; biblioray.pusku.com

  34. Hello there, I found your site via Google even as searching for a comparable topic,
    your site got here up, it looks good. I’ve bookmarked it in my google
    bookmarks.[X-N-E-W-L-I-N-S-P-I-N-X]Hello there, just
    became aware of your blog through Google, and
    located that it is really informative. I’m going to watch out
    for brussels. I will appreciate if you happen to continue this in future.
    Lots of folks shall be benefited from your writing.
    Cheers!

    Feel free to visit my webpage – bettyjostarke.net

LEAVE A REPLY

Please enter your comment!
Please enter your name here