Total Pageviews

Monday, September 22, 2014

MASTER SLAVE CONTROL using AT89C51


Assalam u Alaikum ! Today I want to share my fourth year's Microcontroller AT89C51 based project of Master Slave Control. Hope it helps you in your studies ! :)




MASTER SLAVE CONTROL
AT89C51

Introduction

There has always been needs of performing many operations on different locations through a single controller. Master Slave Control is the technique that provides these features of performing and controlling various operations in different locations.
As the name suggests, there is one master controller and one or more slave controllers. AT89C51 supports up to 255 slave controllers that can be utilized in different areas for different requirements. Master Controller is used to perform certain operations and instructs the slave controls to perform required operations as well.
Transmission and reception between master and slave controls is done serially through the Rx and Tx pins of the microcontrollers. Multiprocessing ability of the microcontrollers is thus utilized in this technique. There can also be a shift in master and slave controllers, one controller can become master or slave at any instant of time to handle the shifting of controls for required operations.
In our project we have used master slave control for the delivering the input of keyboard on the LCD and the LED’s. In our project, keyboard and LCD is attached to the master controller and the LEDs’ are attached with slave controllers. Each controller has 8 LEDs’ to show the BCD equivalent of the Number entered from the keyboard.




Block diagram


PROGRAM
MASTER CODE

lcd_data equ 090h
lcd_e equ P3.5
lcd_rw equ P3.3
lcd_rs equ P3.4
CTWRDARST EQU 01100011B
CNTWRDAOPR EQU 00100011B
CNTRWRBSTART EQU 00011010B
CONFIG EQU 38H
ENTRYMODE EQU 6
OFFCUR EQU 0CH
LINECUR EQU 0EH
BLINKCUR EQU 0DH
COMBNCUR EQU 0FH
HOMECUR EQU 02H
SHLFCUR EQU 10H
SHRTCUR EQU 14H
CLRDSP EQU 01H
OFFDSP EQU 0AH
ONDSP EQU 0EH
SHLFDSP EQU 18H
SHRTDSP EQU 1CH



ORG 0000H
LJMP MAIN

ORG 0003H
LJMP KBRFDISP                                      // KEYBOARD INTERRUPT

MAIN :

LCALL INITRS232                                              // INITIALIZE SERIAL
LCALL RESETLCD                                              //RESET LCD
LCALL INITLCD                                                  // INITIALIZE LCD
MOV P2,#OFFH                                           // INPUT FROM KEYBOARD
MOV IE,#100000001B
SETB IT0                                                    // INTERRUPT ENABLE
SJMP $                                                                 // REPEAT FOREVER

KBRDISP:
MOV A,P2
ANL A,#0FH
LCALL BCDTOASCII                        // BCD TO ASCII FOR LCD
LCALL LCALL WRLCDDATA                     // LCD PRINTING
LCALL PUTCHAR                                     // SERIAL TRANSMISSION
RETI
PUTCHAR:
JNB TI,$              // WAIT FOR PREVIOUS DATA TO BE TRANSMITTED
CLR TI
CLR TB8                                           //PREPARE FOR TRANSMIT
MOV SBUF,A
SETB TB8
RET
INITRS232:
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#11001000B                         \\ FOR MODE-2 , TB8=1
SETB TR1
RET
RESETLCD:
CLR LCD_RS
CLR LCD_RW
CLR LCD_E
MOV R0,#30H
SETB LCD_E
CLR LCD_E
MOV A,#4
LCALL DELAY
MOV LCD_DATA,#30H
SETB LCD_E
CLR LCD_E
MOV A,#1
LCALL DELAY
MOV LCD_DATA,#30H
SETB LCD_E
CLR LCD_E
MOV A,#1
LCALL DELAY
MOV R0,#CONFIG
LCALL WRLCDCOM
MOV R0,#08H
LCALL WRLCDCOM
MOV R0,#01H
LCALL WRLCDCOM
MOV R0,#ENTRYMODE
LCALL WRLCDCOM
RET
DELAY:
MOV R7,A
AGA:
MOV TH0,#0FCH
MOV TL0,#17H
SETB TR0
WAIT2:
JNB TF0,WAIT2
CLR TF0
CLR TR0
DJNZ R7,AGA
RET
WRLCDCOM:
CLR LCD_E
CLR LCD_RS
CLR LCD_RW
MOV LCD_DATA,R0
LCALL PULSEEWAIT
RET
INITLCD:
CLR LCD_RS
CLR LCD_RW
CLR LCD_E
MOV R0,#38H
LCALL WRLCDCOM
MOV R0,#0EH
LCALL WRLCDCOM
MOV R0,#06H
LCALL WRLCDCOM
MOV R0,#01H
LCALL WRLCDCOM
RET

BCDTOASCII:
CJNE A,#0AH,$+3
JNC BIG
ADD A,#30H
SJMP EXIT
BIG:
ADD A, #37H
EXIT:
MOV R0,A
RET

WRLCDDATA:
CLR LCD_E
SETB LCD_RS
CLR LCD_RW
MOV LCD_DATA,R0
LCALL PULSEEWAIT
RET
PULSEEWAIT:
CLR LCD_E
SETB LCD_E
CLR LCD_E
MOV LCD_DATA,#0FFH
SETB LCD_RW
PUSH ACC
PEW:
INC B
SETB LCD_E
MOV A,LCD_DATA
CLR LCD_E
JB ACC.7,PEW
POP ACC
RET
SLAVE 1 CODING

ORG 0000H
MOV TMOD,#20H                                               //9600 BAUD
MOV TH,#-3
MOV SCON, #0F0H                //ENABLE RECEIVER MODE 3 , MULTIPROC ENABLED
SETB TR1

BACK:
JNB RI,$                                                    // WAIT FOR CODE
CLR RI
MOV A,SBUF
CJNE A,#0AH,BACK
CLR SM2                                                   // SIMPLE PROCESSOR


GAIN:
JNB RI,$                                                    // WAIT FOR DATA
CLR RI
MOV A,SBUF
CJNE A,#ODH,AGAIN                               // D IS USED FOR RESET
SETB SM2                                                 // MULTI PROC ENABLED
SJMP BACK
AGAIN:
MOV P1,A
SJMP GAIN

SLAVE  2 CODING

ORG 0000H
MOV TMOD,#20H                                     //9600 BAUD
MOV TH,#-3
MOV SCON, #0F0H                 //ENABLE RECEIVER MODE 3 , MULTIPROC ENABLED
SETB TR1
BACK:
JNB RI,$                                                    // WAIT FOR CODE
CLR RI
MOV A,SBUF
CJNE A,#0BH,BACK
CLR SM2                                                   // SIMPLE PROCESSOR
GAIN:
JNB RI,$                                                    // WAIT FOR DATA
CLR RI
MOV A,SBUF
CJNE A,#ODH,AGAIN                               // D IS USED FOR RESET
SETB SM2                                                 // MULTI PROC ENABLED
SJMP BACK
AGAIN:
MOV P1,A
SJMP GAIN

SLAVE 3 CODING

ORG 0000H
MOV TMOD,#20H                            //9600 BAUD
MOV TH,#-3
MOV SCON, #0F0H                 //ENABLE RECEIVER MODE 3 , MULTIPROC ENABLED
SETB TR1

BACK:
JNB RI,$                                           // WAIT FOR CODE
CLR RI
MOV A,SBUF
CJNE A,#0CH,BACK
CLR SM2                                          // SIMPLE PROCESSOR

GAIN:
JNB RI,$                                           // WAIT FOR DATA
CLR RI
MOV A,SBUF
CJNE A,#ODH,AGAIN                      // D IS USED FOR RESET
SETB SM2                                        // MULTI PROC ENABLED
SJMP BACK

AGAIN:
MOV P1,A
SJMP GAIN




CONSTRUCTION
In Master Controller:
P1 is connected with LCD with control inputs from P3.
P2 is connected with Keyboard through the keyboard decoder MM74C922.
TxD Pin of Master Controller is connected with RxD pins of all slave controllers.
Each controller is properly provided crystal frequency, VCC and Ground.
In Slave Controllers:
P1 of each controller is allotted to 8 LEDs’ to show the BCD code coming from the Master Controller.

WORKING

If we analyze the program step by step then,
In main routine:
1-    RS232 serial communication is initialized in MODE 2 UART and TB8=1 for addressing in multiprocessors using suitable value in SCON register also baud rate of 9600 is set for communication.
2-    LCD is reset and initialized using separate routines.
3-    Then Port 2 which is connected to keyboard is made ready to accept input.
4-     Interrupt zero is enabled which is related to keyboard and on every key press interrupt is activated KBRDISP routine is activated.
In KBRDISP routine:
1-    Data from keyboard in port 2 is moved to accumulator.
2-    Upper nibble of data is masked as keyboard consists of 15 keys 0-F.
3-    This masked BCD code is sent to BCDtoASCII routine where it is converted in ASCII to be shown on LCD by adding suitable values (30H or 37H) in the data in accumulator.
4-    This ready to display data is sent to WRLCDDATA routine where it is printed on LCD.
5-    Then a Routine called PUTCHAR is called to transmit data to slave controllers.
In PUTCHAR routine:
1-    TI flag is used to check if the transmitter is busy or ready to send data.
2-    Then by clearing RB8 data is made ready to send, and by using SBUF data is sent and RB8 is set again for addressing.

So the process of master controller which is taking data from the keyboard, writing it to LCD and sending to other slave controllers over TxD is completed.
Now we move to the Slaves coding where they are ready to accept data.
In Slaves:
1-    First of all Baud rate of slave controller is set to match with master controller to achieve proper communication.
2-    Then slave controllers are initialized in mode 3 UART and Multiprocessor is enabled by moving suitable value in SCON register.
3-    Then Receivers wait for the code to arrive and when it arrives it is checked for the value of A,B,C for slave 1,2,3 respectively.
4-    If the code of any slave is matched then that slave is activated and Simple processor is enabled.
5-    It again waits for the inputs from the keyboard and displays on the LEDs’ until D key is pressed from the keyboard is pressed.
6-    D key of keyboard acts as a reset for the controller and Multiprocessors are again enabled and the control is transferred to initial position where all the slave controllers wait for the coming code and all the process is repeated.

Conclusion


This technique can be employed in the wide distances, where the sent code from the Master microcontroller can still be seen on slave controllers instead of being distant from the slave controller. This technique can be employed in industries as well as other machineries where one needs to handle many machines or equipment using single remote microcontroller.

Wireless Temperature Sensor With Arduino UNO and SIM900D (Program Included)


Assalam u Alaikum ! Today I want to share my fourth year Microwave Communication project with you guys. Hope you like it and you are welcomed to ask any questions if any problem arises ! :)



Wireless Temperature Monitor
With Arduino UNO and SIM900D
Wireless Temperature Monitor is a multipurpose device to be used in any applicable area. Salient features of this device are
            (1) Temperature Sensing
            (2) Reporting
Temperature sensing is very important parameter of the device. Sensing the temperature on different instances enables the user to perform necessary and required action whenever needed. For example, if a user wants to operate the heater in his room, He might feel the temperature and would turn the heater on or off. Using this device, sensing of temperature is automatically performed and by sufficient changes it can allows the user to automate the heaters’ on off process.
 After the temperature is sensed, user might know what temperature has been sensed so that he could perform required action. This device Reports to the user on user-defined parameters. Reporting is being done through GSM technology which is widely available and is user friendly. User would be reported on his cell phone about the temperature automatically on different time intervals.



 Circuit Diagram

 Circuit Analysis
First Temperature sensor is given Ground and VCC through the Arduino board. Then, LM35’s output is fed to pin 1 of the Arduino board which is defined in the source code.
For connecting the GSM Module with the Arduino we simply connect RXD pin of the Arduino to the TXD pin of GSM and TXD pin of Arduino to the RXD pin of GSM.
These connections will take analog input present at pin 1 from the sensor and convert them digitally inside, then after comparison in the program, data would be sent through the TXD pin of Arduino to the RXD pin of GSM which would send it through the mobile carrier service to the user.
  Source Code
float temp;
int tempPin = 1;
float rem;
void setup()
{
  Serial.begin(9600);  //Baud rate of the GSM/GPRS Module
   temp = analogRead(tempPin);
  temp = temp * 0.48828125;
}
void loop()
{
 rem = analogRead(tempPin);
 rem = rem * 0.48828125;
  if(rem>=temp+2 || rem<=temp-2)
  {
    Serial.print("\r");
  delay(1000);                 
  Serial.print("AT+CMGF=1\r");   
  delay(1000);
  Serial.print("AT+CMGS=\"+923005100300\"\r");    //Number to which you want to send the sms
  delay(1000);
    Serial.print("Current Temperature is : ");
  Serial.print(rem);   //The text of the message to be sent
  delay(1000);
  Serial.write(0x1A);
  delay(1000);
  delay(1000);
  delay(1000);
  temp = rem;
}

}

This program is written for every 2 degree change in temperature , you can change it .