Anda di halaman 1dari 14

Com partilhar

mais

Prximo blog

Criar um blog

Login

PIC Microcontroller Note


Addicted to electronics, microcontroller, LED Dot Matrix, Led 7 -Segment, PIC Digital Clock, Digital Watch, Led Dot Matrix Clock, Led Dot Matrix Watch, GPS and other DIY projects. Short notes about my PIC Microcontroller experiments sometimes it's just a short note sometimes it's a full PIC Microcontroller Project. The information here including source code and schematic are available for FREE, please contact me if you w ant the source files of the schematics/PCBs.

Making y our own Digital Clock

MON DA Y , J A N UA RY 5 , 2 0 0 9

A Simple Clock using DS1307 + PIC16F877A


Ev en I hav e posted about "DS1 307 + PIC1 6F87 7 A", I didn't hav e chance to make a real prototy pe of the clock. I hav e done only on the simulation software. Today , I hav e receiv ed a comment about that post. ah_bear followed my code and schematic on that post but the clock didn't work. This is because the code on that post is for reading time from DS1 307 so there must be some v alues in the DS1 307 before y ou can read. The solution is simple. Just place setting time codes before reading codes. This time, I hav e made a real prototy pe to confirm that it's working. There is no setting buttons. If y ou want to make a real usable clock y ou hav e to implement the button interfaces (I may make one and post it here). The photo of my working prototy pe is featured below. Please check out my flikr at http://flickr.com/photos/punkky / for more photos.

Topics
Micr ocon t r oller (3 3 ) Clock (2 4 ) PIC1 6 F6 2 7 a (1 5 ) PIC1 6 F6 2 8 (1 5 ) Sou r ce Code (1 4 ) Sch em a t ic (1 1 ) Mik r oC (1 0 ) Dot Ma t r ix (9 ) 7 -Seg m en t (8 ) DS1 3 0 7 (6 ) Elect r on ics (5 ) PIC1 6 F8 8 7 (5 ) PIC1 6 F8 7 7 a (4 )

The schematic of the clock is v ery simple. Please note that the schematic does not show power supply to the PIC1 6F87 7 A and the DS1 307 , y ou hav e to connect them by y ouself. If y ou are new to PIC/LCD interface please see MikroC "Hello World!" LCD ex ample .

PCB (3 ) Cir cu it Sim u la t ion (2 ) Cir cu it Sim u la t or (2 ) GPS (2 ) Mu lt iplex in g (2 ) Oscilla t or (2 ) T r ip (2 ) W a t ch (2 ) Ba t t er y Ch a r g er (1 ) Com pu t er (1 ) DC-DC Con v er t or (1 ) FM T u n er (1 ) Nix ie (1 ) W or dpr ess Mu (1 ) led (1 )

Blog Archive
2 0 1 0 (4 ) 2 0 0 9 (1 3 )

The source code:


/ / S a m p l ec o d ef o r / / D S 1 3 0 7R T CI n t e r f a c i n gw i t hP I C 1 6 F 8 7 7 A / / C o d e db yp u n k k y @ g m a i l . c o m / / C o m p i l e r :m i k r o C8 . 0 . 0 / / h t t p : / / p i c n o t e . b l o g s p o t . c o m / / 0 5 / 0 1 / 2 0 0 9 / / U s ew i t hy o u ro w nr i s k u n s i g n e ds h o r tr e a d _ d s 1 3 0 7 ( u n s i g n e ds h o r ta d d r e s s) ; v o i dw r i t e _ d s 1 3 0 7 ( u n s i g n e ds h o r ta d d r e s s , u n s i g n e ds h o r tw _ d a t a ) ; u n s i g n e ds h o r ts e c ; u n s i g n e ds h o r tm i n u t e ; u n s i g n e ds h o r th o u r ; u n s i g n e ds h o r td a y ; u n s i g n e ds h o r td a t e ; u n s i g n e ds h o r tm o n t h ; u n s i g n e ds h o r ty e a r ; u n s i g n e ds h o r td a t a ; c h a rt i m e [ 9 ] ; c h a rd d a t e [ 1 1 ] ; u n s i g n e dc h a rB C D 2 U p p e r C h ( u n s i g n e dc h a rb c d ) ; u n s i g n e dc h a rB C D 2 L o w e r C h ( u n s i g n e dc h a rb c d ) ; v o i dm a i n ( ) { I 2 C _ I n i t ( 1 0 0 0 0 0 ) ;/ / D S 1 3 0 7I 2 Ci sr u n n i n ga t1 0 0 K H z P O R T B=0 ; T R I S B=0 ;/ /C o n f i g u r eP O R T Ba so u t p u t T R I S C=0 x F F ; L c d _ I n i t ( & P O R T B ) ;/ /I n i t i a l i z eL C Dc o n n e c t e dt oP O R T B L c d _ C m d ( L c d _ C L E A R ) ;/ /C l e a rd i s p l a y L c d _ C m d ( L c d _ C U R S O R _ O F F ) ;/ /T u r nc u r s o ro f f L c d _ O u t ( 1 ,1 ," T I M E : " ) ; L c d _ O u t ( 2 ,1 ," D A T E : " ) ; / / S e tT i m e w r i t e _ d s 1 3 0 7 ( 0 , 0 x 8 0 ) ;/ / R e s e ts e c o n dt o0s e c .a n ds t o pO s c i l l a t o r w r i t e _ d s 1 3 0 7 ( 1 , 0 x 1 0 ) ;/ / w r i t em i n2 7 w r i t e _ d s 1 3 0 7 ( 2 , 0 x 0 1 ) ;/ / w r i t eh o u r1 4 w r i t e _ d s 1 3 0 7 ( 3 , 0 x 0 2 ) ;/ / w r i t ed a yo fw e e k2 : M o n d a y w r i t e _ d s 1 3 0 7 ( 4 , 0 x 0 5 ) ;/ /w r i t ed a t e1 7 w r i t e _ d s 1 3 0 7 ( 5 , 0 x 0 1 ) ;/ /w r i t em o n t h6J u n e w r i t e _ d s 1 3 0 7 ( 6 , 0 x 0 9 ) ;/ /w r i t ey e a r8>2 0 0 8 w r i t e _ d s 1 3 0 7 ( 7 , 0 x 1 0 ) ;/ / S Q W Eo u t p u ta t1H z

Nov em ber (1 ) A u g u st (1 ) Ma y (1 ) A pr il (1 ) Ma r ch (2 ) Febr u a r y (2 ) Ja n u a r y (5 ) 3 D Elect r on ics Desig n T h in g s t o do 2 -dig it BCD t o decim a l con v er sion Squ a r e W a v e ou t pu t fr om DS1 3 0 7 A Sim ple Clock u sin g DS1 3 0 7 + PIC1 6 F8 7 7 A 2 0 0 8 (4 7 )

Related Webz
W a t ch Kzy Blog On lin e W a t ch A u ct ion Na lig a Not e Pu n k k y 's Blog PLA ZEON W a t ch Kzy

Feeds
Post s Com m en t s

w r i t e _ d s 1 3 0 7 ( 0 , 0 x 0 0 ) ;/ / R e s e ts e c o n dt o0s e c .a n ds t a r tO s c i l l a t o r w h i l e ( 1 ) { s e c = r e a d _ d s 1 3 0 7 ( 0 ) ;/ /r e a ds e c o n d m i n u t e = r e a d _ d s 1 3 0 7 ( 1 ) ;/ /r e a dm i n u t e h o u r = r e a d _ d s 1 3 0 7 ( 2 ) ;/ /r e a dh o u r d a y = r e a d _ d s 1 3 0 7 ( 3 ) ;/ /r e a dd a y d a t e = r e a d _ d s 1 3 0 7 ( 4 ) ;/ /r e a dd a t e m o n t h = r e a d _ d s 1 3 0 7 ( 5 ) ;/ /r e a dm o n t h y e a r = r e a d _ d s 1 3 0 7 ( 6 ) ;/ /r e a dy e a r t i m e [ 0 ]=B C D 2 U p p e r C h ( h o u r ) ; t i m e [ 1 ]=B C D 2 L o w e r C h ( h o u r ) ; t i m e [ 2 ]=' : ' ; t i m e [ 3 ]=B C D 2 U p p e r C h ( m i n u t e ) ; t i m e [ 4 ]=B C D 2 L o w e r C h ( m i n u t e ) ; t i m e [ 5 ]=' : ' ; t i m e [ 6 ]=B C D 2 U p p e r C h ( s e c ) ; t i m e [ 7 ]=B C D 2 L o w e r C h ( s e c ) ; t i m e [ 8 ]=' \ 0 ' ; d d a t e [ 0 ]=B C D 2 U p p e r C h ( d a t e ) ; d d a t e [ 1 ]=B C D 2 L o w e r C h ( d a t e ) ; d d a t e [ 2 ]= ' / ' ; d d a t e [ 3 ]=B C D 2 U p p e r C h ( m o n t h ) ; d d a t e [ 4 ]=B C D 2 L o w e r C h ( m o n t h ) ; d d a t e [ 5 ]= ' / ' ; d d a t e [ 6 ]=' 2 ' ; d d a t e [ 7 ]=' 0 ' ; d d a t e [ 8 ]=B C D 2 U p p e r C h ( y e a r ) ; d d a t e [ 9 ]=B C D 2 L o w e r C h ( y e a r ) ; d d a t e [ 1 0 ]=' \ 0 ' ; L c d _ O u t ( 1 , 6 , t i m e ) ; L c d _ O u t ( 2 , 6 , d d a t e ) ; D e l a y _ m s ( 5 0 ) ; } } u n s i g n e ds h o r tr e a d _ d s 1 3 0 7 ( u n s i g n e ds h o r ta d d r e s s ) { I 2 C _ S t a r t ( ) ; I 2 C _ W r ( 0 x d 0 ) ;/ / a d d r e s s0 x 6 8f o l l o w e db yd i r e c t i o nb i t( 0f o r w r i t e ,1f o rr e a d )0 x 6 8f o l l o w e db y0>0 x D 0 I 2 C _ W r ( a d d r e s s ) ; I 2 C _ R e p e a t e d _ S t a r t ( ) ; I 2 C _ W r ( 0 x d 1 ) ;/ / 0 x 6 8f o l l o w e db y1>0 x D 1 d a t a = I 2 C _ R d ( 0 ) ; I 2 C _ S t o p ( ) ; r e t u r n ( d a t a ) ; } u n s i g n e dc h a rB C D 2 U p p e r C h ( u n s i g n e dc h a rb c d ) { r e t u r n( ( b c d> >4 )+' 0 ' ) ; } u n s i g n e dc h a rB C D 2 L o w e r C h ( u n s i g n e dc h a rb c d ) { r e t u r n( ( b c d&0 x 0 F )+' 0 ' ) ; } v o i dw r i t e _ d s 1 3 0 7 ( u n s i g n e ds h o r ta d d r e s s , u n s i g n e ds h o r tw _ d a t a ) { I 2 C _ S t a r t ( ) ;/ /i s s u eI 2 Cs t a r ts i g n a l

/ / a d d r e s s0 x 6 8f o l l o w e db yd i r e c t i o nb i t( 0f o rw r i t e ,1f o r r e a d )0 x 6 8f o l l o w e db y0>0 x D 0 I 2 C _ W r ( 0 x D 0 ) ;/ /s e n db y t ev i aI 2 C( d e v i c ea d d r e s s+W ) I 2 C _ W r ( a d d r e s s ) ;/ /s e n db y t e( a d d r e s so fD S 1 3 0 7l o c a t i o n ) I 2 C _ W r ( w _ d a t a ) ;/ /s e n dd a t a( d a t at ob ew r i t t e n ) I 2 C _ S t o p ( ) ;/ /i s s u eI 2 Cs t o ps i g n a l }


Poste d by punk k y at Monday, January 05, 2009 Topics: C lock , DS1307 , Microcontrolle r , PIC 16F877a , Sche m atic , Source C ode

54 comments:
Blue T ear's said... Great post. But i need help to increase buttons to set time and date. Can y ou help me with this.
Jan u ary 6, 2009 at 10:20 PM

punkky said... I'm working on the complete clock. I will post the whole things. Please come back later.
Jan u ary 11, 2009 at 10:49 A M

Blue T ear's said... Can y ou post y our new code for the buttons. Thanks
Jan u ary 15, 2009 at 8:28 PM

ox ox o said... thanks for sharing the code. but i do not understand the datasheet for DS1 307 on how to set the time that i want..for ex ample, i want to set the time for 24-hr clock at 0800 or 1 900(7 p.m). i don get to understand how u write 0x 01 as 1 4 hour (write_ds1 307 (2,0x 01 ); //write hour 1 4) and other timing as well. do adv ise this asap, a million thanks~!
March 25, 2009 at 12:33 A M

PIC said... good program


A pri l 25, 2009 at 6:53 PM

trungnt said... Based on y our code, I hav e written code for RTC using buttons to set time and 1 2 Led 7 -Seg to show time (y earmonth-date-hour-min-sec). Thanks!!!
May 27, 2009 at 9:53 PM

Chuck said... Can y ou help me? This is my first attempt to program a chip. What to make a red clock for car. I'v e been try ing to program a pic chip 1 6f628A for the last month. For some reason all I get is ERROR hardware not found on COM. I hav e down loaded picax e programming editor.

I purchased the pic programmer. I hav e a USB to serial cable. What is wrong?????
Ju l y 14, 2009 at 4:54 PM

Chuck said... Me again. Y ou can contact me at sbcm07 @hotmail.com


Ju l y 15, 2009 at 3:26 A M

Ranier said... hi ev ery one, help me to make add-ons to this circuit.. i will make an alarm clock that will based to the digital clock made... this is my first time to program to a chip. pls help me... here's my email address... ranier21 ph@y ahoo.com
October 6, 2009 at 5:32 PM

KENNY said... may i know wat ty pe of cry stal r using?


Decem ber 8, 2009 at 8:16 PM

sarah said... may i know which software did y ou used to simulate the circuit and the coding.tq
Decem ber 10, 2009 at 11:22 PM

Minos said... I'v e made the schematic, but the simul inisis doesn't work. time is 00:00:00, and date 00:00:2000. can u help me pls?
Jan u ary 11, 2010 at 7:58 PM

m alik said... I'v e made the schematic, but the simul inisis doesn't work. time is 00:00:00, and date 00:00:2000. can u help me pls?
A pri l 21, 2010 at 10:26 PM

m alik said... please please help for this issue

I'v e made the schematic, but the simul inisis doesn't work. time is 00:00:00, and date 00:00:2000. can u help me pls?
A pri l 21, 2010 at 10:26 PM

m alik said... I'v e made the schematic, but the simul inisis doesn't work. time is 00:00:00, and date 00:00:2000. can u help me pls?
A pri l 21, 2010 at 10:27 PM

T an said... hi, may i know how to add the alarm function to this project code? thank
May 14, 2010 at 6:09 PM

T an said... This comment has been removed by the author.


May 14, 2010 at 6:11 PM

m alik said... i hav e implemented it on hardware it works fy n. On proteus it works only with i2c dbugger. Do not waste ur ty m by simulating it on Proteus.. just direct implement it. thnx
May 15, 2010 at 2:45 A M

hilm i sa'ari said... hello.. nice project.. i want to try this project, but i got some error when build at microC PRO.. so.. any problem at there..? here's my email address... sk8terboy _amie@y ahoo.com.my
October 7, 2010 at 7:45 PM

m alik said... @hilmi what is error? giv e me details


October 7, 2010 at 11:19 PM

hilm i sa'ari said... This comment has been removed by the author.
October 8, 2010 at 3:50 A M

hilm i sa'ari said... This comment has been removed by the author.
October 8, 2010 at 3:52 A M

hilm i sa'ari said... @malik.. this all the error.. please help me t build this source code.. i use microC PRO.. thank y ou ->27 324 Undeclared identifier 'I2C_Init' in ex pression delete.c ->31 31 3 Too many actual parameters delete.c ->32 324 Undeclared identifier 'Lcd_CLEAR' in ex pression delete.c ->33 324 Undeclared identifier 'Lcd_CURSOR_OFF' in ex pression delete.c ->88 324 Undeclared identifier 'I2C_Start' in ex pression delete.c ->89 324 Undeclared identifier 'I2C_Wr' in ex pression delete.c ->90 324 Undeclared identifier 'I2C_Wr' in ex pression delete.c ->91 324 Undeclared identifier 'I2C_Repeated_Start' in ex pression delete.c

->92 324 Undeclared identifier 'I2C_Wr' in ex pression delete.c ->93 31 5 Inv alid ex pression delete.c ->92 401 ; ex pected, but 'data' found delete.c ->93 423 '}' ex pected ';' found delete.c ->96 1 503 Result is not defined in function: 'read_ds1 307 ' delete.c ->96 31 2 Internal error '' delete.c ->0 1 02 Finished (with errors): 08 Oct 201 0, 05:1 4:1 2 delete.mcppi
October 8, 2010 at 4:15 A M

m alik said... @hilmi commands format in MickroC basic and pro is not not same. go to help in MickroC pro and see proper formats. Its better to use MickroC for PIC microcontrollers v 8.1 . i personally used abov e v ersion and got satisfactory results
October 8, 2010 at 4:37 PM

hilm i sa'ari said... @malik thank y ou v ery much.. this solution is work! :) so, how can i get the schematic with the button to setup the date and time..? do y ou hav e that project..?
October 8, 2010 at 6:50 PM

m alik said... @hilmi wel come no i hav e not sch project including button to set the time Actually i used DS1 307 in big project where just one time time and date is being set by microcontroller commands and then RTC works for whole life.. but on internet buttons project for set and reset time is av ailable search for it thnx
October 8, 2010 at 6:56 PM

hilm i sa'ari said... @malik i already build this circuit with that source code. but i got some problem at circuit after rebuild for 3 times to get confirmation about this circuit.. 1 st, my LCD just show only one line of two.. thats mean just at upper line of LCD hav e show the 1 6 black square and at the second line, nothing display ..

2nd, if this CLOCK successful, the LED will be blinking..? thank y ou.. :)
October 9, 2010 at 11:28 A M

m alik said... chk ur circuit's connection place the cry stal for RTC v ery near to RTC. adjust the cry stal by hand so that display will be shown also chk ur programing software to burn in ucontroller.such as configration bits
October 10, 2010 at 1:10 A M

Anderson said... Please, i need y our help, like malik, i'v e made the schematic and the program but in the simulation appears Hour: 00:00:00 and Date: 00/00/2000 did someone fix that? THANKS
October 27, 2010 at 9:00 PM

m alik said... i hav e implemented it on hardware it works fy n. On proteus it works only with i2c dbugger. i2c debugger is present wt the place where oscilloscope is present in proteus. Do not waste ur ty m by simulating it on Proteus.. just direct implement it. thnx
October 28, 2010 at 12:57 A M

m alik said... Image for Proteus simulation: http://www.ziddu.com/download/1 2265522/RTC.png.ht ml


October 28, 2010 at 1:04 A M

m alik said... @anderson @all code and schematic is giv en below: http://www.ziddu.com/download/1 2265583/finalRTC.rar .html Pakistan Zindabad
October 28, 2010 at 1:09 A M

BeNg HuA said...

hi... can u write the sample of codes start from 0 until 9 for me to display on the LCD?
N ov em ber 24, 2010 at 11:13 PM

m alik said... for(i=0;i<=9;i++) { Lcd_Show(i); delay (200); {


N ov em ber 25, 2010 at 2:54 A M

lOnElY BoY ^^ said... hi ev ery one, help me to make add-ons to this circuit.. i will make an alarm clock that will based to the digital clock made... this is my first time to program to a chip. pls help me... here's my email address... please help me><....nex t week i need to prepare my presention..i need fast...please><..email me..meel_mjii91 @y ahoo.com
March 3, 2011 at 8:33 PM

m alik said... Dear this code works fine copy this code compile it and burn it in chip it works fine on hardware.i hav e used this.thnx
March 3, 2011 at 11:03 PM

Hasan said... just use 1 0khz for i2c it worked for me


May 19, 2011 at 4:25 A M

T EST E said... thank y ou for this post I used this code and worked fine in my pic1 6f87 7 a and ds1 307 best regards from Brazil
Septem ber 10, 2011 at 2:29 PM

par said... where is I2C_Rd function?????


Decem ber 20, 2011 at 4:34 PM

m alik said... @par i2c_rd() is built in function in mickroC compiler. If u want to search this in abov e code then do: Ctrl+f and search ur required function.
Decem ber 20, 2011 at 11:38 PM

Mith said... Hai, I would like to do a DIGITAL TIMETABLE DISPLAY SY STEM IN CLASSROOM with an alert at the end of each periods. I selected pic 1 6f87 7 a ic for this purpose. But I don't know the proper use of embedded c language. So,

could u please giv e the codes... I did't hav e any simple tutorial from internet to study the embedded c. I know the standard c language, but I am confused with some embedded c programs that i had seen on internet, so I need to study from the basics of embedded c. could u please giv e any suggestion.....
Jan u ary 26, 2012 at 3:22 A M

Marc P. said... Hello! Nice project! :) but i don't see any push-button to set the minutes etc.. where are they ? thank y ou so much! :) marC:)
March 5, 2012 at 3:00 A M

Marc P. said... Hello! Nice project! :) but i don't see any push-button to set the minutes etc.. where are they ? thank y ou so much! :) marC:)
March 5, 2012 at 3:01 A M

Marc P. said... Hello! Nice project! :) but i don't see any push-button to set the minutes etc.. where are they ? thank y ou so much! :) marC:)
March 5, 2012 at 3:01 A M

m alik said... sorry dear time set option is not present in abov e mine project.time is set only once in c code and then can be changed or set by again in c code.one can add time set option in this project.thnx
March 5, 2012 at 3:25 A M

SANJEEV said... v ery nice project...and thanks for posting the code...it will be nice if someone here add push buttons to set time....and share the code.. once again thanks to punkky ....
March 20, 2012 at 9:04 A M

nasser said... hey ....such a great post

i'v e been try ing to do this clock but the only compiler that i know how to use is the pic c compiler so can u help me and send me the source code in c....... thanks keep it up
A pri l 21, 2012 at 4:30 PM

sd sn said... This comment has been removed by the author.


Decem ber 25, 2012 at 10:47 A M

sd sn said... Hy e..Thankz for the code...it's help me a lot to do a project...hehe3,,but i hav e changed some code but it's works in hardware and not working in proteus i don't know why ...ahakz!! Software: Mikro C Pro for PIC v 5.6.1 Here the Code: // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_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 TRISB4_bit; sbit LCD_EN_Direction at TRISB5_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;

unsigned short read_ds1 307 (unsigned short address ); v oid write_ds1 307 (unsigned short address,unsigned short w_data); unsigned short sec; unsigned short minute; unsigned short hour; unsigned short day ; unsigned short date; unsigned short month; unsigned short y ear; unsigned short take; char time[9]; char ddate[1 1 ]; unsigned char BCD2UpperCh(unsigned char bcd); unsigned char BCD2LowerCh(unsigned char bcd); v oid main(){ I2C1 _Init(327 68); //DS1 307 I2C is running at 1 00KHz PORTB = 0;

TRISB = 0; // Configure PORTB as output TRISC = 0x FF; Lcd_Init(); // Initialize LCD connected to PORTB Lcd_Cmd(_Lcd_CLEAR); // Clear display Lcd_Cmd(_Lcd_CURSOR_OFF); // Turn cursor off Lcd_Out(1 , 1 , "TIME:"); Lcd_Out(2, 1 , "DATE:"); //Set Time write_ds1 307 (0,0x 80); //Reset second to 0 sec. and stop Oscillator write_ds1 307 (1 ,0x 1 0); //write min 27 write_ds1 307 (2,0x 01 ); //write hour 1 4 write_ds1 307 (3,0x 02); //write day of week 2:Monday write_ds1 307 (4,0x 05); // write date 1 7 write_ds1 307 (5,0x 01 ); // write month 6 June write_ds1 307 (6,0x 09); // write y ear 8 --> 2008 //09 write_ds1 307 (7 ,0x 1 0); //SQWE output at 1 Hz write_ds1 307 (0,0x 00); //Reset second to 0 sec. and start Oscillator while(1 ) { sec=read_ds1 307 (0); // read second minute=read_ds1 307 (1 ); // read minute hour=read_ds1 307 (2); // read hour day =read_ds1 307 (3); // read day date=read_ds1 307 (4); // read date month=read_ds1 307 (5); // read month y ear=read_ds1 307 (6); // read y ear time[0] = BCD2UpperCh(hour); time[1 ] = BCD2LowerCh(hour); time[2] = ':'; time[3] = BCD2UpperCh(minute); time[4] = BCD2LowerCh(minute); time[5] = ':'; time[6] = BCD2UpperCh(sec); time[7 ] = BCD2LowerCh(sec); time[8] = '\0'; ddate[0] = BCD2UpperCh(date); ddate[1 ] = BCD2LowerCh(date); ddate[2] ='/'; ddate[3] = BCD2UpperCh(month); ddate[4] = BCD2LowerCh(month); ddate[5] ='/'; ddate[6] = '2'; ddate[7 ] = '0'; ddate[8] = BCD2UpperCh(y ear); ddate[9] = BCD2LowerCh(y ear); ddate[1 0] = '\0'; Lcd_Out(1 ,6,time); Lcd_Out(2,6,ddate); Delay _ms(50); }

} unsigned short read_ds1 307 (unsigned short address) { I2C1 _Start(); I2C1 _Wr(0x d0); //address 0x 68 followed by direction bit (0 for write, 1 for read) 0x 68 followed by 0 --> 0x D0 I2C1 _Wr(address); I2C1 _Repeated_Start(); I2C1 _Wr(0x d1 ); //0x 68 followed by 1 --> 0x D1 take = I2C1 _Rd(0); I2C1 _Stop(); return(take); } unsigned char BCD2UpperCh(unsigned char bcd) { return ((bcd >> 4) + '0'); } unsigned char BCD2LowerCh(unsigned char bcd) { return ((bcd & 0x 0F) + '0'); } v oid write_ds1 307 (unsigned short address,unsigned short w_data) { I2C1 _Start(); // issue I2C start signal //address 0x 68 followed by direction bit (0 for write, 1 for read) 0x 68 followed by 0 --> 0x D0 I2C1 _Wr(0x D0); // send by te v ia I2C (dev ice address + W) I2C1 _Wr(address); // send by te (address of DS1 307 location) I2C1 _Wr(w_data); // send data (data to be written) I2C1 _Stop(); // issue I2C stop signal }
Decem ber 25, 2012 at 10:48 A M

Ov ais Iqbal said... My code works on Proteus fine ev en without I2C debug... but cant get it working on Hardware. My controller is fine programmer works good. All circuit connection are Ok. But cant get it running!
Febru ary 3, 2013 at 1:33 PM

Ov ais Iqbal said... if somebody can upload picture of breadboard or PCB, it might be helpful. Thanks
Febru ary 3, 2013 at 1:34 PM

Sebas said... to work in ISIS put the I2C DEBUGGER and it's work well in the schematic
Febru ary 8, 2013 at 12:00 PM

nev chits said... Thank y ou v ery Much!!!


Febru ary 20, 2013 at 3:48 A M

Dary l Herm oso said... Hi Im using y our code that posted form this thread. But when simulating the program, the time display on LCD was "January 01 ,2000" not the set date that was giv en on the code. Please nee a help
March 23, 2013 at 3:55 PM

Post a Com m en t

Links to this post


Create a Li n k

Save on ARM Micro's


www.futurlec.com Wide Range of ARM Controllers, Development Boards and Stamps

Newer Post

Home

Older Post

Subscribe to: Post Comments (Atom)

Web Blog Directory |||

Anda mungkin juga menyukai