Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

automatic device turn off and on

Status
Not open for further replies.

aneeshere

Junior Member level 1
Joined
Jun 21, 2010
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,436
guys,

I want to automatically turn on a device(example led) everyday morning 8.00 to 9.00 and keep it on for the rest of the day for all days.
I designed a clock using ds1307 and pic16f877a and lcd display.
now how do i do the rest?
please help me..
thanks
 

if you read the ds1307 RTC in a loop, turn on the device when the time reaches 8:00 and off at 9:00
 

how do i check the time through program. i already tried it in proteus but got no response.i tried to do it when the minute becomes 11 just for simulation purposes but it is not responding.

i tried while(minute == 11)
{
porta.f0=0;
}

also tried
while (time[3] == 1 && time[4] ==1)
{
porta.f0=0;
}

did not work
 

if you wish to switch on a 8:00 and off at 9:00 all you need to do it test if the hour is 8 if so switch on else switch off
assume functions to read the RTC etc code would be something like
Code:
  while(1)
    {
     int hour=readRTC();
     if(hour==8) switchON();
     else      switchOFF();
    }
don't forget the ds1307 stores its data in BCD you have to convert it to decimal

have a look at
DS1307 RTC tutorial
 

ill paste my program here.

unsigned short read_ds1307(unsigned short address );
void write_ds1307(unsigned short address,unsigned short w_data);
unsigned short sec;
unsigned short minute;
unsigned short hour;
unsigned short day;
unsigned short date;
unsigned short month;
unsigned short year;
unsigned short data;
char time[9];
char ddate[11];

unsigned char BCD2UpperCh(unsigned char bcd);
unsigned char BCD2LowerCh(unsigned char bcd);

void main(){

I2C_Init(100000);
PORTB = 0;
TRISB = 0;
PORTA = 0;
TRISA = 0;
TRISC = 0xFF;
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
Lcd_Out(1, 1, "TIME:");
Lcd_Out(2, 1, "DATE:");

//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x10); //write min 10
write_ds1307(2,0x01); //write hour 01
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x05); // write date 05
write_ds1307(5,0x01); // write month 1
write_ds1307(6,0x09); // write year 9
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator

while(1)
{
sec=read_ds1307(0); // read second
minute=read_ds1307(1); // read minute
hour=read_ds1307(2); // read hour
day=read_ds1307(3); // read day
date=read_ds1307(4); // read date
month=read_ds1307(5); // read month
year=read_ds1307(6); // read year

time[0] = BCD2UpperCh(hour);
time[1] = BCD2LowerCh(hour);
time[2] = ':';
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[5] = ':';
time[6] = BCD2UpperCh(sec);
time[7] = BCD2LowerCh(sec);
time[8] = '\0';

ddate[0] = BCD2UpperCh(date);
ddate[1] = BCD2LowerCh(date);
ddate[2] ='/';
ddate[3] = BCD2UpperCh(month);
ddate[4] = BCD2LowerCh(month);
ddate[5] ='/';
ddate[6] = '2';
ddate[7] = '0';
ddate[8] = BCD2UpperCh(year);
ddate[9] = BCD2LowerCh(year);
ddate[10] = '\0';

Lcd_Out(1,6,time);
Lcd_Out(2,6,ddate);
Delay_ms(50);

while(minute == 11)
{
PORTA.F1=1;
}
}
}

unsigned short read_ds1307(unsigned short address)
{
I2C_Start();
I2C_Wr(0xd0);
I2C_Wr(address);
I2C_Repeated_Start();
I2C_Wr(0xd1);
data=I2C_Rd(0);
I2C_Stop();
return(data);
}

unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + '0');
}

unsigned char BCD2LowerCh(unsigned char bcd)
{
return ((bcd & 0x0F) + '0');
}
void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C_Start();
I2C_Wr(0xD0);
I2C_Wr(address);
I2C_Wr(w_data);
I2C_Stop();
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top