Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Kai Klaas
02/07/06 07:55
  02/07/06 08:00

Read: 8129 times

#109412 - Answers
Responding to: Suresh R's previous message
Suresh said:
I have not used an ISP Header. can i know about it.

(Pin1 of header goes to P1.7)

The ISP header allows you to connect the ATMEL ISP programmer (ISP cable), which we have discussed here a lot in the last days and weeks, to the AT89S52.
To program the AT89S52 turn-off Vcc of micro, disconnect the reset line of micro from MAX1232's output by the help of shown jumper. Then, connect the 'ISP cable' to the header, turn-on Vcc of micro (target) and program it. After verification of proper programming, program the lock bits, turn-off Vcc of target, remove the 'ISP cable', set the jumper again to connect reset line of micro to MAX1232's output and turn-on Vcc of micro again. Now the micro will do its job.

Suresh said:
description of this instruction is needed.

begin:              mov auxr,#00011001b     ;reset pin is input
                    mov tmod,#00000001b     ;timer 0 in modus 1

These two lines initialize the AT89S52. The first line configures the auxr-register, which is an additional SFR of AT89S52, not implemented with original 80C52. It allows you to switch-off the internal watchdog during idle, to switch-off ALE and to configure the reset pin as input only. Have a look at datasheet of AT89S52 to see more details.
The second line configures timer0 to work in mode1.

Suresh said:
Also, it would be helpful to understand the code if you could give a description of the operation that the software does for a particular switch setting.
i.e.,I mean to know the logic you have used in it to get the required time delay.

The code, which I recall here again, is very simple:

                    $include (89s52.mcu)    

                    org 0
                    sjmp begin

                    org 002bh

begin:              mov auxr,#00011001b     ;reset pin is input
                    mov tmod,#00000001b     ;timer 0 in modus 1
                                            ;Total delay is
                                            ;number 'z' (BCD- 
                                            ;switches) times
                                            ;10msec delay of
                                            ;timer 0
                                            ;reads 'start' and
                                            ;BCD switches

start_pressed?:     clr p1.4                ;strobe watchdog
                    mov c,p0.2              ;read 'start'
                    setb p1.4               ;strobe watchdog

                                            ;'start' pressed?
                    jc start_pressed?       ;No!

                                            ;'start' is pressed:            
                    mov a,p0                ;read "1"
                    swap a                  ;eases layout
                    cpl a                   ;true data
                    anl a,#00001111b        ;low nibble needed
                    mov r0,a                ;store "1" in r0
                    mov a,p2                ;read "10","100"
                    cpl a                   ;true data
                    mov r1,a                ;store it in r1
                    swap a                  ;eases layout
                    anl a,#00001111b        ;low nibble needed
                    mov b,#10               ;load #10 into b
                    mul ab                  ;a = "10" x 10
                    add a,r0                ;add r0 ("1")
                    mov r0,a                ;store it in r0
                    mov a,r1                ;now we need "100"
                    anl a,#00001111b        ;low nibble needed
                    mov b,#100              ;load #100 into b
                    mul ab                  ;a = "100" x 100
                    add a,r0                ;add r0
                    mov r0,a                ;low byte in r0
                    mov a,#0                ;carry?
                    addc a,b                ;add carry to b
                    mov r1,a                ;high byte in r1
                    jnz activate_relay      ;r1<>0!

                    mov a,r0                ;r0=0?

                    jz start_released?      ;r0=0 and r1=0!
                                            ;means z=0!                     
                                            ;r0<>0 or r1<>0!
                                            ;means z<>0!
activate_relay:     clr p0.0                ;turn on relay

                                            ;initialize timer            
timer_delay:        mov th0,#220            ;reload high byte
                    mov tl0,#15             ;reload low byte
                    setb tr0                ;start timer 0
                    clr p1.4                ;strobe watchdog

                                            ;timer busy?
timer_busy?:        jnb tf0,timer_busy?     ;timer busy!

                                            ;10msec delay over
                    clr tr0                 ;stop timer 0
                    clr tf0                 ;clear overfl. flag
                    setb p1.4               ;strobe watchdog

                                            ;decrement z
                    mov a,r0                ;                
                    clr c                   ;
                    subb a,#1               ;a=r0-1
                    mov r0,a                ;low byte of z=z-1
                                            ;into r0
                    mov a,r1                ;carry?
                    subb a,#0               ;
                    mov r1,a                ;high byte of z=
                                            ;z-1 into r1

                    jnz timer_delay         ;r1<>0!

                    mov a,r0                ;r0=0?

                    jnz timer_delay         ;r0<>0!

                                            ;r0=0 and r1=0!
                                            ;means z=0!
                    setb p0.0               ;turn off relay

start_released?:    clr p1.4                ;strobe watchdog
                    mov c,p0.2              ;read 'start'
                    setb p1.4               ;strobe watchdog

                                            ;'start' released?
                    jnc start_released?     ;No!

                                            ;'start' released!
                                            ;initialize waiting
                    mov r1,#103             ;'start' released
waiting_loop_1:     mov r0,#255             ;for 0.2 sec?
waiting_loop_2:     clr p1.4                ;strobe watchdog
                    mov c,p0.2              ;read 'start'
                    setb p1.4               ;strobe watchdog

                                            ;still released?
                    jnc start_released?     ;No!
                                            ;still released!
                    djnz r0,waiting_loop_2  ;repeat loop 2

                    djnz r1,waiting_loop_1  ;repeat loop 1

                    ljmp start_pressed?     ;'start' released
                                            ;for at least


You have three BCD switches: "1", "10" and "100". With these you can input numbers from 0 to 999. Multiply this number by 10msec and you have the possible turn-on times of dispenser, means 0 to 9.99sec. You can put a decimal point between "100" BCD switch and "10" BCD switch to optically visualize this range.

After initialization of micro, the program waits for the start button being pressed. When logic low is detected at P0.2, the micro reads the BCD switches and and forms a binary number (z = 0...999), which then is temporarily stored in r0 (low byte) and r1 (high byte).

Directly afterwards the program checks, whether z = 0. If so, the main delay routine is skipped.

If z is not 0, then the main output (P0.0) gets activated, means the dispenser is turned-on. Immediately after that, the delay routine is invoked, which turns-on timer0 for z times. As timer0 produces a 10msec delay, looping this timer for z times gives the wanted turn-on time of dispenser.

Correctly spoken the timer is not configured to exactly 10msec, because the additonal instructions in the delay loop also consume time. The timer was configured in that way, that timer0 delay plus cycle time of additional instructions yield 10msec.

Timer0 setting is: 65536 - (220 x 256 + 15) = 65536 - 56335 = 9201. In combination with 11.0592MHz crystal this gives a time delay of 1 / 11.0592MHz x 12 x 9201 = 9.9837msec.

With all this timing stuff, don't forget, that your relay turning-on the dispenser can show a turn-on and turn-off delay of many many miliseconds. So, don't expect very high precision, when you choose a dispensing time in the 10msec range. Choose a fast relay, with equal turn-on and turn-off time, if you need high precision.

If the delay time is over, means if the loop, which activates timer0 has run through for z times, the main output (P0.0) gets deactivated, means the dispenser is turned-off again.

If we would now jump to the start of program again, then we had trouble with switch bounce. Instead of that we need to do something which guarantees, that all further start button pressings done during the delay and all bounces are ignored and that a permanently pressed start button will not turn-on the dispenser again and again. So, we jump to the start only, if after the dispensing time the start button was released for a period of 0.2sec.


List of 57 messages in thread
Circuit for dispensing unit      Suresh R      01/31/06 05:09      
   1.1 sec monoshot      Abhishek Singh      01/31/06 09:43      
      this thread is apin off from an earlier      Terry Lingle      01/31/06 13:07      
         yes      Steve M. Taylor      01/31/06 13:55      
         timing circuit      Suresh R      02/01/06 04:17      
   Monostable      Andy Neil      01/31/06 12:08      
   Yes.      Steve M. Taylor      01/31/06 13:06      
   Hello All      Suresh R      01/31/06 22:23      
      Description of the "Dispensing Unit"      Andy Neil      02/01/06 00:39      
         using micro      Suresh R      02/02/06 00:25      
            Microcontroller      Andy Neil      02/02/06 01:35      
               Pressure      Steve M. Taylor      02/02/06 03:51      
            What must your circuit can do?      Kai Klaas      02/02/06 07:17      
               0.1 sec      Steve M. Taylor      02/02/06 10:34      
                  but not with a potentiometer      Erik Malund      02/02/06 10:38      
                     Vernier      Steve M. Taylor      02/02/06 13:02      
                        and calibrate it how?      Erik Malund      02/02/06 13:14      
               Precision        Andy Neil      02/02/06 15:13      
                  Sure!      Kai Klaas      02/02/06 16:01      
                     Price      Andy Neil      02/02/06 17:06      
                        Less than 1      Kai Klaas      02/02/06 20:02      
                           levels of precision      Suresh R      02/03/06 05:01      
                              Please have a look into datasheet!      Kai Klaas      02/03/06 05:57      
                                 somewhere here there is a link      Erik Malund      02/03/06 06:51      
                                    Details?      Kai Klaas      02/03/06 07:17      
                                       I recall that in an earlier thread      Erik Malund      02/03/06 07:20      
                              Ooops.      Steve M. Taylor      02/03/06 09:49      
                              Blown Discharge PIN      Abhishek Singh      02/04/06 19:15      
                                 You can also let the smoke out of the      Terry Lingle      02/04/06 22:37      
                                    limits      Steve M. Taylor      02/05/06 06:13      
                                       dissapation      Terry Lingle      02/05/06 09:45      
                                          There must be a point.      Steve M. Taylor      02/05/06 10:31      
                                             Fusing the bonding wires      Terry Lingle      02/05/06 13:59      
                                                History making      Steve M. Taylor      02/05/06 14:47      
                                                Current limiting      Kai Klaas      02/07/06 06:42      
                                 I do go through      Suresh R      02/07/06 01:50      
            schematic and code      Kai Klaas      02/05/06 19:47      
               codes      Suresh R      02/07/06 00:32      
                  Instruction Description      Andy Neil      02/07/06 04:28      
                     not quite      Erik Malund      02/07/06 06:09      
                        Pedantic      Andy Neil      02/07/06 07:12      
                           is that not the pot calling the kettle b      Erik Malund      02/07/06 07:17      
                              Of course not!      Andy Neil      02/07/06 07:31      
                  Answers      Kai Klaas      02/07/06 07:55      
                     Re: codes and shcematic      Suresh R      02/10/06 03:55      
                        Recommendations      Kai Klaas      02/10/06 07:05      
                           Decimal switches - how to start C      Erik Malund      02/10/06 08:09      
      LM555 pin 2 wired wrong.      Charles Bannister      02/01/06 04:45      
         ... and the LED?      Andy Neil      02/01/06 05:31      
            i'm sure thts not the circuit      Abhishek Singh      02/01/06 06:38      
            Astable??      Kai Klaas      02/01/06 11:46      
               I wondered who'd spot that first...      Andy Neil      02/01/06 12:47      
   Damaged?      Kai Klaas      02/01/06 11:51      
      And Andy's correction      Steve M. Taylor      02/01/06 12:03      
         Absolutely!      Kai Klaas      02/01/06 12:24      
   one shot in the foot      Erik Malund      02/01/06 12:31      
      Need not to work unreliably      Kai Klaas      02/02/06 07:10      

Back to Subject List