CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

My project with 16F876A and ds1307. Really need help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

My project with 16F876A and ds1307. Really need help
PostPosted: Fri Mar 14, 2008 10:28 am     Reply with quote

First of all, thank you so much for visiting my topic
I am very new with C language and programming.
I've just coded. but my works did not work.
I use six 7segment leds anode common controlled by 6 npn transistor which are connected to PortA. And PortB is to transfer data to 7seg leds
T
The original driver of ds1307 is from http://www.ccsinfo.com/forum/viewtopic.php?t=23255&highlight=ds1307
I was modified the driver to set 1Hz SQW output and connect swq/out to RB0 ext_interrupts to get date and time every second
But when complie, i was recieve this message

"interrupts disabled during call to prevent re-entrancy (@I2C_WRITE_1)"
interrupts disabled during call to prevent re-entrancy (@I2C_READ_1)"
interrupts disabled during call to prevent re-entrancy (bcd2bin)"
"Funtion not void and doe not return a value EXT_isr"

I am very happy to get your help
Thank you so much


Last edited by HTAluvBeBeo on Sun Mar 16, 2008 12:54 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 11:03 am     Reply with quote

Quote:
#int_EXT
EXT_isr()
{
sec++;
if(sec==60) sec=0;
ds1307_get_time(hr,min,sec);
ds1307_get_date(day,mth,year,dow);

}


Quote:
void main(){
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
enable_interrupts(GLOBAL);

while(1){
key=0;
ds1307_get_time(hr,min,sec);
ds1307_get_date(day,mth,year,dow);

keyscan();
}
}

This is very bad program design. In your main loop, you are constantly
reading the date and time from the ds1307. Then you have an interrupt
which also does i2c operations on the same ds1307 chip. What if
an interrupt occurs while an i2c operation is in progress in the main loop ?
You can't do that. It won't work. My advice is to use the #int_ext to
set a global variable (a flag). Check the flag in the main loop and if
it's set, then read the date and time and then clear the flag.
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 6:58 pm     Reply with quote

thank you so much. I am very new with programming, i will fix my stupid program
is there any problem else:-?


Last edited by HTAluvBeBeo on Sun Mar 16, 2008 12:54 am; edited 1 time in total
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Sat Mar 15, 2008 1:36 am     Reply with quote

I've changed my hardware and used RC0 RC1 RC2 to catch the buttons instead of using together with 7seg leds
everything seems better

But instead of using only one more I/O to catch buttons, Now I have to use RC 0 RC1 RC2 to do that
I still want to use one I/O to catch upto 6 buttons
Thank you so much


Last edited by HTAluvBeBeo on Sun Mar 16, 2008 12:55 am; edited 1 time in total
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Sat Mar 15, 2008 9:26 am     Reply with quote

with the code above, my program runs untill 20:20:22
And there is some bugs when i set time to 22:22:22 or something like that
I don't know why
Please help me
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Sat Mar 15, 2008 10:18 am     Reply with quote

with the following code


The program wont work when it runs to (or I set to) value which do not have number 1 or 4
for example
06:37:58
or
20:23:57
etc

The time and date must have number 1 or 4 in it for program to work
for example
04:37:58
or
21:23:57

What a crazy bug
I don't know why
Could you show me the solution:-?
Thank PCM Programmer and other friends for reading my topic
Sorry for my bad English[


Last edited by HTAluvBeBeo on Sun Mar 16, 2008 12:55 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 15, 2008 2:00 pm     Reply with quote

1. You are posting too much code. People are ignoring your posts
because no one wants to look at hundreds of lines of code.

2. I assume that you got the ds1307 driver from the CCS code library.
So it probably works. Don't post that code. Just provide a link to
the post in the CCS code library. We can go there to look at it.

3. You need to change the design of your program so that it is easier
to understand and easier to test. You should create a function that
is used only to display a number on your LEDs. That's the only thing
it should do. Then you can test it separately and prove that it works.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Mar 15, 2008 3:20 pm     Reply with quote

One thing I noticed was that you are mixing two different configurations.
ds1307_init() has:
Code:

   i2c_write(0x90);     //  squarewave output pin 1Hz
while ds1307_set_date_time() has:
Code:

  i2c_write(0x10);            // REG 7 - 1Hz squarewave output pin
The OUT-bit is don't care in your setup so this shouldn't affect performance, but it got me confused. It's best to set the configuration equal in both functions.
Guest








PostPosted: Sat Mar 15, 2008 6:51 pm     Reply with quote

thank for your care, I found the problem
I use ext_in on RB0 and this I/O is also to transfer the data to a segment of 7seg leds
So what should I do to use ext_int on RB0 to upadate time and date every second while using Port B to transfer the data to 7seg leds
Thank you so so much, I haven't had enough experiece with PIC andC language.
Thank PCM Programmer for your helpful advices
Thank for friend who replied my post
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Sat Mar 15, 2008 7:31 pm     Reply with quote

Anonymous wrote:
thank for your care, I found the problem
I use ext_in on RB0 and this I/O is also to transfer the data to a segment of 7seg leds
So what should I do to use ext_int on RB0 to upadate time and date every second while using Port B to transfer the data to 7seg leds
Thank you so so much, I haven't had enough experiece with PIC andC language.
Thank PCM Programmer for your helpful advices
Thank for friend who replied my post

One more question:
How to control the brightness of leds in my case
Using PWM, do I need one more I/O to do that:-?
PS:ckielstra, you have a code that will probably useful for me
http://www.ccsinfo.com/forum/viewtopic.php?t=26177
I will try to use this code and int_timer1 to update time and date evey second instead of using int_ext RB0
Is it ok:-?
Or maybe give up the ds1307 to use your code to do my own clock:D
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Sun Mar 16, 2008 12:48 am     Reply with quote

Thank you all
I did 2 clock. they work fine
one with ds1307 and use int_timer1 and code lib of ckielstra to update time and date every 1s
the other do not use ds1307. just use code lib of ckielstra that i mentioned above

Thank for your help, PCM Programmer and ckielstra

I still want to know how to control brightness of my leds
could you show me some links or advices

Sory for my bad English
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Mar 16, 2008 7:27 am     Reply with quote

You can make the dimming as difficult as you want to. An easy solution is to use the PWM module of your PIC in combination with a single transistor in the power (or ground) line to your LEDs. Choose a frequency of 100Hz or higher to avoid seeing the LED flicker.
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Sun Mar 16, 2008 11:36 am     Reply with quote

Could you give me an example or schematic how to control six 7seg leds and dim by using PWM
I am very new to electronics, MCU and programming
Thank for replying
sorry for my bad English
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group