Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

software multi-tasking using 8051 1

Status
Not open for further replies.

lanceaustin

Programmer
May 5, 2003
23
DE
Iam looking forward to learn to use 8051 controller to work for multi-purpose at the same time but don't understand how.


Lets suppose;

I want the controller to monitor P2.0 to P2.4 ,

when ever a bit is High i.e SET controller jumps to a specific Label to perform certain task like connecting a analog switch like MT8816 but at the same time controller should also keep on monitoring other pins and the pin which is just set whether the pin which is just set goes low or not...

e.g.


using 89c52 & MT8816 analog switch

; P2.0 is connected with a device which will sents a high or low signal.
; Port 1 is connected with a analog switch to sent 8 bit data when ever the P2.0 goes High.
; the analog switch remain connected for 10 seconds using timer 0 in 16-bit mode and then gets disconnected but at the same time controller also keep track whether P2.0 goes low if this happens then every thing is stopped.
; cs PIN IS Permittely high.
; strobe pin of MT8816 connected with Pin15 i.e P3.5
; address lines of MT8816 connected on P1.0 to P1.7 and DATA pin is connected with controllers P1.8
; I want to connect X0 with Y0


ORG 00H
LJMP MAIN
ORG 000BH ;timer 0 vector address
LJMP T0_ISR




MAIN:
MOV P2.0,#00H ;clearing Pin2.0
JNB P2.0,$ ;do nothing except for checking High signal
MOV TMOD,#02 ;timer 0 in mode 2
MOV R7,#100 ;10 X 5000 = 10 SECONDS.
MOV P3.5,#01H ;strobe pin is set high
MOV P1,#00000001B ;address for MT8816 and 1 for DATA pin.
MOV IE,#82H
SETB TR0
JNB P2.0
MOV P2.0,#00H ;clearing Pin2.0
END



T0_ISR:
CLR TR0 ;stop timer
DJNZ R7,SKIP ; decrement for 10 seconds.
CLR TR0
LJMP EXIT


SKIP:
MOV THO,#HIGH(-50000)
MOV TLO,#LOW(-50000)
SETB TR0
EXIT: RETI


the above programs may have some bugs or many more than enough but the idea is to keep connecting X0 with YO untill the bit P2.0 is set low or 10 seconds are passed, if the bit P2.0 is not goes low uptill 20 seconds then also the connection get disconnected.

But Here if there are four device connected at

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

and controller has to check all bits at all times and which ever goes high is connected with Y0.
how to provide all the above bit same facility at the same time.

the condition is if all four are High at the same time all should be connected with Y0, all these devices connected to these bits are also connected with X0, X1,X2,X3 rows of MT8816.
 
erm, maybe you cant provide the same functionality for all pin at the same time?

if you examine PIC architecture you will see that every pin can be given a priority. the PIC will service each pin interrupt in order of priority until no interrupt requests exist and so on.

multitasking does not occur with interrupts. the interrupt service routines execute with interrupts disabled and return promptly and when many execute in rapid succession they give the impression of multitasking.

i hope this will lead you to a solution.
straiph


"There are 10 types of people in this world, those who know binary and those who don't!"
 
straiph,
that is abostuley correct.. but iam using AT89c52 controllers as these are the only onces avaiable in my region and most important i only know there assembly coding...

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..

but please do provide me some example for monitoring the bits....















 
Hello to all of you,

As i am testing MT8816 with microcontroller using following configuration:

1) P1 is connected with address Lines of MT8816 along with DATA pin at P1.7.
2) Dial Tone is coming at Y0
3) Telephone is connected with MT8816 row X0

the program is written in such a way that when ever power is supplied to controller, it sents data to MT8816 and connects X0 with Y0 ( MOV P1,#10000000B)

Now this works fine but when i set my software in such a way that first the controller should detect off-hook and then make connection of X0 with Y0 and disconnection occur when the set is on-hook... the software does not work...

Off hook / on hook = P2.0 . this signal is coming from LM3900 Comparator which is giving 0.04 volts at ON-HOOK and 0.51 volts at OFF-HOOK.


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


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,DISCONNECTING_TONE
SJMP ONHOOK_WAIT

DISCONNECTING_TONE:
MOV P1,#00000000B ;DISCONNECT Y0 to WITH X0
CLR P3.5 ;STROBE IS SET LOW, SWITCH DISCONNECT

SJMP MAIN
END
 
it depends how you want it to work - i got confused along the way lol

ok - my 2 suggestions.

1st is simple - it sounds when any door is open and will only resound after all doors have been closed.

write the status of each pin to consecutive bits in a byte. if the byte>zero then set the alarm bit. byte=zero reset alarm bit. if alarm bit=on the sound for 6 seconds.

2nd example will sound when ever a door interlock changes status.

write the status of each pin to consecutive bits in a byte. compare with memory byte variable. if different write the read byte to the memory byte and sound for 6 seconds.

as with your telephone - have you tried slowing it down abit to allow the affects occur before you test for them?


"There are 10 types of people in this world, those who know binary and those who don't!"
 
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.

Is there any specifications which shows timer requirement for scanning the bits.
 
using the following:-

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

or

LOOP: MOV P1,#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 instruction break out of loop but what instruction should i use after that to find which bit is set and what if out of 8 bits 6 or 7 set in some interval and also 1 or 2 bits are cleared...how to tackle this...

means 8 telephone sets are connected with P1 and software enables the controller to see if any off-hook occur but which set is off hook how to write command for this.
 
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 ...
 
can some one please explain me the following code use to Monitor High and Low Signal at P2 , off hook = 1 , On Hook = 0;----
; 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.

Part and Inventory Search

Sponsor

Back
Top