Discussion in "Project Addition or Changes" started by    koushal    Apr 21, 2007.
Thu May 31 2007, 11:20 am
#11
all you can do is polling as you dont want to use interrupts... so.. after displaying the time or while reading the time from RTC, you check for the low of pin. then save the value of time in a variables. and same during polling if it goes high, then save the rtc value again. and subtract both of them.. and save to rtc ram. not sure its a good idea.. but that is all u can do i guess..
its easy to do this way coz.. you know where the RTC hour is stored, and mins are stored, so time can be stored easily. try this way and tell me if ok.. :-)
Fri Jun 01 2007, 09:32 am
#12
Rickey,

Thanks for the hints.

I've been thinking all night long tried to figure out how to structure the code and it looks very complex for me (he..he..as I'm a newbie, but I made a constant progress in these few months. Thanks for your helps).

Just want to make sure I wrote corectly yesterday. I need an totalize timer which will count total of time the input port in low state. This input port not always in low state. So the totalize timer will count all of the time the input port in low state and compare it with preset value. The maximum preset value is around 20 minutes.

Refer to your hints, how to check for the pin in high state as the mcu is busy calculationg the duration of time the input port in low state ?. I guess I need another timer, say with 20 ms to continouesly check the state of the input port.

Will it be easily to use interrupt ?. If yes, please give me some hints how to use it for above purpose. I don't need extreme accurate totalize timer. 90 - 95 % accurate is already plenty for me.


Thanks,
SGH

Fri Jun 01 2007, 11:51 am
#13
Well you can get better results than 90-95%. its better to use interrupts.. do this way.. e.g. you are checkin pin 3.2(INT0) for low, enable interrupts and set the interrupts to edge triggered, so no wastage of time.
define some variables or registers e.g. ltrig_hr, ltrig_min,ltrig_sec (these will store the triggering low time of the pin)
then htrig_hr,htrig_min,htrig_sec (these will store the trigger low of the pin).

for low you can use the interrupts but yes, for check high of the pin again, you need to poll it. now the thing is where to poll it. in the program, when we are receiving data from RTC, at the end of data reception you can poll for the pin to be high. and if it is high store the current values (simple move takes only micro seconds) to htrig_hr ... and those registers.
and for low, whenever interrupt occurs you save the time in ltrig registers. and set a flag check_high, to enable the low checking of pin.

If you are using alarm in your clock then, interrupts are not free i think so better use polling, poll the same way as i explained polling of high,
e.g. of how to do with polling

jnb check_low,no_low
jb P1.0,no_low
setb check_high
mov ltrig_hr,42H
mov ltrig_min,41H
mov ltrig_sec,40H
clr check_low
no_low:
jnb check_high,no_high
jnb P1.0,no_high
setb check_low
mov htrig_hr,42H
mov htrig_min,41H
mov htrig_sec,40H
clr check_high
no_high:
; rest of your code

at startup you must set the flag check_low.
 SGH like this.
Mon Aug 13 2007, 08:23 am
#14
Hi Rickey,

I've been working on DS1307+AT89s51+16x2 LCD (in 4 bit mode) since May, 2007 and I've posted my code in this thread on Saturday, May 05, 2007.

The LCD initializing code was not mine and was downloaded from the internet.

To initialize LCD or change display on LCD, I used this code : resetlcd4, initlcd4. Occasionally when the display change (due to operation sequence), the words displayed on the screen overlapped with previous words and caused the entire system to hang. It is very frustrating as it happened occasionally.

I've checked the other code many times. I suspected I experincing problems with LCD routines but I don't know how to read the LCD specifications.

My At89S51 runs at 11.0592 Mhz.

Lcd used was LMB162AFC from topwaydisplay.com. The LCD specifications was 187 kbytes and I don't know how to zip it. Can I send it to other site ?. Here are some specifications : E cycle time (tc) 1500 ns (min), E high level width (tpw) 175 ns (min), E rise time (tr) 20 ns (max), E fall time (tf) 20 ns (max), Address set-up time (tas) 5 ns (min), Address hold time (tah) 13 ns (min), Data set-up time (tdsw) 50 ns (min), Data delay time (tddr) 125 ns (max), Data hold (th) 13 ns (min). Could you please take a look for the timing (delay) required. Many thanks.

Why the author of this code initilized the lcd 2 times : resetlcd4 (then sjmp initlcd4) followed by another initlcd4 ?.


Thanks,
SGH
Mon Aug 13 2007, 05:43 pm
#15
I think you've gone through the LCD tutorial in my page so you can understand why LCD is first reset then initialized.
there is a reset sequence of the LCD.. its like this way..
  1. First Reset
    Second Reset
    Third Reset
    Data Width

So this is the reset sequence, and the init sequence is usual as you use for 8-bit or 4-bit LCD.
and as i see from the timings you gave.. all are in "ns" and our machine cycle is in "µS" so wont be a problem.. just take a look at the reset sequence and the init sequence of the LCD. That is the important part.
Tue Aug 14 2007, 07:38 am
#16
As I mentioned before, the problem only occur occasionally, but very frustrating. Don't know when it will occur.

The code I used look similar to the code used by other member of this forum (Binu). Binu code didn't used 'pulseewait4' and the rw pin was tied to ground.

When the problem occur, I reset the system by switch off electric power to the circuit for 1 second and re-power. After this reset, the system recover until next problem.

What other area I should check ?. I've checked the code many times.

Thanks,
SGH
Tue Aug 14 2007, 12:34 pm
#17
There is for sure a problem in the code, because you are getting output means your connections are ok.
What possibly can be wrong is.. you might be using high ram. Can you attach the code so i can take a look at it?
Tue Aug 14 2007, 01:21 pm
#18
I'm using AT89S51, it has 4 kbytes ROM with 128 bytes ram.

What is high ram ?. Please elaborate. Last variable in the program was stored at ram address 39H and the stack pointer at 70H (mov sp,#70h). Is this the error ?.

Thanks,
SGH
Tue Aug 14 2007, 01:40 pm
#19
no no i am not talking about that... i mean.. sometimes RAM overflow occurs.. when you use complete stack.. u are not left with any space to write the stack content.. so problem occurs..
Thats why i want to see your code once.. just to confirm.
Wed Aug 15 2007, 07:11 am
#20
The code (in text form) is 40 kb. This forum only allow 10 kb attachment. Can I send the code to following email : [email protected] ?.


Thanks,
SGH

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am