project for checking status of lights very day 12 :11 am

   project for checking status of lights very day 12 :11 am

 
Descripition :

Where it help to save the power in big bulidings it will checking the lights states in very room where according your configure desigined  where you can send meassage to pariticular floor this room turn off lights thorght bluetooth commonds.


project code



#include<lpc21xx.h>
#include "delayheader.h"
#include "lcdheader.h"
#include<string.h>
     
void init_rtc(void);

void init_rtc()
{
 lcdstring("Digital timer");
 CCR=(1<<0);   // enable
 PREINT=456;   // crystel oscillator giving 15Mhz, but rtc will work at 32.768khz  to scle this we are using formula and geting this number 
 PREFRAC=25024;
 HOUR=12;
 ALHOUR=12;
 ALMIN=10;
 MIN=11;
 SEC=0;
}
int main()
{
 
 int i;
 char *password="check";
char recvpass[5];
    lcdinit();
     uart_int();
 init_rtc();
 while(1)
 {
  lcdcmd(0xc0);  
  lcddata(HOUR/10+0x30); // we can use '0' = 48 = (0x30)  i to a conertions
  if(ALHOUR==HOUR&&MIN==ALMIN)
  {
   if(IOPIN1&(1<<17))
{
  uart_tx_string("some lights turn on");
  IOSET1=(1<<17);
}
  }
  else
  {
   uratstart();
  lcddata(HOUR%10+0x30);
  lcddata(':');
  lcddata(MIN/10+0x30);
  lcddata(MIN%10+0x30);
  lcddata(':');
  lcddata(SEC/10+0x30);
  lcddata(SEC%10+0x30);
   for(i=0;i<5; i++)
 {    
   recvpass[i]=uart_rx();
     uart_tx(recvpass[i]);
 }
 if(strncmp(password,recvpass,5)==0)
 {
        uart_tx_string("stop lights ");
        IOCLR1=(1<<17);
  }
 
 }
 }
}


Another function code


#include<lpc21xx.h>
#include "lcdheader.h"
#include "delayheader.h"
void lcdinit(void)
{
IODIR0 |= RS|RW|EN|DATA_PINS;
 lcdcmd(0x38);
 lcdcmd(0x0E);
 lcdcmd(0x01);
 lcdcmd(0x80);
}

void lcdcmd (int cmd)
 {
  IOCLR0 = (DATA_PINS);
  IOSET0 = (cmd<<15);
  IOCLR0 = RS;
  IOCLR0 = RW;
  IOSET0 = EN;
  delay(50);
  IOCLR0 = EN;
 }
//--------------------------//
void lcddata (int data)
  {
     IOCLR0 = (DATA_PINS);
  IOSET0 = (data<<15);
  IOSET0 = RS;
  IOCLR0 = RW;
  IOSET0 = EN;
  delay(50);
  IOCLR0 = EN;
  }
//--------------------------//
void lcdstring(char *string)
{
 while(*string!='\0')
  {
  lcddata(*string);
  string++;
  }
}
//-------------------------//

void lcdstringmul(char *str)
{
 int count=1;
 while(*str)
 {
  lcddata(*str);
  str++;
  count++;
  if(count==16)
   lcdcmd(0xc0);
  if(count==32)
  {
   lcdcmd(0x01);
   lcdcmd(0x80);
   count=1;
  }
 }
}
void lcd_num(int num)
{
 if(num)
 {
  lcddata((num%10) +0x30);
  lcd_num(num/10);
 }
}
 void uart_int(void)
{

 PINSEL0 |= (1<<0)|(1<<2);    // configuring the UART funtion
 PINSEL0 &= ~((1<<1)|(1<<3));
 U0LCR = (1<<0)|(1<<1)|(1<<7);  // configuring line control register(LCR),DLATCH
 U0DLM = 0;        // Loding value DLM and DLL
 U0DLL = 97;
 U0LCR = (1<<0)|(1<<1);     // disable the DLATCH register
}
char uart_rx (void)
 {
   while(!(U0LSR & (1<<0)));
   return (U0RBR);
 }
void uart_tx(char c)
 {
  while(!(U0LSR & (1<<5)));
  U0THR = c;
 }
 void uart_tx_string(char *str)
  {
  while(*str)
  {
  uart_tx(*str);
  str++;
  }
  }
  void uratstart()
   {
   while(1)
   {
   uart_tx(uart_rx());
   }
   }












Comments

Popular posts from this blog

READING VALUES FROM SENSOR AND THAT WRITING TO EEPROM