Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer Program

Status
Not open for further replies.

cne

New Member
Hi,

I am using Flowcode to create a PIC program that counts down minutes on a seven segment display. I also want to add a function to the program where, at a certain point, a variable is stored in the eeprom. At another point in the program, that data is retrieved and stored in another variable.
This is so when the power is turned off, the PIC remembers the preset time.
For example...

Set Macro
1.Get keypad number for time preset
2.Store number in eeprom

Read Switch
Start Timer Macro
1. Get data in eeprom
2. Start TMR0
3. Count down from that number

The flowcode program has an option to add blocks of C code and ASM within a program,
so if possible the function would be in one of these languages. I am a beginner in terms of programing.

Thanks in advance,
Cameron
 
If you are using the free version of Flowcode then it doesn't include the EEPROM routines. Have a read of this thread and see if it makes any sense. You can just copy the C code I wrote into a C box and it should work.

Edit, it's a little more complex than I thought but if you still need help I can probably knock together an example flowcode program.

Mike.
 
Last edited:
I had a play with flowcode and wrote the code to read/write EEPROM. It doesn't work in the simulation as the simulation doesn't appear to execute C code but it does produce the correct C source code.

Edit, you'll probably have to save the files to your computer and change the name as this stupid forum inserts an extra period in the filename. The zip file contains the flowcode file.

Mike.
 

Attachments

  • EEPROM..c
    2.9 KB · Views: 271
  • EEPROM..zip
    1.5 KB · Views: 194
Last edited:
Thanks for your solution,
It all looks fine, until I try to compile, and I get the following errors...
Code:
[COLOR="DarkRed"]\EEPROM.c(77:10): error: invalid operand 'FLC_ADDRESS'
\EEPROM.c(77:8): error: failed to generate expression
\EEPROM.c(78:11): error: unknown identifier 'FLC_DATA'
\EEPROM.c(78:11): error: invalid operand 'FLC_DATA'
\EEPROM.c(78:9): error: failed to generate expression
\EEPROM.c(83:9): error: unknown identifier 'FLC_SAVEINT'
\EEPROM.c(83:9): error: invalid operand 'FLC_SAVEINT'
\EEPROM.c(83:8): error: failed to generate expression
\EEPROM.c(99:10): error: unknown identifier 'FLC_ADDRESS'
\EEPROM.c(99:10): error: invalid operand 'FLC_ADDRESS'
\EEPROM.c(99:8): error: failed to generate expression[/COLOR]
 
Whoops, those should be FCL_ not FLC_. Can you edit the C Code to change them. Just double click the C Code boxes and where ever you see FLC_ change it to FCL_.

Edit, I've also changed the attachments above.

Mike.
 
Last edited:
Thank you so much for your solution.
It compiles OK and I will revise my program today.

Another quick question,
I am utilizing the TMR0 interrupt in flowcode set to one second, but it is slightly inaccurate. I must use a 4mhz crystal on the PIC. I don't know if there is a simple revision I can make, or if I can do it another way.
It is actually counting minutes, every 60 cycles.
 

Attachments

  • Example..zip
    1.3 KB · Views: 203
The way to get it accurate is to use timer 2 setup as in the attachment to generate 100 interrupts per second.

Edit, to get the 250 value you need to enter it and then press ok.

Mike.
 

Attachments

  • timer2..png
    timer2..png
    12.4 KB · Views: 274
Last edited:
Thanks Again,
Regarding the EEPROM code...
I am using a 16F628A, and when I change the chip, I get the following errors...

error: unknown identifier 'pir2'
error: failed to generate expression
error: error in 'while' loop statement
 
Last edited:
For the 16F628 change the write code to,
Code:
	    FCL_SAVEINT=intcon;         //save interrupt status
	    eecon1=0;                   //ensure CFGS=0 and EEPGD=0
	    eecon1.WREN = 1;            //enable write to EEPROM
	    eeadr = FCL_ADDRESS;        //setup Address
	    eedata = FCL_DATA;          //and data
	    intcon.GIE=0;               //No interrupts
	    eecon2 = 0x55;              //required sequence #1
	    eecon2 = 0xaa;              //#2
	    eecon1.WR = 1;              //#3 = actual write
	    intcon=FCL_SAVEINT;         //restore interrupts
	    while([COLOR="red"]eecon1.WR[/COLOR]);           //wait until finished
	    eecon1.WREN = 0;            //disable write to EEPROM

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top