Saturday, November 29, 2014

SOLAR TRACKING PANEL



/* SOLAR TRACKING SYSTEM*/










ORG 0H
ACALL LCDSTART
ACALL DISPLAY
MOV R0,#11H
ACALL STARTMOTOR

LCDSTART: MOV A,#38H
ACALL CMD
ACALL DELAY
MOV A,#0EH
ACALL CMD
ACALL DELAY
MOV A,#01H
ACALL CMD
ACALL DELAY
MOV A,#06H
ACALL CMD
ACALL DELAY
RET

DISPLAY: MOV A,#83H
ACALL CMD
ACALL DELAY
MOV A,#'S'
ACALL DATAWRT
ACALL DELAY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAY
MOV A,#'L'
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'R'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'T'
ACALL DATAWRT
ACALL DELAY
MOV A,#'R'
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAY
MOV A,#'K'
ACALL DATAWRT
ACALL DELAY
MOV A,#'I'
ACALL DATAWRT
ACALL DELAY
MOV A,#'N'
ACALL DATAWRT
ACALL DELAY
MOV A,#'G'
ACALL DATAWRT
ACALL DELAY
MOV A,#0C7H
ACALL CMD
ACALL DELAY
MOV A,#'S'
ACALL DATAWRT
ACALL DELAY
MOV A,#'Y'
ACALL DATAWRT
ACALL DELAY
MOV A,#'S'
ACALL DATAWRT
ACALL DELAY
MOV A,#'T'
ACALL DATAWRT
ACALL DELAY
MOV A,#'E'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#9DH
ACALL CMD
ACALL DELAY
MOV A,#'B'
ACALL DATAWRT
ACALL DELAY
MOV A,#'Y'
ACALL DATAWRT
ACALL DELAY
MOV A,#0D9H
ACALL CMD
ACALL DELAY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAY
MOV A,#'S'
ACALL DATAWRT
ACALL DELAY
MOV A,#'E'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'S'
ACALL DATAWRT
ACALL DELAY
MOV A,#'E'
ACALL DATAWRT
ACALL DELAY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAY
MOV A,#'-'
ACALL DATAWRT
ACALL DELAY
MOV A,#'B'
ACALL DATAWRT
ACALL DELAY
RET

STARTMOTOR: MOV A,#01H
ACALL CMD
ACALL DELAY
MOV A,#82H
ACALL CMD
ACALL DELAY
MOV A,#'S'
ACALL DATAWRT
ACALL DELAY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAY
MOV A,#'L'
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'R'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'T'
ACALL DATAWRT
ACALL DELAY
MOV A,#'R'
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAY
MOV A,#'K'
ACALL DATAWRT
ACALL DELAY
MOV A,#'E'
ACALL DATAWRT
ACALL DELAY
MOV A,#'D'
ACALL DATAWRT
ACALL DELAY
MOV R5,#0DH
BACK: MOV A,R0
MOV P3,A
       MOV R0,A
ACALL DELAY1
MOV A,#9AH
ACALL CMD
ACALL DELAY
MOV A,#'6'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

MOV A,#33H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'7'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

MOV A,#22H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'8'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

MOV A,#66H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'9'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

MOV A,#44H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'1'
ACALL DATAWRT
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

MOV A,#88H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'1'
ACALL DATAWRT
ACALL DELAY
MOV A,#'1'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'A'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY

MOV A,#11H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'1'
ACALL DATAWRT
ACALL DELAY
MOV A,#'2'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'N'
ACALL DATAWRT
ACALL DELAY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAY
MOV A,#'N'
ACALL DATAWRT
ACALL DELAY


MOV A,#33H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#'1'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY


MOV A,#22H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#'2'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY

MOV A,#66H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#'3'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY

MOV A,#44H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#'4'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY


MOV A,#88H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#'5'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY

MOV A,#11H
MOV P3,A

ACALL DELAY1

MOV A,#09AH
ACALL CMD
ACALL DELAY
MOV A,#'0'
ACALL DATAWRT
ACALL DELAY
MOV A,#'6'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAY
MOV A,#'M'
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY
MOV A,#' '
ACALL DATAWRT
ACALL DELAY








RET




CMD: MOV P0,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DATAWRT: MOV P0,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET


DELAY: MOV R7,#0FFH
LOOP2: MOV R6,#0FFH
LOOP1: DJNZ R6,LOOP1
DJNZ R7,LOOP2
RET

DELAY1: MOV R1,#0FFH
BACK3: MOV R2,#50H
BACK2: MOV R3,#50H
BACK1: DJNZ R3,BACK1
DJNZ R2,BACK2
DJNZ R1,BACK3
RET

END









Friday, November 14, 2014

PASSING MESSAGE BETWEEN CLIENT AND SERVER IN SECURE WAY


/****************** CLIENT CODE ****************/



#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

int main()
{
  int welcomeSocket, newSocket;
 struct sockaddr_in serverAddr;
  struct sockaddr_storage serverStorage;
  socklen_t addr_size;
char ptext[20];
 char ctext[20];
 char alpha[26]="abcdefghijklmnopqrstuvwxyz";
 char keyha[26]="noqfgiazywvxumsdtehbjckplr";
 int i,j;


  /*---- Create the socket. The three arguments are: ----*/
  /* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */

  welcomeSocket = socket(PF_INET, SOCK_STREAM, 0);
  
  /*---- Configure settings of the server address struct ----*/
  /* Address family = Internet */

  serverAddr.sin_family = AF_INET;

  /* Set port number, using htons function to use proper byte order */

  serverAddr.sin_port = htons(7891);

  /* Set IP address to localhost */

  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

  /* Set all bits of the padding field to 0 */

  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);  

  /*---- Bind the address struct to the socket ----*/

  bind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr));

  /*---- Listen on the socket, with 5 max connection requests queued ----*/

  if(listen(welcomeSocket,5)==0)
    printf("Listening\n");
  else
    printf("Error\n");

  /*---- Accept call creates a new socket for the incoming connection ----*/

  addr_size = sizeof serverStorage;
  newSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size);

  /*---- Send message to the socket of the incoming connection ----*/

printf("\n Encryption : ");
 printf("\n Enter the plain text :");
 for(i=0;i<6;i++)
scanf("%c",&ptext[i]);
 for(i=0;ptext[i]!='\0';i++)
   for(j=0;alpha[j]!='\0';j++)
   {
if(ptext[i]==alpha[j])
{
ctext[i]=keyha[j];
break;
}
   }
 ctext[strlen(ptext)]='\0';
  
 send(newSocket,ctext,20,0);
}

I used monoaplhabetic cipher to encrypt the message.


/****************** SERVER CODE ****************/

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

int main(){
  int clientSocket,i,j;
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
  char ptext[20];
 char ctext[20];
 char alpha[26]="abcdefghijklmnopqrstuvwxyz";
 char keyha[26]="noqfgiazywvxumsdtehbjckplr";


  /*---- Create the socket. The three arguments are: ----*/
  /* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */

  clientSocket = socket(PF_INET, SOCK_STREAM, 0);
  
  /*---- Configure settings of the server address struct ----*/
  /* Address family = Internet */

  serverAddr.sin_family = AF_INET;

  /* Set port number, using htons function to use proper byte order */

  serverAddr.sin_port = htons(7891);

  /* Set IP address to localhost */

  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

  /* Set all bits of the padding field to 0 */

  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);  

  /*---- Connect the socket to the server using the address struct ----*/

  addr_size = sizeof serverAddr;
  connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);

  /*---- Read the message from the server into the buffer ----*/

  recv(clientSocket, ctext, 6, 0);

  /*---- Print the received message ----*/

printf("the cipher text is");
for(i=0;i<6;i++) 
printf(" %c",ctext[i]);
  for(i=0;ctext[i]!='\0';i++)
  for(j=0;keyha[j]!='\0';j++)
  {
if(ctext[i]==keyha[j])
{
 ptext[i]=alpha[j];
 break;
}
  }
 printf("\n The Plain text is : ");
 for(i=0;i<6;i++)

printf(" %c",ptext[i]);


}

I used monoalphabetic cipher to decrypt the algorithm.

THE OUTPUTS ARE:


First server code should be executed and it will give "listening" output. After that we must execute the client code ,so that it will ask us to enter the key or message(I assumed the message as the key),then we will enter the key(or)message. It will show the encrypted message in client  side and also in server side.Now in server side we can observe both encrypted message and decrypted message .
In this way message is securely travelled from the client system to 
server system. 


server listening to client requests.

             client asking to enter the key or message


Message encrypted
  
Message decrypted


By using monoaplhabetic cipher ,i encrypted and decrypted data.