PDA

View Full Version : Real time clock ICs



Eng4444
- 1st June 2006, 07:34
Hello,

i'm again search for Real time clock but this time, not for DS1307.

Could anyone provide me with any PicBasic Pro program for any real time clock IC used with any PIC?

i'll just buy both ICs and make my life easier... because i'm about to break my head with this DS1307 and PIC16F876A ...

sayzer
- 1st June 2006, 08:46
http://www.picbasic.co.uk/forum/showthread.php?t=423

Jerson
- 1st June 2006, 09:25
Hello,

i'm again search for Real time clock but this time, not for DS1307.

Could anyone provide me with any PicBasic Pro program for any real time clock IC used with any PIC?

i'll just buy both ICs and make my life easier... because i'm about to break my head with this DS1307 and PIC16F876A ...
This one is for the PCF8583 from Philips. Perhaps you can use this as a starting point to talk to either this device or a DS1307.

' Read the time in BCD format
RTC_GetTime:
I2Cread i2sda, i2scl, $A3, 2, [Second, Minute, Hour]
return

Jerson

BobK
- 1st June 2006, 13:35
Hello Eng444,

What's the problem? This forum has many examples of using RTC's including one back in Oct 2004 by Tonigalea that uses a DS1337. Paul Borgmier (sp? sorry) put 2 really nice RTC programs on this site last year that don't even use a separate RTC chip. I have tried them and they work very nice. They even have an alarm time example in them. I am on my 3rd project now using the DS1337 RTC. I use this as my projects need to keep accurate timing with a battery backup. I have even done routines to handle daylight savings time. I have used this RTC with a 16F88, 16F877A, and a 18F452. They are easy to work with but with everything else in life there is a learning curve. I found it very worth the time I invested.

There are also several examples of elapsed time counters here on this site from Darrel Tayor. Melanie has given us the Olympic Timer based on the 1302 RTC. She also has a clock program posted on the MELabs website.

Your post did not say specifically what your problem is. Some RTC's require converting data from the RTC from BCD to decimal. Paul Borgmier's clocks don't use this conversion. Tonigalea's DS1337 program doesn't use it.

Read through the posts here on this site and try a few things. Let us know more about the problem so we can help you! The people here are great and willing to help!

BobK.

Eng4444
- 1st June 2006, 14:10
I am working on a certain project and do not have any knowledge in RTC, nor how to program them. In fact, i just learned PicBasic Pro...

I have Pic16F876A and i am trying to manage to make my DS1307 work.

I Have read all the examples but as i am new to this thing, i didn't understand them...

i do not need alarms...etc etc i do not need it sophisticated at all. i am to calculate Energie which is given by: Energy = Power * time.

i already got power in a certain variable and now, i need to get the time elapsed in order to multiply by power...

any help?

BobK
- 1st June 2006, 14:49
Hi Eng 4444,

If you aren't looking for a "time stamp" of time and date then what you should try is Darrel Taylor's "Elapsed Timer" program on this site. Your program can control when to start timing and when to stop timing. Melanie's "Olympic Timer" is another example of a start and stop timer. You should look at these two programs. Both of them output the result to an LCD display. Both of these programs use a background timer using the PIC's timers. You can have your PIC do the calculations based on the inputs and then display the results.

The May 2006 issue of Nuts and Volts magazine has a nice tutorial on using PIC timers including a sample program that should help you out understanding how these timers are used. I believe this forum also has numerous posts relating to using PIC timers. I personally am just starting to use them so I wouldn't be much help in the actual design of one at this point. I just have a basic understanding of how they work.

sayzer
- 1st June 2006, 14:55
Also as BobK pointed in right direction, have the followings into consideration.

If you use RTC to calculate the elapsed time, you will have difficulties when time passes from one minute to other, or from one hour to other. You will be lost in HEX conversions to come with elapsed time.

I highly recommend using Melanie’s Olympic timer. It is already a timer just as you need, it is not an RTC.

It is quite easy to implement it into your PIC; even if you can’t use it with your PIC, have your energy calculation in your PIC by getting a signal from a separate PIC in which the Olympic timer is implemented.

Jumper
- 1st June 2006, 15:09
Hi,

If you dont use a backup battery for the 1307 make sure that the un-used leg for the backup function is tied to ground. You can find this in the datasheet but if this is not done the chip will not work properly (sometimes it doesn't, other times it does but never when you want it to).

We are using the 1307 and it is doing fine.


TRIS? = %00000000 ' all pins to output just replace ? with port name

SDA var Port?.? 'define port for I2C communication replace ?.? with pin
SCL var Port?.?

Hours var Byte
Minutes var Byte
Seconds var Byte
RTC var Byte
I2C_Adr_B var byte


RTC = % 11010000 ' Device adress on I2C bus
I2C_Adr_B=0

I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[128,0,0,0,0,0,0,128] 'Reset time to 0 and stopped, 12 hour setting

Start_RTC:
I2C_Adr_B=0
I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,16] 'Start RTC if you put a resistor and LED between the "SEC" pin and 5V it should start flash 1/s
return

RTC_Read:
I2C_Adr_B=0
I2CREAD SDA,SCL,RTC,I2C_Adr_B,[seconds,minutes, hours] ' in bcd code
return

call each part with a GOSUB

Good luck and enjoy

Eng4444
- 1st June 2006, 20:35
Hi,

If you dont use a backup battery for the 1307 make sure that the un-used leg for the backup function is tied to ground. You can find this in the datasheet but if this is not done the chip will not work properly (sometimes it doesn't, other times it does but never when you want it to).

We are using the 1307 and it is doing fine.


TRIS? = %00000000 ' all pins to output just replace ? with port name

SDA var Port?.? 'define port for I2C communication replace ?.? with pin
SCL var Port?.?

Hours var Byte
Minutes var Byte
Seconds var Byte
RTC var Byte
I2C_Adr_B var byte


RTC = % 11010000 ' Device adress on I2C bus
I2C_Adr_B=0

I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[128,0,0,0,0,0,0,128] 'Reset time to 0 and stopped, 12 hour setting

Start_RTC:
I2C_Adr_B=0
I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,16] 'Start RTC if you put a resistor and LED between the "SEC" pin and 5V it should start flash 1/s
return

RTC_Read:
I2C_Adr_B=0
I2CREAD SDA,SCL,RTC,I2C_Adr_B,[seconds,minutes, hours] ' in bcd code
return

call each part with a GOSUB

Good luck and enjoy
__________________________________________________ _____________

i wouldl ike to thank you so much! but now i returned home and far from my Lab. I will try it tomorrow. is it suitable for PIC16F876A? and by the way, how to set the date and time to: "10:15:30 01-06-2006 "? can you tell me how and in which part of your program?

thank you again....

BobK
- 2nd June 2006, 01:39
Hi Eng4444,

The simplest way is to set those values as the variables for hours, minutes, seconds, month, date, year and then write them into the RTC. Obviously the minutes setting should be a few minutes ahead of the actual start time to allow you time to program the PIC and then put it into your board and start the board up. That's what I do to start the clock on my boards.

BobK

Jumper
- 2nd June 2006, 02:32
Hi,

Just to be really sure. Don't forget to put pullup resistors 4k7 between [SDA --> 5V] and [SCL --> 5V].

Another thing we have seen is that adding "DEFINE I2C_SCLOUT 1" (this makes the SCL line bipolar) can help if there is a lot of noice in your set up. This is not the solution for a bad design just a way to try to get the best possible chance to communicate with the 1307.

I am sure that as soon as you get the chip to respond your learning curve will go thru the roof.

Eng4444
- 2nd June 2006, 04:11
I'll try all of this in 4 hours... i really hope it will work!!

Eng4444
- 2nd June 2006, 04:28
Hi Eng 4444,

should try is Darrel Taylor's "Elapsed Timer" program on this site. Your program can control when to start timing and when to stop timing. Melanie's "Olympic Timer" is another example of a start and stop timer. You should look at these two programs.


__________________________________________________ ______________

Sorry but where to find those 2 programs on this website? in which section?

BobK
- 2nd June 2006, 13:10
Hi Eng4444,

From this forum's main menu select CODE EXAMPLES. There you will find the following items:

1) Olympic Timer
2) Easy & Accurate Clocks without RTC ICs
3) Elapsed Timer Demo

Of the three, #2 is the only one that I personally have tried. But you should look at all three programs and decide which one you want to use. They are all easy to understand.

BobK

Eng4444
- 3rd June 2006, 09:12
call each part with a GOSUB

Good luck and enjoy

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++

What do you mean by this?

could anyone explain to me?

of course i need it to show constantly the time and keep on incrementing seconds, minutes, hours, days...

so what is this GOSUB? and how to use it?
One more things, what to do if i want to set time and date as:
02:10:00 3-6-2006?

where to write them?in which sentence?

urgent help is needed because i am working right now on this...

BobK
- 3rd June 2006, 12:46
Hi ENG4444,

What Jumper is referring to with the GOSUB is that the routines "Start_RTC" and "RTC_Read" are called from your main program. Read the PBP manual referring to the word "GOSUB" for a further explanation.

The clock setting portion is, as I stated in an earlier reply, is handled in the setup of the clock. You put these values in the variables for the clock, meaning "seconds", "minutes", "hours", etc then write them into the RTC.

It really sounds to me that you are in such a panic to get this project done by 9am Monday morning that you can't slow down and pay attention to what we are trying to say to you. You have posted on several sections of this forum with different requests. One request is for an RTC for a clock. Another post says you need elapsed time. Several of us have provided you with the information you requested. So now what do you want? We are here to help you but from your ongoing statements you aren't learning anything or really don't understand what is being given to you.

Sit back and put your feet up in the air and relax for a few minutes. Re-look at the information we have provided. Try a few of the example programs that have been provided to you and see what they may or may not do for you.

Maybe you should post some of the code you have so far and give us a schematic to look at. I can feel the panic in your requests. We want to help but can only go so far here!

BobK

The example programs are documented as to what each portion of the program is doing. Look at them and they will show you where to enter the values for setting the clock.

Eng4444
- 4th June 2006, 05:37
Maybe you should post some of the code you have so far and give us a schematic to look at. I can feel the panic in your requests. We want to help but can only go so far here!


__________________________________________________ _______________

To tell you the truth, i have right now 15 programs related to real time clock and elapsed time and i'm not able to use any of them...

as i said before, i don't know anything about PicBasic Pro, nor PIC, nor RTC. I just got stuck with this situation and should make it pass.. i'm simply a biomedical engineer..

so for example, i'll tell you what i did yesterdsay night. This is a program from Melanie (thanks Melanie for providint such important program) :

http://www.melabs.com/resources/samples/submitted/MN1307.txt

i will not paste it here because it's too long...
but she's using PIC16F628. For me, i didn't find it; i found 16F628A which must be similar.... right?

i did the circuit as she was saying (bought 2 Lines LCD), connetions to PIC and for DS1307, there was a suspicious part in some lines she wrote:

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++
" ' 10K Resistors required from PORTB.1 and PORTB.2 to Vdd
' PORTB.0 relies on weak pull-up's (for future use)
'
SQWpin var PORTB.0
' You don't actually need to wire this pin... but...
' If you're observant, you'll notice I've wired the DS1307's
' SQW to RB0. Rather than 'poll' and display the time/date
' as in this example code, you can have an interrupt
' on RB0 each second to do this. In fact if you look at
' my code for setting the DS1307 you'll see I've already
' programmed it for a 1 second 'Tick' for exactly this
' purpose...
SCLpin var PORTB.1
SDApin var PORTB.2
'
' Setting Buttons
' ---------------
' Buttons are connected between PORTB.4, 5 & 6 down to Vss
' No Resistors required - we're using weak pull-up's
'
DecButton var PORTB.4 ' Press to Decrement Button
SetButton var PORTB.5 ' Press to Set/memorise Button
IncButton var PORTB.6 ' Press to Increment Button
"

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++

so i just "connected": SQWpin of DS to PORTB.0
SCLpin to PORTB.1
SDApin to PORTB.2
and for ports B.4 ,B.5 and B.6, i have put "push buttons" to ground.
and also i have put 10K resistors as she said.

so i got the same unused ports that she mentioned and was happy because i felt that it will work!

now the programming section came....

i just copied and pasted the whole program on PicBasic Pro, compiled it, things were fine.

Then, using the programmer (i'm using ICPROG), i put the PIC, chose 16F862A and programmed but it gave:
"verify error at location 0000xH"

so i retuend to the program and paid attention to some sentences Melanie wrote in the beginning:
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F628, WDT_ON
' Watchdog Timer
@ DEVICE pic16F628, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic16F628, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F628, PROTECT_OFF
' Program Code Protection
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
i tried to add "A" near each "8" but didn't work... so i noticed that i am already doing these setting from ICPROG (by checking what i need) so i removed all this section and programmed without it. It worked.

it was time to test..

LCD is just giving black rectangles.. nothing else :-( :-( !!!!

i don't know what to do... i downloaded all this program to PIC... we do not program DS1307 also? no program should be inserted inside it?

i also used a crystal for it... 32.768 as i remember...

so here it is, i explained one case...and i previously fell in many previous similar cases... no one here around me is ready to help so i just thought that maybe i can find help on the internet. This is why i am sending many posts.... i should finish this whole work by next friday... i'm working on the biomedical part and do not have too much time to sit, read manual, try exercises, build more circuits and test.... i can't lay my legs Bob! i'm working on this project 20 hours a day since 3 months! can you beleive it? so i "really" cannot sit and just be in the mood to learn PicBasic Pro and I2c and RTC.....

in case someone would be able to help i'll be grateful..

Eng4444
- 4th June 2006, 05:50
you said:

"
"What Jumper is referring to with the GOSUB is that the routines "Start_RTC" and "RTC_Read" are called from your main program. Read the PBP manual referring to the word "GOSUB" for a further explanation.

The clock setting portion is, as I stated in an earlier reply, is handled in the setup of the clock. You put these values in the variables for the clock, meaning "seconds", "minutes", "hours", etc then write them into the RTC. "
__________________________________________________ ______________

So do you mean that i should write all the program:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

TRIS? = %00000000 ' all pins to output just replace ? with port name

SDA var Port?.? 'define port for I2C communication replace ?.? with pin
SCL var Port?.?

Hours var Byte
Minutes var Byte
Seconds var Byte
RTC var Byte
I2C_Adr_B var byte


RTC = % 11010000 ' Device adress on I2C bus
I2C_Adr_B=0

I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[128,0,0,0,0,0,0,128] 'Reset time to 0 and stopped, 12 hour setting

Start_RTC:
I2C_Adr_B=0
I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,16] 'Start RTC if you put a resistor and LED between the "SEC" pin and 5V it should start flash 1/s
return

RTC_Read:
I2C_Adr_B=0
I2CREAD SDA,SCL,RTC,I2C_Adr_B,[seconds,minutes, hours] ' in bcd code

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

in the PIC16F876A directly and it works?

let's say i want to chose port B and pin 22 which is RB1
23 which is RB2
so i write:
TRISB = %00000000
SDA var PortB.1
SCL var PortB.2
true?
and i wire b.1 to sda of DS, B.2 to SCL DS.... right?



Now tell me, if i just connect PIC16F876A to this DS1307 and a 4 lines LCD (or 2 lines). and let's say i just want to use this whole PIC just for the DS (it's stupidity i know but let's say i will keep all ports not used) would this program, as he gave it to me, be enough to begin displaying time and date on LCD? or i should write more things that he didn't write thinking that i should know them..... ?

Melanie
- 4th June 2006, 08:45
Since my original program was configured for a 4-Line LCD (which extensively used the LCDOut command), and you're using a 2-Line LCD which does not, unless you make significant changes to the program to compensate for the difference it's not exactly going to work, is it?

You might need to be aware, that a 2-Line LCD communicates by SERIAL asynchronous. For reliability your PIC will ideally need to be driven by an Xtal or Resonator and not rely on the Internal Oscillator. See Thread...

http://www.picbasic.co.uk/forum/showthread.php?t=3966&highlight=Internal+Oscillator

A 4 or 8-wire connected LCD does not have this limitation.

You obviously haven't a clue as to what you're doing. With your level of expertise, unless you EXACTLY replicate programs and hardware examples that are posted - without changes, your chances of success are slim to none.

Let me put this into perspective... I catch a Cold. I therefore go into a BioMed Lab to devise a cure. I only need to cure my Cold, and then I will never set foot in a BioMed Lab ever again. I give myself a week to accomplish this... I am not a Doctor or a Scientist or even a BioMed Technician. All I know is that the Plasma they drip into your arm is the same stuff that drives the Starship Enterprise...

Eng4444
- 4th June 2006, 09:01
I already said that i have no clue...

i have LCD 4 lines so i will try it....

Eng4444
- 4th June 2006, 21:47
This DS1307... we do not program it? just access it from PIC?

A Professor here said that i am obliged to program it... one of us is stupid so who is it?


for me, i have read so many examples but i never noticed that i should program a DS1307.... i just have to connect it to PIC and then access it by the program..

Am i mistaken?

Travin77
- 4th June 2006, 22:57
I think that the professor is using "program" loosely. You will write the time and date therby "programming it".

Travin

Archilochus
- 5th June 2006, 00:43
There are also a few control bits that might need configuring - 12/24 hour mode, square wave output & rate, and a whopping 56 bytes of "NV"RAM for you to use... guess those could also fall into the "program" category :-)

Arch

Melanie
- 5th June 2006, 01:26
>A Professor here said that i am obliged to program it... one of us is stupid so who is it?

Have you read the DS1307 Datasheet?

If you haven't then GO DO IT before you ask questions like the one above.

You will discover that when you first Power-Up a DS1307 for the first time (regardless if you have a Battery Backup connected or not), it sits there and DOES NOTHING until you enable it by clearing the CH (Clock Halt) bit in one of it's Registers (which Bit in which Register I leave you to discover by READING the device Datasheet). That Sir is called "programming" - apart from that, how's the chip supposed to know what the current Time and Date is from which to continue timing? Telepathy?

People who can't be bothered to read Datasheets or Manuals and expect everyone else to do their work for them usually get short changed on this forum.

Eng4444
- 5th June 2006, 20:10
He apologised today... he meant by "programming" the real meaning and not as many expected.. Simply, he meant that i should put all the program inside DS1307.... i think he didn't have any idea about this DS...

anyway, life continues.... i'm about to present my project on friday.Still delaying this matter of timer because it makes me nervous! have i ever said that i designed a new instrument that analyzes blood, saliva and bones at the same time?

It's so useful and i am working now on reducing it's size... i'm using MEMS technlogy in case anyone is interested.

This is why i'm so squeezed by time and do not have time to read any discover new and silly datasheets.... time is treasure and i cannot lose it.

So if this timer does not work it doesn't matter but i just hope it will work so that i can display time and date on the screen or maybe put a timer to be used by patients.

Eng4444
- 5th June 2006, 20:47
It is located at:

http://www.melabs.com/resources/samples/submitted/MN1307.txt

for those who are interested.

No more fabrication of PIC 16F628 or 16F876, and this is worldwide done. It's same case for other PICs. They are being replaced by 16F628A and 16F876A.

so, can this program be used directly on a pic 16F628A without facing any problem or changing any code?

I will try it on a 4-line LCD but i just want to know about the PIC... yesterday, Melanie gave me a way to stop the comparators on 16F876A. So should something be done for this 16F628A?

thank you.

Archilochus
- 6th June 2006, 00:02
Somewhere at the Microchip website you'll find some 'silly' documents about migrating to new (or improved) devices. Oh no... one more thing to read =:-0

Arch

rcbandwidth
- 6th June 2006, 02:47
Eng4444:What kind of Engineer will you be if all you want to do is copy someone elses work as pass it off as your own?,Why would any company want to hire someone who has this mindset?...You are trying to run before you can walk.Melanie and others in this forum have bent over backwards trying to help you,a lack of preparation on your part has gotten you into this situation,As a Bio-med engineer you should have a little more enthusiasm about learning some basic programming techniques in order to complete your academic assignments.

Get to Work!!!
R.C

Eng4444
- 6th June 2006, 03:49
In the program located at http://www.melabs.com/resources/samp...ted/MN1307.txt

should i change something in the code if i wanna use PIC16F628A? because i already read somewhere in the forum a certain discussion that there shouldn't be difference but i just want to be sure.

best regards.

Eng4444
- 6th June 2006, 03:53
i wonder how i was told that:

" Since my original program was configured for a 4-Line LCD (which extensively used the LCDOut command), and you're using a 2-Line LCD which does not, unless you make significant changes to the program to compensate for the difference it's not exactly going to work, is it? "

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++

But if somehow someone focused on what i was saying it would have been nicer..i'm not asking to just receive any answers...

i was talking about the program located at:

http://www.melabs.com/resources/samples/submitted/MN1307.txt

there, it is written that:
"
' Written for 2 line 16 Character LCD
"

and i tried it like this but with a PIC16F628A and didn't work.

This is why i will ask again if i should do some changes to the program; and what are they?

thank you.

Jumper
- 6th June 2006, 04:10
Hi,

I think Melanie in her remarks in her program was reffering to a LCD with 2 rows and 16 characters on each row (2*16 LCD). Melanie usually uses as little special hardware as possible so she probably just pulled up the most common LCD from her magic drawer. This LCD is electrically connected to the PIC using 4 data lines (and some more) which are mentioned in the LCDOUT command.

If you have 2 cables to the LCD (plus power) is is probably a serial LCD which can not be used using the LCDOUT command.

Hard to tell without haveing the schematics and really understanding what you whish to do.

Eng4444
- 6th June 2006, 04:22
i can have any LCD i want. This is not a problem.

now i have 2:
Winstar WH1602A ( 2 lines, 16 char) and WINSTAR WH160A (4 x 16).

and they are both parallel as i think... right? to assure you, check:

winstar.com.tw

so this is the 2 lines 16 char LCD i used and the program didn't work.

Still again asking: should i change something related to PIC16F628A?

thank you.

keithdoxey
- 6th June 2006, 09:51
LCD is just giving black rectangles.. nothing else :-( :-( !!!!


Have you adjusted the contrast correctly.

At one extreme it will display nothing, at the other extreme it will display black rectangles. Somewhere inbetween it will display the characters correctly.

Melanie
- 6th June 2006, 12:09
> Still again asking: should i change something related to PIC16F628A?

If I don't know the answer to questions like will my program work on a 16F628 as well as a 16F628A... I would...

1. Download both Datasheets and compare them...

2. Create a simple program to display "I must learn to study Datasheets" on my LCD and compile it for a standard 16F628. I would then burn an 'A' version with that code and checked if it would still work.

But that's me... you on the other hand would rather ask the same questions over and again on the forum... hint... if you tried option 2, you'd discover the answer in less than 15 minutes...

Even Drugs and Chemicals have Datasheets - and you would use one of those without checking the Datasheet first?



'
' Device Programming Options
' --------------------------
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F628, WDT_ON
' Watchdog Timer
@ DEVICE pic16F628, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic16F628, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F628, PROTECT_OFF
' Program Code Protection

'
' Hardware Defines
' ----------------
'
' LCD Display
' -----------
Define LCD_DREG PORTB ' Port for LCD Data
Define LCD_DBIT 4 ' Use upper 4 bits of Port
Define LCD_RSREG PORTB ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 3 ' Port Pin for RS bit
Define LCD_EREG PORTB ' Port for Enable (E) bit
Define LCD_EBIT 2 ' Port Pin for E bit
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 2 ' Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)

'
' Software Defines
' ----------------
CounterA var BYTE
CounterB var BYTE
CounterC var BYTE
DataA var BYTE

'
' EEPROM Contents
' ---------------
Data @0,"I must learn not to be lazy and to read Datasheets!"

'
' Initialise PIC
' --------------
TRISA=%00000000 ' PortA all OUTPUT
TRISB=%00000000 ' PortB all OUTPUT
CMCON=%00000111 ' Comparators OFF

'
' Main Program
' ------------
Pause 2000 ' Timeout for LCD Hardware to wake-up...
LCDOut $FE,1 ' Clear Display
Loop:
For CounterA=0 to 35
Gosub DisplayMessage
Next CounterA
Pause 1000
For CounterA=35 to 0 step -1
Gosub DisplayMessage
Next CounterA
Pause 1000
Goto Loop

'
' Subroutine Displays Scrolling Message
' -------------------------------------
DisplayMessage:
LCDOut $FE,$80
For CounterB=0 to 16
CounterC=CounterA+CounterB
Read CounterC,DataA
LCDOut DataA
Next CounterB
Pause 500
Return

End

If the above doesn’t work for you, then there are still career openings in Landscape Gardening…

Eng4444
- 7th June 2006, 04:42
Well that's simple!

Without landscape gardening, nobody would have remained alive!!

and that's a "TRUTH".

Perhaps you people eat PIC16F876, PIC16F876A, PIC16F628, PIC16F628A, PIC16F88...... several delicious different vegetables and fruits! yeah?

Maybe if just one of you read well what i was writing withouth playing the intelligent, would have understood what i was saying each time...


Thank you for your cooperation.
Sam.

BobK
- 7th June 2006, 12:59
Hello again Eng4444,

It's nice to see that you are still here. Just to give a further example of what we are all trying to say to you, I just put the program that Melanie had just posted into an older project board of mine. Her program puts the LCD on PortB. Well my LCD is on PortA. So I made some minor changes to the program and tried it. It didn't work! Her program is for a 16F628 and I had a 16F872. I commented out the DEVICE setup and chose to set the configuration fuses through my programmer. Still didn't work. I only got blocks on line 1 of the LCD. So I opened the datasheet on the 16F872 and went to the section on the A/D module and found in the register explanation how to disable the A/D module and how to make the Analog pins all digital. Programmed the chip again and now the message scrolls across the screen!

Now before you go and say what a smart ass you are let me explain that I do not have any degree in ANYTHING' I am a self employed alarm installer. I play with electronics for fun and once in a while I might make a few bucks making something to get the job done.

I read this forum faithfully and pay attention to what the real pros like Melanie, Mister E, David Taylor, and the many other fine folks have to say when they offer their advise and expertise to someone. I really haven't gotten involved with anyone here to the extent that I have with you because I don't want to say or do something stupid. I don't think that you gave anyone here that has responded to you a fare shake. You say I dropped out. Well I didn't. I was reading everything. I read this forum at least twice a day and if I'm at a place that has internet access then I use my Dell handheld and go on to see what's up. If it wasn't for this forum and the fine people here I wouldn't have the knowledge I have today.

By the way, I started at 7:15 this morning working on that little display program and was up and running including the troubleshooting in less than 1/2 hour. I keep the datasheets for the parts I use on my computer so that they are handy. The most frequently posted comment is read the datasheet. You don't have to read it like a novel, just refer to it once in a while. I know you are pressed for time so I won't hold you up. Good luck on you project! I have to goto work.

Have a nice day!

BobK

Eng4444
- 7th June 2006, 18:38
i would say and repeat to you people:

I DO NOT WORK WITH THIS TYPE OF TECHNOLOGY!!

why no one understands??? i work with MEMS!!!!!!!! i already said it.....

stop talking to me as if i'm a stupid intruder... you have your world and i have mine.. you are EXPERTS in PICs (this is why i came to you).

and i am EXPERT in MEMS! ( in case someone needs anything related to MEMS i'll be ready!)

Bobk, i checked your profile. I respect you very much but you made me nervous when you kept asking me to give details and schematics! So, i'm sorry to talk in a bad way to you.

So here it is... a chematic! i did it with paint because with circuit builder it exceeds the attachement size. Those are the exact connections i did on Breadboard and then on PCB.

And also, here is the program i used ( the same of Melanie):

@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F628A, WDT_ON
' Watchdog Timer
@ DEVICE pic16F628A, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628A, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628A, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic16F628A, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628A, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F628A, PROTECT_OFF


Define LCD_DREG PORTA ' Port for LCD Data
Define LCD_DBIT 0 ' Use lower 4 bits of Port
Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 6 ' Port Pin for RS bit
Define LCD_EREG PORTA ' Port for Enable (E) bit
Define LCD_EBIT 7 ' Port Pin for E bit
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 2 ' Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)


SQWpin var PORTB.0
SCLpin var PORTB.1
SDApin var PORTB.2

DecButton var PORTB.4
SetButton var PORTB.5
IncButton var PORTB.6

Data @0,74,97,110,70,101,98,77,97,114,65,112,114
' Jan Feb Mar Apr
Data 77,97,121,74,117,110,74,117,108,65,117,103
' May Jun Jul Aug
Data 83,101,112,79,99,116,78,111,118,68,101,99
' Sep Oct Nov Dec
Data 84,117,101,87,101,100,84,104,117,70,114,105
' Tue Wed Thu Fri
Data 83,97,116,83,117,110,77,111,110
' Sat Sun Mon

CounterA var byte
CounterB var byte
CounterC var byte
CounterD var byte
RTCSec var byte
RTCMin var byte
RTCHour var byte
RTCWDay var byte
RTCDay var byte
RTCMonth var byte
RTCYear var byte
RTCCtrl var byte
SetTime var byte
SetSec var byte
SetMin var byte
SetHour var byte
SetDay var byte
SetMonth var byte
SetYear var byte
TimeOut var word

ButtonRepeat con 200
goto JumpStart

ConvertBCD:
CounterB=CounterA DIG 1
CounterB=CounterB<<4
CounterB=CounterB+CounterA DIG 0
Return

DisplayMonth:
CounterB=CounterB*3-3
DisplaySequence:
For CounterA=CounterB to CounterB+2

Read CounterA,CounterD
LCDOut CounterD
Next CounterA
Return

FindDays:
LookUp SetMonth-1,[31,28,31,30,31,30,31,31,30,31,30,31],CounterA
' Above line gives the 'usual' days of the Month
' Section below adjusts for Leap-Year
If SetMonth=2 then
If (SetYear&$03)=0 then CounterA=29
endif
Return

SetButtonRelease:
LCDOut $FE,1
While SetButton=0:Wend
Pause 250 ' Small pause to kill any Key-Bounce
Return

JumpStart:
CMCON=%00000111
TRISA=%00000000
TRISB=%11111111
OPTION_REG.7=0
Pause 200

ReDisplay:
LCDOut $FE,1
ReDisplayLoop:

I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl]

If RTCSec.7=1 then goto SetUpPreset

If SetButton=0 then
Gosub SetButtonRelease
goto Setup
endif

LCDOut $FE,$80
If RTCHour.6=1 then

CounterA=(RTCHour>>4)&$01
else
CounterA=(RTCHour>>4)&$03
endif
CounterA=CounterA*10+(RTCHour&$0F)
If RTCHour.6=1 then

LCDOut #CounterA
else
LCDOut #CounterA Dig 1,#CounterA Dig 0
endif
LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
IF RTCHour.6=1 then
If RTCHour.5=1 then
LCDOut "PM"
else
LCDOut "AM"
endif
endif

LCDOut " ",$FE,$C0
CounterB=RTCWDay*3+33
Gosub DisplaySequence

LCDOut " ",#(RTCDay>>4)&$0F,#RTCDay&$0F," "
CounterB=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
Gosub DisplayMonth
LCDOut " 20",#(RTCYear>>4)&$0F,#RTCYear&$0F,$FE,$80
'
Pause 250
Goto ReDisplayLoop

SetupPreset:
RTCSec=$00
RTCMin=$15
RTCHour=$13
RTCWDay=$01
RTCDay=$12
RTCMonth=$06
RTCYear=$02
RTCCtrl=$10

Setup:
SetTime=RTCHour.6
If SetTime=1 then

SetHour=(RTCHour>>4)&$01

else
SetHour=(RTCHour>>4)&$03

endif
SetHour=SetHour*10+(RTCHour&$0F)
If SetTime=1 then
If RTCHour.5=1 then
If SetHour<12 then SetHour=SetHour+12

else
If SetHour=12 then SetHour=0
endif
endif
SetMin=((RTCMin>>4)&$0F)*10+(RTCMin&$0F)
SetSec=((RTCSec>>4)&$0F)*10+(RTCSec&$0F)
SetYear=((RTCYear>>4)&$0F)*10+(RTCYear&$0F)
SetMonth=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
SetDay=((RTCDay>>4)&$0F)*10+(RTCDay&$0F)

CounterC=0
TimeOut=0
SetupLoop:
LCDOut $FE,1,"Set "

If CounterC=0 then
LCDOut "Mode"
endif
If CounterC=1 then
LCDOut "Hours"
endif
If CounterC=2 then
LCDOut "Minutes"
endif
If CounterC=3 then
LCDOut "Seconds"
endif
If CounterC=4 then
LCDOut "Year : 20"
endif
If CounterC=5 then
LCDOut "Month"
endif
If CounterC=6 then
LCDOut "Day"
endif
If CounterC<>4 then LCDOut " :"

SetupDisplayLoop:
If CounterC=0 then
LCDOut $FE,$8B
If SetTime=0 then
LCDOut "24HR"
else
LCDOut "12HR"
endif
LCDOut $FE,$8B
endif
If CounterC=1 then
CounterA=SetHour
If SetTime=1 then
LCDOut $FE,$8E
' Display AM/PM bit
If CounterA<12 then
LCDOut "AM"
else
LCDOut "PM"
endif
If CounterA=0 then CounterA=12
If CounterA>12 then CounterA=CounterA-12
endif
LCDOut $FE,$8C,#CounterA
If CounterA<10 then LCDOut " "
LCDOut $FE,$8C
endif

If CounterC=2 then
LCDOut $FE,$8E,#SetMin
If SetMin<10 then LCDOut " "
LCDOut $FE,$8E
endif

If CounterC=3 then
LCDOut $FE,$8E,#SetSec
If SetSec<10 then LCDOut " "
LCDOut $FE,$8E
endif

If CounterC=4 then
LCDOut $FE,$8D,#SetYear DIG 1,#SetYear Dig 0
LCDOut $FE,$8D
endif

If CounterC=5 then
LCDOut $FE,$8C
CounterB=SetMonth
Gosub DisplayMonth
LCDOut $FE,$8C
endif
'
' Day
' ---
If CounterC=6 then
LCDOut $FE,$8A,#SetDay
If SetDay<10 then LCDOut " "
LCDOut $FE,$8A
endif

SetupEntryLoop:

If DecButton=0 then

If CounterC=0 then
If SetTime=0 then
SetTime=1
else
SetTime=0
endif
endif
'
' Decrement Hours
' ---------------
If CounterC=1 then
If SetHour=0 then
SetHour=23
else
SetHour=SetHour-1
endif
endif
'
' Decrement Minutes
' -----------------
If CounterC=2 then
If SetMin=0 then
SetMin=59
else
SetMin=SetMin-1
endif
endif
'
' Decrement Seconds
' -----------------
If CounterC=3 then
If SetSec=0 then
SetSec=59
else
SetSec=SetSec-1
endif
endif
'
' Decrement Years
' ---------------
If CounterC=4 then
If SetYear=0 then
SetYear=99
else
SetYear=SetYear-1
endif
endif
'
' Decrement Month
' ---------------
If CounterC=5 then
If SetMonth=1 then
SetMonth=12
else
SetMonth=SetMonth-1
endif
Gosub FindDays
If SetDay>CounterA then SetDay=CounterA
endif
'
' Decrement Days
' --------------
If CounterC=6 then
Gosub FindDays
If SetDay=1 then
SetDay=CounterA
else
SetDay=SetDay-1
endif
endif
Pause ButtonRepeat
TimeOut=0
Goto SetUpDisplayLoop
endif

If IncButton=0 then

If CounterC=0 then
If SetTime=1 then
SetTime=0
else
SetTime=1
endif
endif
'
' Increment Hours
' ---------------
If CounterC=1 then
If SetHour=23 then
SetHour=0
else
SetHour=SetHour+1
endif
endif
'
' Increment Minutes
' -----------------
If CounterC=2 then
If SetMin=59 then
SetMin=0
else
SetMin=SetMin+1
endif
endif

If CounterC=3 then
If SetSec=59 then
SetSec=0
else
SetSec=SetSec+1
endif
endif
'
' Increment Years
' ---------------
If CounterC=4 then
If SetYear=99 then
SetYear=0
else
SetYear=SetYear+1
endif
endif
'
' Increment Month
' ---------------
If CounterC=5 then
If SetMonth=12 then
SetMonth=1
else
SetMonth=SetMonth+1
endif
'
Gosub FindDays
If SetDay>CounterA then SetDay=CounterA
endif
If CounterC=6 then
Gosub FindDays
If SetDay=>CounterA then
SetDay=1
else
SetDay=SetDay+1
endif
endif
Pause ButtonRepeat
TimeOut=0
Goto SetupDisplayLoop
endif
'
' Set Button Pressed
' ------------------
If SetButton=0 then
CounterC=CounterC+1
' Increment Menu Item
TimeOut=0
If CounterC>6 then
' Save Data if all edit items exhaused
LCDOut $FE,1,"Memorised"

Eng4444
- 7th June 2006, 18:39
CounterA=SetHour
If SetTime=1 then
If CounterA>12 then CounterA=CounterA-12
If CounterA=0 then CounterA=12
endif
Gosub ConvertBCD
RTCHour=CounterB
' Save the Hours Value
If SetTime=1 then
RTCHour.6=1
' Save the 12 Hour Mode Flag
If SetHour=>12 then RTCHour.5=1
' Save the 'PM' Flag
endif
'
' Save Minutes
' ------------
CounterA=SetMin
Gosub ConvertBCD
RTCMin=CounterB
'
' Save Seconds
' ------------
CounterA=SetSec
Gosub ConvertBCD
RTCSec=CounterB
'
' Save Year
' ---------
CounterA=SetYear
Gosub ConvertBCD
RTCYear=CounterB
'
' Save Month
' ----------
CounterA=SetMonth
Gosub ConvertBCD
RTCMonth=CounterB
'
' Save Day
' --------
CounterA=SetDay
Gosub ConvertBCD
RTCDay=CounterB
CounterA=SetYear+4
CounterB=SetMonth
If SetMonth<3 then
CounterA=CounterA-1
CounterB=CounterB+12
endif
CounterD=(SetDay+(153*CounterB-457)/5+365*CounterA+CounterA/4-CounterA/100+CounterA/400+2) MOD 7
RTCWDay=CounterD+1
'
' Do the Business
' ---------------

I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl]
Pause 1000
Gosub SetButtonRelease
Goto ReDisplay
endif
Gosub SetButtonRelease
Goto SetupLoop ' Loop for Next Menu Item
endif


Pause 1 ' Kill 1mS
TimeOut=TimeOut+1
If TimeOut>20000 then goto ReDisplay

End

Eng4444
- 7th June 2006, 19:00
i did the same connections shown in the shematic , downloaded the same program (that is displayed here) inside PIC16F628A, gave 5VDc and checked the connections again. But i didn't see anything on LCD.......

I even added a variable resistor (10 K) for the contrast of LCD and fixed the light in the middle position.

SO now, you will keep on saying that i have to read datasheets??

or you will try to help me in an effective way?

i finished my MEMS laboratory and sent it to canado to be manifactured :-D

Friday i will present it in front of jury and MONDAY..... i'll graduate :-) and since then, i'll pass a whooooooole month in the Carribean!

But right now, since i am used to pressure of work, i'll continue and work on this real time clock. But not now.... during the last month i was sleeping only 4 hours daily and then, working 20 hours on this project non-stop , with just 30 minutes of break for each day.... imagine this situation!!?

so i will just sleep......

Please guys, take it into consideration and check that schematic and program... tomorrow i'll be well awake so i'll concentrate on your replies and try to accomplish what you told me to do..

But please, please , please........ stop talking about datasheets...

By the way:

"The California Dept of Fish and Game is advising hikers, hunters and fishermen to take extra precautions and keep alert for bears while in the Yosemite and Mammoth areas.

They advise people to wear noise-producing devices such as little bells on their clothing to alert but not startle the bear unexpectedly. They also advise carrying pepper spray in case of an encounter with a bear. It is also a good idea to watch for fresh signs of bear activity and know the difference between black bear and grizzly bear droppings. Black bear droppings are smaller and contain berries and possibly squirrel fur. Grizzly bear droppings have little bells in them and smell like pepper spray." :-)

BobK
- 7th June 2006, 19:50
Hi Eng4444,

I wasn't trying to make you nervous by asking for drawings and code work. It just makes it easier to figure out what is going on. At first glance of the schematic I see the following:

1) I think your LCD data lines are wrong. You should tie lines DB0 thru DB3 to ground then starting with DB4 tied to RA.0, DB5 to RA.1, DB.6 to RA.2 and DB7 to RA.3. The Read/Write pin on the LCD needs to go to ground. I tried to get the Datasheet (don't you just love it?) from Winstar but you have to signup with them to get these and I'm waiting to hear back from them so I can verify these connections when using a 4 bit bus. The couple of types of LCDs and VFDs I use start with DB4 when using 4 line bus connections.

2) Pin 3 on the DS1307 needs to go either to a backup battery or tied to ground if you're not using the battery.

3) You should change the pull up resistors on the SCL and SDA lines from 10K to 4.7K.

4) I realize you had a hard time getting this drawn out but I don't see any capacitors. You need a .1uF on the power supply lines of EACH device as close to the device as possible. You should also have a .1uF and a 10uF on each side of the voltage regulator if that's how you are powering this project.

You did mention that you have a potentiometer connected to the contrast pin of the LCD. I didn't see that on the drawing.

Start with the above and try the program above. This may just take care of your problem. I have not sat down with the code. I trust that you have checked and rechecked that. Keep in mind that a single character wrong somewhere can keep it from working correctly. Someone recently had LCBOUT instead of LCDOUT. Big difference!

Good luck!

BobK

Eng4444
- 7th June 2006, 20:30
Hello again :-)

i just wanted to check befor sleeping if someone has answered. and Here i found yours BobK.

thank you for the notes. I'll take them into consideration tomorrow.

Here i attached the datasheet for you. So don't wait for winstar... sometimes they take lot of time.

i hope i provided you with everything.

By the way,

the matter of variable resistor wasn't included because i just forgot to put it. But i assure you that i connected it in a good way and worked fine.

So in case you wanna include or add something, i'll be thankful for the time you gave to me.

Good night now... i'm soooooooooooooooooooo tired :-(

SteveB
- 7th June 2006, 21:42
BobK,
The "datasheet" Eng4444 posted was a bit sparse, but did reference the KS0066 (http://www.axman.com/support/CME-8GB60/Seikolcd.pdf) or equivalant controler.

Hope this helps, and it looks like you are correct about the data lines to the LCD, they should be D4-D7 (not D0-D3) in 4 bit mode.

Steve B

BobK
- 8th June 2006, 03:40
Hi Steve,

Yes I saw that information. I was worried since I said that. The displays that Melanie uses must use D0 thru D3. I really didn't want to cross her. Her stuff is really pretty good. I know now I'll feel the pain of her whip! I checked some of the things I did with 4 bit LCD's and they all used D4 thru D7 which is why I said that. I even looked in the PBP manual and that example is also D4 to D7. Later I looked at her 1307 Clock program and said OH NO! But considering everything that ENG4444 has been thru it can't hurt to try it. I do hope it works for him.

Thanks for the datasheet help, Steve. I saved it in my reference files.

BobK

Jumper
- 8th June 2006, 03:43
Hi,

I would like to add a 4k7 resistor between DS1307 (pin7) and 5V as a pullup resistor and as said many times before GND the backup battery pin.

SteveB
- 8th June 2006, 05:18
I haven't gone through the code completely, but taking another quick look at the schematic I noticed there aren't any pull-ups used for the buttons. I did see a TRISB=%11111111 in there, as well as checking one of the buttons low as a condtion in an IF...THEN statement used to enter the SetupEntryLoop (I am assuming the logic is the same on all three). So they are floating, and should be pulled-up. You could just use those 10K pull-ups you removed from the SCL/SDA lines (which should now have 4.7K) and add them to the pins for each of the buttons. Just need one additional for the third button.

Steve

Melanie
- 8th June 2006, 05:28
Gawd, that's a four-year-old program and you expect me to remember what LCD's I was using at the time? I do recall that you could use either the upper or lower 4-bits. On checking the current DATASHEET (Datasheets always seem to come into the conversation on this thread) I find that Tri-T (our currect supplier) only supports the UPPER four bits. So this is obviously non-standard. I'd connect as per the PBP manual, but using the Port pins as specified in the DEFINES within the program. I've tried the original MN1307 this morning (I've not checked the posted version) connected that way and it works.

Buttons are on PortB and use the PICs internal weak pull-up's.

Eng4444
- 8th June 2006, 05:29
The best thing is to have a huge project done ahead of time... everybody there is still working.

I checked all the comments i have. Thank you for your cooperation :-)

how would i know that they should have been D4 throught D7.... i do not work with electronics and i was doing exactly as it was said.

i will try all what was said in 2 hours and then give feedback.

i wish a nice day for everybody!

Eng4444
- 8th June 2006, 05:37
Seems we sent our posts in the same time!


SO you are saying that i can connect to the lower 4 bits as long as i keep the "defines" in the program?

And in case i will use from D4 to D7 i should change the "defines".
So what to change in this part if so?

"

Define LCD_DREG PORTA ' Port for LCD Data
Define LCD_DBIT 0 ' Use lower 4 bits of Port
Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 6 ' Port Pin for RS bit
Define LCD_EREG PORTA ' Port for Enable (E) bit
Define LCD_EBIT 7 ' Port Pin for E bit
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 2 ' Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)

"

i'll check this this thread when i arrive to my Lab.

By the way,
Don't you think people that this thread reached the highest score of visits?! hehe.

Let's reach the highest possible number! :-)

Melanie
- 8th June 2006, 05:37
There is a very basic software only (no RTC chip required) elapsed timer demo, ready to run, just an LCD and one Button only, at the bottom of this thread here...

http://www.picbasic.co.uk/forum/showthread.php?t=3423

Eng4444
- 8th June 2006, 08:07
Hello,

Here i arrived and will test your program....

honestly, i liked the first program because it gives time and date. I really hope it will work.

By the way, don't think that i will say that "i" did it. But i will show the source of it and all the posts and replies for this thread.

i really hope i'll ba able to see something on LCD.

First thing is that i will change the bits from D4 TO D7 and connect them to PIC; moreover, i will put 4.7 K resistors and 0.1uF Capcitors

More infos to come soon!

Eng4444
- 8th June 2006, 08:26
I connected all the circuit with the new changes and then downloaded the program after adding the following:

@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F628A, WDT_ON
' Watchdog Timer
@ DEVICE pic16F628A, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628A, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628A, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic16F628A, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628A, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F628A, PROTECT_OFF
' Program Code Protection

So now , when i compile with microcoe studio it compiles successfully. Bu when i want to program the IC, it gives a message :

" this program contains EEDATA - EDATA and this part will be discarded"

so i press "OK" and it begins programming.

during the process, when it arrives to " Programming EEDATA section" it stops and gives this message:
" Programming time-out or connection error"

For sure i have no connection error because i tried a small program on another IC and it worked.

any idea?

Melanie
- 8th June 2006, 10:06
Not from me, I don't use Microcode studio and avoid any questions on the topic.

If you compiled your MN1307.bas code from a DOS Window...

PBP -p16F628 MN1307 -v

or

PBP -p16F628A MN1307 -v

depending which version you're using... It will compile.

Likewise I can't comment on your method of programming the actual PIC.

Eng4444
- 8th June 2006, 10:58
A real BIG thanks for this nice code.

Here it worked :-)

it is displaying time and date.

Still a small problem that i will describe in details:

1- it says to chose between 24 hours or 12 hours and this is working fine.
2- chose time and date and things are also fine. In fact i chose today's date and time.

3- when i press the middle button again to save, it says: MEMORIZED.

but since then, time is not being updated on the screen. It is left all the time as i have set it since the beginning. I have waited 30 minutes and nothing has changed.

By the way, i used the 3V battery and noticed that everything was changed to 4 whether by number or place. What i mean is:
04:04:04
04 Apr 2004

so what do you suggest to do?

more than 3/4 of the work is done and i need to continue it till the end.

thanks in advance.

By the way Bobk,

i didn't use any capacitors but you were right about D4 till D7.
so help me to finish it....

I'll check in 1 hour.

Bye.

BobK
- 8th June 2006, 13:31
Hi Eng4444,

I'm glad to hear that you got it working. Now put the .1uF capacitors across each device and reset the project and see if it works. I slept in this morning so I'm running late for work. Keep plugging away!

BobK

Eng4444
- 8th June 2006, 22:08
i got busy a bit and now i returned to work.

I added the capacitors but nothing happened. the time is not advancing!!!!

i changed the cristal (32.768) and placed a new one but also nothing happened...

what is the reason??

i can easily go to the menu and set the time and date whenever i want but after i see : "MEMORIZED", time and date freeze on LCD...

can you help me Melanie? or anyone else..

thanks.

Eng4444
- 8th June 2006, 22:40
i added even a cristal 4M betweens pins 15 and 16 for the PIC16F628A with 2 capacitors but i'm still having same problem... time is not changing.

It is just freezing on the LCD without any change...

i also replaced the DS by a new IC and i still have the same problem..


You guys should have expertise in those things and similar cases... i hope you will discover the matter...

By the way, i also replaced the cristal of DS by another new one and i still have same problem...

waiting for something from your part..

BobK
- 8th June 2006, 23:20
Hi Eng4444,

Just got home from work and see that you are still having a problem. Just a quick question. Is the ability to set the time with the 3 push buttons really critical for you to show what you have done? If not then you could go to the part of the code that starts with "SETUP PRESET:" and enter the starting time and date manually. I will look over the code here this evening and get back to you on that.

Adding the capacitors (.1uF) has nothing to do with this problem. They are part of good design practice.

Just so I understand what has happened: You programmed the micro and the system started running and time and date was being displayed. You went into the set time and date mode and it accepted your time and date changes. Then you pressed the button to send you changes to the RTC and that's when it froze.

I will look for that part of the code you sent me and compare it with Melanie's posted code. Just out of curiosity, did you copy and paste her code or did you retype the whole thing?

Let me know. Thanks!

BobK

BobK
- 8th June 2006, 23:53
HI Eng4444,

The program listing that you sent me has the following last line:

LCDOut $FE,1,"Memorised"

Do you have anything after that? There's more to it like the part that writes the new values to the RTC. I got the following from Melanie's code:

' Make the User feel happy
' Save 12/24 Hours to BCD DS1307's Format
' ---------------------------------------
CounterA=SetHour
If SetTime=1 then
If CounterA>12 then CounterA=CounterA-12
If CounterA=0 then CounterA=12
endif
Gosub ConvertBCD
RTCHour=CounterB

' Save the Hours Value

If SetTime=1 then
RTCHour.6=1
' Save the 12 Hour Mode Flag
If SetHour=>12 then RTCHour.5=1
' Save the 'PM' Flag
endif
'
' Save Minutes
' ------------
CounterA=SetMin
Gosub ConvertBCD
RTCMin=CounterB
'
' Save Seconds
' ------------
CounterA=SetSec
Gosub ConvertBCD
RTCSec=CounterB
'
' Save Year
' ---------
CounterA=SetYear
Gosub ConvertBCD
RTCYear=CounterB
'
' Save Month
' ----------
CounterA=SetMonth
Gosub ConvertBCD
RTCMonth=CounterB
'
' Save Day
' --------
CounterA=SetDay
Gosub ConvertBCD
RTCDay=CounterB
'
' Calculate Day of Week & Save
' ----------------------------
' Melanie's fudge for calculating Days of Week
' using PBP's integer math...
' by the time someone's clock displays the
' the wrong Day of Week, I'll hopefully have long
' retired and be past caring...
' I wouldn't however go stick this routine in a
' Nuclear Power Station to purge the reactor
' every Monday morning without checking how far it
' will work before the integer math overflows...
' In my routine RTCWDay=1 is a Tuesday (the
' start of my week) and continues sequentially
' until RTCWDay=7 which is a Monday
CounterA=SetYear+4
CounterB=SetMonth
If SetMonth<3 then
CounterA=CounterA-1
CounterB=CounterB+12
endif
CounterD=(SetDay+(153*CounterB-457)/5+365*CounterA+CounterA/4-CounterA/100+CounterA/400+2) MOD 7
RTCWDay=CounterD+1
'
' Do the Business
' ---------------
I2CWrite SDApin,SCLpin,$D0,$00,RTCSec,RTCMin,RTCHour,RTCWDa y,RTCDay,RTCMonth,RTCYear,RTCCtrl]
Pause 1000
Gosub SetButtonRelease
Goto ReDisplay
endif
Gosub SetButtonRelease
Goto SetupLoop ' Loop for Next Menu Item
endif
'
' Menu TimeOut Counter
' --------------------
Pause 1 ' Kill 1mS
TimeOut=TimeOut+1
If TimeOut>20000 then goto ReDisplay
' User paused too long
' Return User to Time & Date Display
' This will however bounce the User to the original
' Setup Menu start point if the DS1307 has not
' been initialised
Goto SetupEntryLoop ' Loop for Button Press
'
End


Check this out> It could be why you're not working.

BobK

Eng4444
- 9th June 2006, 04:19
i re-donloaded the program but everything is still freezing.

Time is not advancing (i mean being incremented).


Melanie didn't answer yet so i think she might have a good answer...


Today is my Presentation! :-)

Eng4444
- 9th June 2006, 04:45
Hi Eng4444,

did you copy and paste her code or did you retype the whole thing?

BobK

i just copied and paste... why to type it again...?

i wish it will work!

It's so strange!

i changed DS1307, PIC 16F628A, cristal 32,768...i changed them all to newer parts.. and then i re-downloaded the program..

but there is something strange happening.

Eng4444
- 9th June 2006, 04:47
He said that i should keep on clearing the PIC in order to make time advance...

i dunno what does this mean but there is no "CLEAR" port on the 16f628A datasheet......

Melanie
- 9th June 2006, 06:35
I will check later in the day when I have a few minutes spare... some of us have more important commitments and have to work for a living too...

Melanie
- 9th June 2006, 11:15
I have downloaded the MN1307 program from the MeLabs website.

I have breadboarded the hardware and wired it per instructions with the exception that I've wired the LCD using DB4 thru 7 rather than DB0 thru 3.

I have run the program.

I have verified that it works as advertised.

I have posted proof here that it works. I have an MPEG video of it ticking away... you want me to email that you?

I don't post programs that don't work.

Now your problem...

It doesn't tick, then the software is just a simple loop that reads the RTC and displays the results on the LCD... this means your RTC isn't working. Also, if on initial first-time power-up it doesn't immediately jump into set-up, then that tells me the RTC isn't communicating with the PIC.

so...

1. Verify that SCL and SDA are wired correctly and you haven't swapped them over and you've not got any shorts.

2. Make sure you have pull-up Resistors on those pins. 10K will work, 4K7 with hindsight is probably better.

3. Make sure you have a Battery Connected.

4. If you haven't got a Battery, then connect the Battery pin to Vss.

5. Make sure your 32kHz Crystal is connected - and it's a good one. Steal one from your average genuine 99-cent Rolex wristwatch if you have any problems.

6. Ensure you have a good RTC chip.

If it still doesn't work, go back to step 1 and start over.



...i'll pass a whooooooole month in the Carribean!

Hurry back, because we're all going to miss you when you're gone...

Eng4444
- 10th June 2006, 09:10
Hurry back, because we're all going to miss you when you're gone...
__________________________________________________ ______________

You know?

i always have found your replies cool. You seem too much easy going and from the calm type.This is wonderful!

till now, i'm still thinking about that 99 cents watch! From where do you bring all those stupid jokes?

Keep on the good job!

Here we reached more than 1000 people who checked this thread! is it enough or we make them 2000?

Best regards.... ;-)

Early1
- 11th June 2006, 09:20
Thirty years ago when I was in the same position as Eng444, at University working on projects for my Bsc in Civil Engineering, I used a stop watch.

A mechanical one at that.

I am realy intrigued as to why any one has gone to so much trouble to re invent the wheel, or egg timer in this case.

I work in instrumentation and RTC are used extensively because we need to log data with a time and date stamp, and if I was going to build a data logger then I would use a RTC, but then I would not build one because I can buy a very good tested and reliable datalogger for £240.

Puzzled

Steve

Melanie
- 14th June 2006, 18:33
Steve

It's 23:58:43 on 28th February... You need a three-minute egg... you're in a panic because PAUSE 180000 exceeds a WORD variable. Do you stop the clock at 12:01:43am or at 00:01:43, and will it be on the 29th February or on the 1st March? Deep down, you KNOW the DS1307 was built by Maxim/Dallas just to provide you with these very answers.

Melanie

Pic_User
- 20th October 2008, 16:05
There is project building. Planning and physically building a project. Writing the code and testing. When it does something unexpected (that would include not working). There is “troubleshooting”.

Troubleshooting is an art. There are efficient ways and there are inefficient ways to accomplish the same end. The problem seems to be that some people just want the answer, not the procedure. They seem to think that someone can see their circuit, and mystically, clairvoyantly, pass their long-distant hand over the program or circuit and KNOW what their mistake is.

Real problems arise when the person ASKING for HELP thinks the helper is just asking silly questions and asking them to do silly things. All that the person ASKING for help wants is an ANSWER. So they end up DEMANDING that the foolish, silly, questions STOP, and GIVE ME THE ANSWER that I need.

So we are “stuck” with the “basic” truthful ANSWER , “I Don’t Know”. :)

See also


i did the same connections shown in the shematic , downloaded the same program (that is displayed here) inside PIC16F628A, gave 5VDc and checked the connections again. But i didn't see anything on LCD.......
...SO now, you will keep on saying that i have to read datasheets??

or you will try to help me in an effective way?

Friday i will present it in front of jury and MONDAY..... i'll graduate :-) and since then, i'll pass a whooooooole month in the Carribean!

...so i will just sleep......

Please guys, take it into consideration and check that schematic and program... tomorrow i'll be well awake so i'll concentrate on your replies and try to accomplish what you told me to do..

But please, please , please........ stop talking about datasheets...-Adam- (this was mis-posted (by me) should have gone in answer to: http://www.picbasic.co.uk/forum/showpost.php?p=64512&postcount=25