Auto Power Off Circuit

  • Designed by: Abdulla M. Abdul-Hadi
  • Project: Auto Power Off Circuit
  • Date: 28/5/2010

--------------------------------------------------------------------------------------------

      Hi, this is an Auto Power Off Circuit which can be adding to any old battery powered instruments which have no auto power off feature, this system save your battery from dying!!
let us assume you used your device which work on battries and you forget to turn off after using it, You'll come back to find a dead battery. So, add-on power off circuit to your device will save your batteries.
 
 
 
                                               
 
                                                             Fig.(1): Auto Power Off Schematic
 
 
 
 

YouTube Video

 
 
 
---------------------------------------------------------------------------------------------
Source Code:
/***  Name:Auto Power-off System
Author: Abdulla M. Abdul-Hadi                        
Notice: Copyright (c) 2010 Abdulla M. Abdul-Hadi 
All Rights Reserved             
Date: 28/5/2010 ***/   
 
#include <16F877A.h>
#use delay(clock=10000000)
#fuses hs,nowdt,nocpd,nolvp,noprotect
#define adc=8
 
 unsigned int8 wel[17]={"Battery Voltage?"}; 
 unsigned int8 rec[13]={"I/P Voltage="};
 unsigned char key,key1,key2,key_f;
 unsigned int8 i;
 unsigned int8 x,x1,x2,y;

#byte portb=0x06
#byte portc=0x07
#byte  portd=0x08
 
#bit c1=portd.0
#bit c2=portd.1
#bit c3=portd.2
#bit r1=portd.3
#bit e=portc.4
#bit rs=portc.5
#bit led1=portc.6
#bit led2=portc.7
 
void keypad();
void enableo();
void enabled();
void welcome();
void display_no();
void display_voltage();
 
void main(void)
{
     set_tris_d(0x07);
     set_tris_c(0x00);
     set_tris_b(0x00);
     setup_adc(adc_clock_div_16);
     setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
     set_adc_channel(0);

     welcome();  // ask for batteries voltages
     keypad();   // scan the keypad
     
    if(key==11)
    {
      key=0;
    }
 
    key1=key;
    display_no();  // display the voltage on the LCD
    key=0;
    delay_ms(500);
    keypad();
 
    if(key==1)
    {
      key=0;
    }
 
    key2=key;
    display_no();
    delay_ms(300);
 
    while(1)
    {  
      x=read_adc();   // read the input voltage
      display_voltage();  // display the voltage on the LCD    
    }
  
}
 
void keypad()
{
begin:
  portd=0xf8;
  key=0;
sel_row:
  r1=0;
 
scan:
  key+=1;
  if(c1==0)
  return;
  key+=1;
  if(c2==0)
  return;
  key+=1;
  if(c3==0)
  return;
sel_new_row:
  portd<<=1;
  #asm
  btfsc PORTD,7
  GOTO scan
  GOTO out
  #endasm
out:
  goto begin;
}
 
void enableo()
{
 rs=0;
 delay_ms(10);  //10
 e=1;
 delay_ms(10);  //50
 e=0;
 rs=0;
}
void enabled()
{
 rs=0;
 e=0;
 delay_ms(10);
 rs=1;
 e=1;
 delay_ms(10);
 e=0;
 rs=0;
}
 
void welcome()
{
 output_b(0x0F);  // clear LCD and the cursor will be at location 0
 enableo();
 output_b(0x38);  // 5x7, 2-lines option
 enableo();
 delay_ms(50);  //50
 for(i=0;i<=15;i++)
 {
  output_b(wel[i]);
  enabled();
  delay_ms(50);  //10
 }
 output_b(0xc0);  // cursor jumb to next line
 enableo();
 delay_ms(50);  //50
}
 
// diplay the received voltage on the LCD
void display_no()
{
 key=key+0x30;  // convert it to ASCII
 output_b(key);  // display the entered voltage on the LCD
 enabled();
 delay_ms(100);
 
 
}
  
// display the received voltage on the ADC channel(0)
void display_voltage()
{
 output_b(0x01);   // clear the LCD
 enableo();
       //10 delay
 for(i=0;i<=12;i++)  // display message then voltage value
 {
  output_b(rec[i]);
  enabled();
 }
 x=x-4;
 x=(x/7);
 x1=x&0x0F;
 x2=x>>4;
 x2=x2&0x0F;
 y=x1+x2+9; 
 output_b(x2+0x30);
 enabled();
 output_b(x1+0x30);
 enabled();
 delay_ms(1000);
 if(key1==0)
 {
  key_f=key2;
 }
 
 if(key1=!0)
 {
  key_f=key1+key2+9;
 }
 if((key_f>y)&&((key_f-y)>=2))
  {
   led1=1;
   led2=1;
  }
 
 if(y>key_f)
 {
   led2=0;
   led1=0;
 }
}
Comments