Setting LCD Clock time/date from PC by clicking on a File!

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Setting LCD Clock time/date from PC by clicking on a File!

Post by medelec35 »

I'm currently working on a project which will allow you to set RTC with current PC time, date and day via USB virtual comport (E.g Eblock EB 039), by just clicking on a singe batch file.
No third party software (except for UART to USB drivers) or DLL fires are required.
Only tested on 64Bit win 7
Attached is flowchart of a basic clock (starts at 00:00.0 00/00/00 and the batch file that when ran will set the time and date to PC time and date.
The last 0 is where the day of the week is going to be displayed when that part is finished
Next flowchart posted should include DS3231/DS1307 RTC so that can be instantly set/synchronised to local PC time and the day of the week setting as well.
My hardware consists of:
EB006V9 programmer with 16F1937 & 9V PSU.
EB039 USB 232 board, plugged in to port C.
EB005 LCD, plugged in to port B.
After 16F1937 has been programmed with attached flowchart and connected USB of RS232 to PC, all you do is run the batch file.
LCD should be automatically updated with same time as your PC.
Only tested in the UK, not sure how it would work if in a different country that has a different date format.

You may or may not find a practical purpose for this.
I have posted it as you may just like to experiment is sending variables down the comport to hardware.
Note:
There are two references to com.
Both of them require the correct port number.
There maybe an issue is comport is greater than 9?

Martin
Attachments
Prog Clock via PC.fcf
(31.23 KiB) Downloaded 1064 times
Send Time & Date.bat
(466 Bytes) Downloaded 729 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

Added automatically setting day of the week as a string e.g 'Sun' and day in number form e.g '2' for Sunday.

I was not sure how to use localdatetime function for retrieval of day of the week, so used the standard formula Day of the week = (d+m+y+(y/4)+c) mod7 as this turns out to be the simplest method.
Since only using 21st century, to determine if leap year or not then only

Code: Select all

if Year % 4 = 0
and not

Code: Select all

if (((Century + Year) % 4 = 0 && (Century + Year) % 100 != 0) || ((Century + Year) % 400 = 0))  
Makes calculations easier.

Next flowchart will be sending time,day,date & year to RTC module

Martin
Attachments
Prog Clock via PC V2.fcf
(43.49 KiB) Downloaded 980 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Hi Martin!

Oh again a really exciting project from you Martin. :D I will test it at first given opportunity. Must just having ordered a Pic.

Thank you for sharing.

Best regard
Jorgen

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

Hi Jorgen,
Thanks.
Nearly there with programming RTC.
Hopefully will be completed tomorrow, but you never know.
Will be so much easier then pressing buttons.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Hi Martin.

Finally I get time and I got the Pic to play with your nice project.

First I test your previous project by manually setting time. Perfect with both of the realtime memorymodule. Work 100% ok, really nice. After that, I have tested the new clock with the batchfile, but sorry no luck.
After programming the chip, nothing happen in the display. I try to add 1sec flash in the main loop and it flash.
What could I have done wrong?
E
One more thing, to program the clock with your batchfile, I have no serial port on my PC, but I have
USB to serial Can i use this or am I misunderstanding something.

Thanks in advance


Best regard

Jorgen

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Hi Again Martin!

Concerning the serial and the batch I have seen the ligth. ofcourse I have to add serial converter ( TTL to rs232 have not seen that).

But I still not managed to the program running. Its just like there are no connection between port B and the display. But there must be, because it Work in FC6 with your first clock project.

Now I have add a displaytest as first in the program and a 1 sec flasher in loop. the flash Work but nothing in the display :?: Do you have any idea.....

I am using EB 006 - 07 FC 5 ver. 5.5.2.1
Attachments
Prog Clock via PC V2Test1.fcf
(44.54 KiB) Downloaded 908 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

Hi Jorgen,
you can get the USB to TTL serial converter very cheap online.
You need to be careful as there are 3.3 & 5V logic versions.
So just make sure its the 5V logic version your ordering.

I have the same hardware as you, so when I get home this evening, I will see if working OK for for me with flowchart you have posted.

One thing i have noticed is on some PC's wrong data is sent and not sure why?
On other PC's works perfect every time.
I hope to find away around the issue with non working PC's

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Ok Martin, thank,s

Meanwhile I make some more test´s. I made a simple display testprogram with pic16f1937 in FC5 it doesn´t Work. Then I made the same program in FC 6 and it Work??

It look like for me maybe, there could be (carefully) a bug in FC5 for driving display for this 16f1937.

If I make the same program with a 16F876 in FC5 it Work.

Hava a nice day

Jorgen
Attachments
FC6Displtest Simple.fcfx
(4.49 KiB) Downloaded 712 times
16f1976dispttt.fcf
(7.5 KiB) Downloaded 859 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

Hi Jorgen,
I just remebered I modified FC5_PIC_LCDDisplay.c file so it will allow LCD to work at all common frequencies including 19.660800MHz
The original FC5_PIC_LCDDisplay.c within 5.5.2.1 will only work LCD if osc running at 32MHz or above.
When the LCD c file was modified it was not known at the time that there will be issues with LCD at 19.660800MHz

The solution is to back up the original file and place attached file in:
64 bit windows:
C:\Program Files (x86)\Flowcode\v5\Components\FC5_PIC_LCDDisplay.c

32 bit windows:
C:\Program Files\Flowcode\v5\Components\FC5_PIC_LCDDisplay.c

Martin
Attachments
FC5_PIC_LCDDisplay.c
(12.47 KiB) Downloaded 749 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Ok Martin. Do I understand it right.

1. Does this mean there has always been an error in FC5 for pic16f1937?

2. If I override the new C file you've created will it have an impact on other types Pic also or do I copy the original back Again or is it a corrected .c file for all pic?

Thank´s Martin I will make a test as soon as possible and you hear. :D

Jorgen

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

jgu1 wrote:1. Does this mean there has always been an error in FC5 for pic16f1937?
Yes as far as I'm aware.
Of course matrix staff will be more accurate than I am.
jgu1 wrote:2. If I override the new C file you've created will it have an impact on other types Pic also or do I copy the original back Again or is it a corrected .c file for all pic?
Hopefully not.
The modification should still allow LCD to work with all targets, not just 16F1937.
So no need to copy original file back.

It's just best to keep a back up just in case.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Hi Martin!

I have overwritten your new file in FC5 Sorry it doesn´t change anything. :(

BR

Jorgen

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

Hi Jorgen,
I did have a EB005 - E-Blocks LCD board working when compiled the flowchart to Eb006 with 16F1937 running at 19MHz
Then I did make another modification to the file prior to sending so I will double check when I get in tonight that I have not made a mistake.

Martin
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by medelec35 »

Hi Jorgen,
Just to make triple sure, I downloaded FC5_PIC_LCDDisplay.c from my post above and placed the file the components directory.
Loaded mLoader and erased chip.
Loaded Prog Clock via PC V2Test1.fcf without changing any settings and compiled to target.

LCD works just fine.
Seconds can be seen incrementing.

So can't say why it works with Flowcode V6 and not flowcode v5 after replacing LCD component C file

Pehaps re download Prog Clock via PC V2Test1.fcf and use that to compile with.

My other suggestion is the original FC5_PIC_LCDDisplay.c may not have been replaced with attached version on the post above.
If you go the the folder where the file is stored, then open file up in your word editor then check to see if it contains the following lines:

Code: Select all

 #ifdef FC_CAL_PIC
  
    #ifdef MX_LCD_PORT_LAT
         #define %a_PORT0    lat%b
         #define %a_PORT1    lat%c
         #define %a_PORT2    lat%d
         #define %a_PORT3    lat%e
         #define %a_PORT4    lat%f
         #define %a_PORT5    lat%g
    #else
         #define %a_PORT0    port%b
         #define %a_PORT1    port%c
         #define %a_PORT2    port%d
         #define %a_PORT3    port%e
         #define %a_PORT4    port%f
         #define %a_PORT5    port%g
        #endif
Of course there are more lines I have just posted the important part.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Setting LCD Clock time/date from PC by clicking on a Fil

Post by jgu1 »

Hi Again Martin

Now I am completely confused.
I have compared the files, and they are similar. As a precaution, than I wrote your file again in lib. Compile to Pic, no luck.

So I tested with my newest EB06 Ver.8 board, no luck with my own test display, no luck. But then I took MM EB005 display, Woov now I could see the default setting and the second began to run. But not with my own testdisplay. I had never had problem with that, so I tryed to compile another program to another Pic with some tekst, and my testdisplay Work.

So far so good. I tryed to program Again via my old EB6 ver.7 connect my testdisplay to port B, no result, then i connected MM EB 005 display to port B, no result. :?: Then I tryed to change the port for the display to port D. no result in my testdisplay. BUT, if I connect EB005 to port D, then I could se it all again :?: :?: :?:

Martin I ask you kindly, are you able to tell me why I not can use my testdisplay(have tryed several displayy not working) with Pic16F1937, But its ok with all other kind of Pic.
And I have no problem in FC6 with Pic16F1937 and all kind of display. :?:

It could also be anyway, I can just use your first clockproject, it really Work perfect.

But it annoys me to know I have something that is not okay in FC5. I still use FC5 as I use FC6.

Thank´s in advance and using your time on me.

Jorgen

Post Reply