 Welcome myself, Giridhar Jain, assistant professor in Electronics and Telecommunication Engineering, Walchen Institute of Technology, Sholapur. Now today I am going to explain you the programming of interfacing circuits with microcontroller 89C51. Now learning outcomes of this session are at the end of this session students will be able to write assembly language program for interfacing circuits for 89C51 with switches, LED's, matrix keyboard, relay and buzzer. Contents of the session are interfacing of switches and LED, interfacing of switches and relays, interfacing of switches, relays and buzzer. Now this is the interfacing circuit which we have discussed in the last video. So this is matrix keyboard. So for matrix keyboard these are the four lines, these are three and these are four lines used as shown in figure. These are the LED's, this is interfacing of buzzer and these are the relays. So here this is P1.0, P1.1, P1.2, this is 3, P1.4, 5, 6 and 7. So these are the three keys arranged in the first row, three in second, three in third and three key arranged in the fourth. So interfacing of switches and LED. Now write a program if switch S1 is press make LED1 on and if switch S2 is press make LED1 off. So think on solution of this programming task. So here if switch S1 is press LED1 should be made on and if switch S2 is press LED1 should be made off. So this operation is equivalent to a flip lock. Now this is flow chart for this programming task. For any every programming task first you should prepare a flow chart and according to the flow chart the program is to be written. So first decision box check if S1 is pressed. If S1 is pressed if it is yes LED1 is on. If S1 is not pressed no then go to check S2 is pressed. If S2 is pressed if yes LED1 should be made off or if S2 is not pressed then continue in a loop. Means you have to check S1 and S2 continuously and if S1 is pressed you will make LED1 on and if S2 is pressed you have to make that same LED off. Now let us discuss the programming. So first statement for the assembly language program is .org00h. So this is start address after the reset. So when microcontroller is reset the program counter of the microcontroller is pointed toward this address 000h. Therefore first instruction is to be written at this address. Then S jump short jump to a sp .org0040h immediately after this at the address 000h. This location and next to location we can write the S jump instruction and the next memory locations are reserved for the interrupt vector address. Therefore we have to jump to a address other than that. So here .org0040h means the next program is starting from this address 40h. So ST this is a label. So clear P1.4. So why this is done? So clear P1.4 means the row one is active. Make row one active then loop. To check if S1 is pressed jump it bit P1.0 to DN1 check if S1 is pressed. If S1 is pressed then clear P2.0 means LED1 will become on. If S1 is not pressed this is true and it will jump to the DN1. So in this label DN1 jump it bit P1.1 to DN2 check if S2 is pressed. If S2 is not pressed jump to a loop and if S2 is pressed set B P2.0 means P2.0 bit is set to 1 means that LED1 will become off. So LED is made on by outputting 0 at P1.0 and LED is made off by outputting 1 to that port line. So this is a complete program for the programming task given. Means if S1 is pressed LED1 is on here and if S2 is pressed LED1 is off and S jump loop means it will jump in a loop for continuously checking switch S1 and S2. Now next interfacing of switches and relays. Now write a program if switch S1 is pressed make relay one on. If S2 is pressed make relay two on and if S3 is pressed make both the relays off. So .org00h s jump st .org0040 as we have done in the previous program. So first we have to check whether S1 is pressed. So clear P1.0 means make row one active because switch S1 is in the first switch in the row one. So jump if bit P1.0 to DN1 check if S1 is pressed if S1 is pressed clear P2.5. So relay interfacing circuit is connected at P2.5 therefore that bit is clear then check if S2 is pressed. So jump if bit P1.1 to DN2 if switch S2 is pressed make relay two on. So relay two is interfacing at port line P2.4 therefore that port line is clear by the instruction clear P2.4. Next now we have to check whether S3 is pressed and if S3 is pressed we have to make both the relays off. So here DN2 jump if bit P1.2 DN3 check if S3 is pressed. If S3 is pressed we have to make both the relays off means P2.4 and P2.5 should be set. So set B P2.5 relay 1 will become off and set B P2.4 relay 2 will be off DN3 jump in a loop. So jump to a loop for continuously checking if status off switch S1, S2 and S3. Now next is interfacing of switches relays and buzzer. So this is a programming statement write a program if switch S1 is pressed make relay 1 on. If S2 is pressed make relay 2 on. If S3 is pressed make both the relays off. If S4 is pressed make the buzzer on and if S6 is pressed buzzer is made off. So this is extension of earlier programming task. So in earlier programming task we have used switch S1 and S2. If S1 is pressed relay 1 is on, S2 is pressed relay 2 is on and if S3 is switched on or if S3 is on relay 1 and 2 are off. So this is a programming task of earlier program and extension is the interfacing of buzzer. Notice if S4 is pressed buzzer should be on and if S6 is pressed buzzer is off. So this program is earlier program as it is only we have changed. So instead of jumping here in a loop. So we are continuing the program. So dot words is 00H S jump ST dot words is 0040. So row 1 active clear P1.4 jump it bit P1.0 to DN1 check if S1 is pressed relay 1 on. Then check if S2 is pressed jump it bit P1.1 relay 2 on and check if switch S3 is pressed jump it bit P1.2. So relay 1 is off and relay 2 is off. So here previously we are continuing in a loop. So DN3 set B P1.4 means after this means after checking S1, S2 and S3 and by taking the appropriate action we have to activate the next row because switch S4 and S6 are position in the second So set B P1.4 means row 1 is off clear P1.5 means row 2 is active jump it bit P1.0 means check if S4 is pressed if S4 is pressed clear P2.6 means buzzer is on. Now check if switch S6 is pressed. So jump it bit P1.2 to DN5 if S6 is pressed buzzer is off by setting the bit P2.6 by set B P2.6 then DN5 set B P1.5 row 2 is made off clear P1.4 row 1 is made on and S jump in a loop for continuously checking the status of S1, S2, S3, S4 and S6 and taking the appropriate action. So these are the references. Thank you for watching this video.