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.

Monitoring PIns of controller at the same time

Status
Not open for further replies.

waqar

New Member
Iam using At89c52 and looking for some assembly software help.

a example will really help me to continue on my work.

Suppose,

I have connected Four Door Sensing Device and there out -put is connected with controller

P2.0
P2.1
P2.2
P2.3

Now when ever any door is opened a siren starts to ring for 6 seconds and under two conditions it is turned off:

1) if no one close the door up till 6 seconds,
or
2) the door is closed before 6 seconds.


using crystal of 11.05KOH

in designing software in assembly for 89c52 i only don't understand how to write code for monitoring all doors , if any one of the door is opened also the controller should perform the siren task but also keep on monitoring other ports if a high signals comes on them..

suppose high comes on P2.0 , sirens starts to ring but at the same time or within 6 seconds High also comes on P2.1 and P2.3 then also the controller should starts the siren for these pins and at the same time look which door is need to be disconnected from the siren considering the above mentioned conditions.

I know i have to use timer to keep on monitoring the bits as fast as possible, lets say 10 micro-seconds... after every 10 seconds controller controller should see if any bit is set or not.

i only need help for the monitoring part...?

also if i use timer 0 for monitoring and timer 1 for generating the siren for 6 seconds, can the same timer 1 interrupt be use for the above four doors ...

Like if a door is opened and the next door is opened after 3 seconds of the first door then also the siren should provide same timing for 6 seconds to all doors in case if all doors are opened at the different times...

what i mean to ask is will the same timer 1 will provide 6 seconds interval for different door opening conditions...or is there any other technqiue..
 
Insted of monitioring all the bits individually, for faster scanning, check for change of data on Port 2 i.e. check for Port2 != 0xFF (if you have logic low from door sensors) So now when ever you see P2 != 0xFF that means any one or more doors are opened. Just turn on your siren.
I don't think you require to know which door is opened. If so, after checking for change on P2 data, check for individual bits.

Regarding timers: You can use single timer for both scanning and ringing the siren.

A suggestion to you: After reading all your posts, I an make out that you have just started learning microcontrollers and the projects you are doing are just not for beginners. Insted you should try small projects and practice more assembly. Get comfortable with its instruction set and later on do such kind of projects.
 
thanks for the reply sir

SIr,
you are rite about that i have just started to learn assembly but i have made few projects like Digital Clock using latches etc...

Now basic aim is to design software for a 8 lines intercom based on MT8816 and At89c52...

should i use C language instead of assembly...what you suggest...

actually the question iam trying to ask is for telephone off-hook....

like


At this stage iam doing an experiment to learn how to make controller monitor 4 bits i.e detecting if any telephone is off-hook or not and when ever the telephone is off-hook DIAL TONE is supplied to that set:-

Dial Tone is connected at :

Y0 of MT8816

Telephone Sets via SLIC are connected with X0 , X1, X2, X3 rows of MT8816 and

Off-Hook Detection, wires via SLIC are attached with following pins :-

following bits Goes High When Telephone goes off-hook

P2.0

P2.1

P2.3

P2.4


Now let suppose P2.0 goes off-hook , the program simply sents address to MT8816 to connect certain row with Yo column as Yo is the column where the DIAL TONE is present...

now i only want to know how give on checking other bits in such a way that no off-hook is missed out of four lines.





ORG 00H
MOV P3,#00000000B ;STROBE IS CLEARED
MOV P2,#00000000B ;RESETING THE PIN
MOV P1,#00000000B ;RESETING THE PIN
AJMP MAIN

LOOP:
MOV R6,#0FFH
WAIT: DJNZ R6,WAIT
RET

MAIN:
OFF: JNB P2.0,OFF ;WAITING FOR OFF-HOOK
MOV P1,#10010000B ;ADDRESS LINE TO CONNECT Y0 WITH X2
SETB P3.5 ;STROBE IS SET HIGH
CALL LOOP
CLR P3.5 ;STROBE GOES LOW AFTER SOME WHILE
DO: SJMP DO
END
 
For beginners, assembly is suggested to deeply understand the architecture of any uC. If you start using C right from beginning it will be difficult to get the idea of how things are worked out at low level.
 
only off-hook detection help needed

ok , i think my problem is i ask too many question in one post without solving the first...so please guide me only on the following problem... you just give me tips and i will program my self like you ahve done in the previous email...

1) Lets consider four lines at this stage. Now the off-hook ( Logical High) is connected from four phone SLIC to

Out put from SLIC

P2.0 SLIC 1 off Hook /On Hook

P2.1 SLIC 2 off Hook /On Hook

P2.2 SLIC 3 off Hook /On Hook

P2.3 SLIC 4 off Hook /On Hook

-----------

Input in SLIC ( Call progess tones & talking path)

SLIC 1 connected with MT8816 row X0

SLIC 2 connected with MT8816 row X1

SLIC 3 connected with MT8816 row X2

SLIC 4 connected with MT8816 row X3

Now where ever any telephone goes off-hook logical high comes at the above ports...

firstly the controller should sent data from P1 to MT8816 to connect the off-hook slic row with Y0 so that the caller hears dial tone.

at this stage i please guide me how to deisgn a software such that each bit sensing off-hook gets equal time so that no off-hook or on hook is missed and supplying Dial tone to the telephone sets...even if all telephone are off-hook.


considering only one telephone set i have made the following program which works fine..but how to design ISR for mroe than one set.

P2.0 is connected with off-hook/on hook

P3.5 is connected with Srobe of MT8816

P1 sents data to address lines along with set bitto DATA pin of MT8816.


ORG 00H
MOV P2,#00000000B ;RESETING THE PIN
MOV P1,#00000000B ;RESETING THE PIN
MOV P3,#00000000B ;STROBE IS CLEARED

MAIN:
OFFHOOK_WAIT: JB P2.0,TONE
SJMP OFFHOOK_WAIT

TONE:
MOV P1,#10000000B ;ADDRESS LINE TO CONNECT Y0 to WITH X0
SETB P3.5 ;STROBE IS SET HIGH

ONHOOK_WAIT: JB P2.0,ONHOOK_WAIT

MOV P1,#00000000B ;DISCONNECT Y0 to WITH X0
CLR P3.5 ;STROBE IS SET LOW, SWITCH DISCONNECT
SJMP MAIN
END
 
I think you are confused with the timing part. You think that if you scan four bits one by one, then there are chances that you'll miss one of the off/on hooks. But that is not the case. 8051 @ 12MHz takes only abut 1uS to execute the instruction "CJNE". So there will be a difference of only 4uS between 1st bit and 4th bit which is negligible and can you think of a person who can lift the receiver and put it back in 4uS?
 
using CJNE

MOV A,P1
LOOP: CJNE A,#01H,LOOP

will the above command will work if it is required to check Status of entire port...in above case if any bit of P1 goes high the instruction will move forward , if all bits are low it loop around CJNE Line.

Now if the above works how it is possible to find which bit is set ..but if the above does not works any command to check status of entire port and then selecting which bit is set or cleared.
 
i think this is the rite way but still

if i use :

LOOP:
MOV A,P1
CJNE A,#01H,LOOP


now the above will check if any data changes on P1 but if any bit is set what command set i have to use after that to know which bit is set.
 
complete instruction set..

to check port data change;

LOOP:
MOV A,P1
JZ LOOP ; waiting for any High Signal on P2

now finding which bit of P2 is high;

BIT0;
CJNE A,#00000001B,BIT1
SJMP work0 ; program goes to bit p2.0 work

BIT1;
CJNE A,#00000010H,BIT2
SJMP work1 ; program goes to bit p2.1 work

BIT2;
CJNE A,#00000100B,BIT3
SJMP work2 ; program goes to bit p2.2 work

BIT3;
CJNE A,#00001000B,BIT4
SJMP work3 ; program goes to bit p2.3 work

BIT4;
CJNE A,#00010000B,BIT5
SJMP work4 ; program goes to bit p2.4 work

BIT5;
CJNE A,#00100000B,BIT6
SJMP work5 ; program goes to bit p2.5 work

BIT6;
CJNE A,#01000000B,BIT7
SJMP work6 ; program goes to bit p2.6 work

BIT7;
CJNE A,#01000000B,LOOP
SJMP work7 ; program goes to bit p2.7 work

the problem i feel with above patterns is if any other bit is set then ...then i think more checks in the above pattern must be included or suggest other way...

in which bit 1 and 0 status can be checked at the same time and all bit sets or cleared then also ...
 
new code

can some one please explain me the following code which i got from a webiste for monitoring P2 data...for my case of off-hook and On Hook

can ; in data area have...
;
CURR: DS 1 ;place to hold current port 2 sample
PREV: DS 1 ;place to hold previous port 2 sample

;----
; setup in system initialize
;
INIT:
MOV P2, #0FFH ;ensure that P2 works as inputs
MOV CURR, #0FFH ;Init the Current and previous values
MOV PREV, #0FFH
;----
; then in your main polling loop
;
MAIN_LOOP:
MOV A, P2 ;get current input states
MOV CURR, A ;save as current value
;
DO_GO_TO_LOWS: ; ____
CPL A ;compute CURR * PREV
ANL A, PREV ;such that 1 bits show changes from 1->0
;
B0_LOW:
JNB ACC.0, B1_LOW
;
PUSH ACC
CALL PROC_P2_0_LOW ;go off to handle the action for P2.0 going low
POP ACC
;
B1_LOW:
JNB ACC.1, B2_LOW
;
PUSH ACC
CALL PROC_P2_1_LOW ;go off to handle the action for P2.1 going low
POP ACC
;
B2_LOW:
JNB ACC.2, B3_LOW
;
PUSH ACC
CALL PROC_P2_2_LOW ;go off to handle the action for P2.2 going low
POP ACC
;
B3_LOW:
JNB ACC.3, B4_LOW
;
PUSH ACC
CALL PROC_P2_3_LOW ;go off to handle the action for P2.3 going low
POP ACC
;
B4_LOW:
JNB ACC.4, B5_LOW
;
PUSH ACC
CALL PROC_P2_4_LOW ;go off to handle the action for P2.4 going low
POP ACC
;
B5_LOW:
JNB ACC.5, B6_LOW
;
PUSH ACC
CALL PROC_P2_5_LOW ;go off to handle the action for P2.5 going low
POP ACC
;
B6_LOW:
JNB ACC.6, B7_LOW
;
PUSH ACC
CALL PROC_P2_6_LOW ;go off to handle the action for P2.6 going low
POP ACC
;
B7_LOW:
JNB ACC.7, DO_GO_TO_HIGHS
;
PUSH ACC
CALL PROC_P2_7_LOW ;go off to handle the action for P2.7 going low
POP ACC
;
DO_GO_TO_HIGHS:
MOV A, PREV ; ____
CPL A ;compute CURR * PREV
ANL A, CURR ;such that 1 bits show changes from 0->1
;
B0_HIGH:
JNB ACC.0, B1_HIGH
;
PUSH ACC
CALL PROC_P2_0_HIGH ;go off to handle the action for P2.0 going high
POP ACC
;
B1_HIGH:
JNB ACC.1, B2_HIGH
;
PUSH ACC
CALL PROC_P2_1_HIGH ;go off to handle the action for P2.1 going high
POP ACC
;
B2_HIGH:
JNB ACC.2, B3_HIGH
;
PUSH ACC
CALL PROC_P2_2_HIGH ;go off to handle the action for P2.2 going high
POP ACC
;
B3_HIGH:
JNB ACC.3, B4_HIGH
;
PUSH ACC
CALL PROC_P2_3_HIGH ;go off to handle the action for P2.3 going high
POP ACC
;
B4_HIGH:
JNB ACC.4, B5_HIGH
;
PUSH ACC
CALL PROC_P2_4_HIGH ;go off to handle the action for P2.4 going high
POP ACC
;
B5_HIGH:
JNB ACC.5, B6_HIGH
;
PUSH ACC
CALL PROC_P2_5_HIGH ;go off to handle the action for P2.5 going high
POP ACC
;
B6_HIGH:
JNB ACC.6, B7_HIGH
;
PUSH ACC
CALL PROC_P2_6_HIGH ;go off to handle the action for P2.6 going high
POP ACC
;
B7_HIGH:
JNB ACC.7, DO_END_CLEANUP
;
PUSH ACC
CALL PROC_P2_7_HIGH ;go off to handle the action for P2.7 going high
POP ACC
;
DO_END_CLEANUP:
MOV A, CURR ;save the currrent value as next loops previous value
MOV PREV, A
;
JMP MAIN_LOOP ;loop to repeat the polling

;------
; then you have these action subroutines
; to fill in with action code.
;

;
;action for P2.0 going to low
;
PROC_P2_0_LOW:
RET
;
;action for P2.1 going to low
;
PROC_P2_1_LOW:
RET
;
;action for P2.2 going to low
;
PROC_P2_2_LOW:
RET
;
;action for P2.3 going to low
;
PROC_P2_3_LOW:
RET
;
;action for P2.4 going to low
;
PROC_P2_4_LOW:
RET
;
;action for P2.5 going to low
;
PROC_P2_5_LOW:
RET
;
;action for P2.6 going to low
;
PROC_P2_6_LOW:
RET
;
;action for P2.7 going to low
;
PROC_P2_7_LOW:
RET
;
;action for P2.0 going to high
;
PROC_P2_0_HIGH:
RET
;
;action for P2.1 going to high
;
PROC_P2_1_HIGH:
RET
;
;action for P2.2 going to high
;
PROC_P2_2_HIGH:
RET
;
;action for P2.3 going to high
;
PROC_P2_3_HIGH:
RET
;
;action for P2.4 going to high
;
PROC_P2_4_HIGH:
RET
;
;action for P2.5 going to high
;
PROC_P2_5_HIGH:
RET
;
;action for P2.6 going to high
;
PROC_P2_6_HIGH:
RET
;
;action for P2.7 going to high
;
PROC_P2_7_HIGH:
RET
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top