SlideShare a Scribd company logo
1 of 11
Download to read offline
Code for auto intensity control of street lights:
Code for this project is written in Mikro C for pic. Complete C code for auto intensity control of
street lights is given below :
[sociallocker]// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
unsigned short read_ds1307(unsigned short address)
{
unsigned short r_data;
I2C1_Start();
I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed
by 0 –> 0xD0
I2C1_Wr(address);
I2C1_Repeated_Start();
I2C1_Wr(0xD1); //0x68 followed by 1 –> 0xD1
r_data=I2C1_Rd(0);
I2C1_Stop();
return(r_data);
}
void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C1_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 –> 0xD0
I2C1_Wr(0xD0); // send byte via I2C (device address + W)
I2C1_Wr(address); // send byte (address of DS1307 location)
I2C1_Wr(w_data); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
}
unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + ‘0’);
}
unsigned char BCD2LowerCh(unsigned char bcd)
{
return ((bcd & 0x0F) + ‘0’);
}
int Binary2BCD(int a)
{
int t1, t2;
t1 = a%10;
t1 = t1 & 0x0F;
a = a/10;
t2 = a%10;
t2 = 0x0F & t2;
t2 = t2 << 4;
t2 = 0xF0 & t2;
t1 = t1 | t2;
return t1;
}
int BCD2Binary(int a)
{
int r,t;
t = a & 0x0F;
r = t;
a = 0xF0 & a;
t = a >> 4;
t = 0x0F & t;
r = t*10 + r;
return r;
}
int second;
int minute;
int hour;
int hr;
int ap;
int light;
int pwm;
int ir;
int adc_value = 0;
unsigned short set_count = 0;
short set;
char time[] = “00:00:00 PM”;
void main()
{
I2C1_Init(100000); //DS1307 I2C is running at 100KHz
TRISD = 0x07;
PORTD = 0x00;
TRISE.F0 = 1;
TRISC.F2 = 0; // designate PORTC pins as output
PORTC.F2 = 0; // set PORTC to 0
Adc_Init();
Lcd_Init();
PWM1_Init(5000);
PWM1_Start(); // start PWM1 // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1,1,”Time:”);
do
{
set = 0;
if(PORTD.F0 == 0)
{
Delay_ms(100);
if(PORTD.F0 == 0)
{
set_count++;
if(set_count >= 4)
{
set_count = 0;
}
}
}
if(set_count)
{
if(PORTD.F1 == 0)
{
Delay_ms(100);
if(PORTD.F1 == 0)
set = 1;
}
if(PORTD.F2 == 0)
{
Delay_ms(100);
if(PORTA.F2 == 0)
set = -1;
}
if(set_count && set)
{
switch(set_count)
{
case 1:
hour = BCD2Binary(hour);
hour = hour + set;
hour = Binary2BCD(hour);
if((hour & 0x1F) >= 0x13)
{
hour = hour & 0b11100001;
hour = hour ^ 0x20;
}
else if((hour & 0x1F) <= 0x00)
{
hour = hour | 0b00010010;
hour = hour ^ 0x20;
}
write_ds1307(2, hour); //write hour
break;
case 2:
minute = BCD2Binary(minute);
minute = minute + set;
if(minute >= 60)
minute = 0;
if(minute < 0)
minute = 59;
minute = Binary2BCD(minute);
write_ds1307(1, minute); //write min
break;
case 3:
if(abs(set))
write_ds1307(0,0×00); //Reset second to 0 sec. and start Oscillator
break;
}
}
}
second = read_ds1307(0);
minute = read_ds1307(1);
hour = read_ds1307(2);
hr = hour & 0b00011111;
ap = hour & 0b00100000;
time[0] = BCD2UpperCh(hr);
time[1] = BCD2LowerCh(hr);
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[6] = BCD2UpperCh(second);
time[7] = BCD2LowerCh(second);
if(ap)
{
time[9] = ‘P’;
time[10] = ‘M’;
}
else
{
time[9] = ‘A’;
time[10] = ‘M’; [/sociallocker]
Solution
Code for auto intensity control of street lights:
Code for this project is written in Mikro C for pic. Complete C code for auto intensity control of
street lights is given below :
[sociallocker]// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
unsigned short read_ds1307(unsigned short address)
{
unsigned short r_data;
I2C1_Start();
I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed
by 0 –> 0xD0
I2C1_Wr(address);
I2C1_Repeated_Start();
I2C1_Wr(0xD1); //0x68 followed by 1 –> 0xD1
r_data=I2C1_Rd(0);
I2C1_Stop();
return(r_data);
}
void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C1_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 –> 0xD0
I2C1_Wr(0xD0); // send byte via I2C (device address + W)
I2C1_Wr(address); // send byte (address of DS1307 location)
I2C1_Wr(w_data); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
}
unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + ‘0’);
}
unsigned char BCD2LowerCh(unsigned char bcd)
{
return ((bcd & 0x0F) + ‘0’);
}
int Binary2BCD(int a)
{
int t1, t2;
t1 = a%10;
t1 = t1 & 0x0F;
a = a/10;
t2 = a%10;
t2 = 0x0F & t2;
t2 = t2 << 4;
t2 = 0xF0 & t2;
t1 = t1 | t2;
return t1;
}
int BCD2Binary(int a)
{
int r,t;
t = a & 0x0F;
r = t;
a = 0xF0 & a;
t = a >> 4;
t = 0x0F & t;
r = t*10 + r;
return r;
}
int second;
int minute;
int hour;
int hr;
int ap;
int light;
int pwm;
int ir;
int adc_value = 0;
unsigned short set_count = 0;
short set;
char time[] = “00:00:00 PM”;
void main()
{
I2C1_Init(100000); //DS1307 I2C is running at 100KHz
TRISD = 0x07;
PORTD = 0x00;
TRISE.F0 = 1;
TRISC.F2 = 0; // designate PORTC pins as output
PORTC.F2 = 0; // set PORTC to 0
Adc_Init();
Lcd_Init();
PWM1_Init(5000);
PWM1_Start(); // start PWM1 // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1,1,”Time:”);
do
{
set = 0;
if(PORTD.F0 == 0)
{
Delay_ms(100);
if(PORTD.F0 == 0)
{
set_count++;
if(set_count >= 4)
{
set_count = 0;
}
}
}
if(set_count)
{
if(PORTD.F1 == 0)
{
Delay_ms(100);
if(PORTD.F1 == 0)
set = 1;
}
if(PORTD.F2 == 0)
{
Delay_ms(100);
if(PORTA.F2 == 0)
set = -1;
}
if(set_count && set)
{
switch(set_count)
{
case 1:
hour = BCD2Binary(hour);
hour = hour + set;
hour = Binary2BCD(hour);
if((hour & 0x1F) >= 0x13)
{
hour = hour & 0b11100001;
hour = hour ^ 0x20;
}
else if((hour & 0x1F) <= 0x00)
{
hour = hour | 0b00010010;
hour = hour ^ 0x20;
}
write_ds1307(2, hour); //write hour
break;
case 2:
minute = BCD2Binary(minute);
minute = minute + set;
if(minute >= 60)
minute = 0;
if(minute < 0)
minute = 59;
minute = Binary2BCD(minute);
write_ds1307(1, minute); //write min
break;
case 3:
if(abs(set))
write_ds1307(0,0×00); //Reset second to 0 sec. and start Oscillator
break;
}
}
}
second = read_ds1307(0);
minute = read_ds1307(1);
hour = read_ds1307(2);
hr = hour & 0b00011111;
ap = hour & 0b00100000;
time[0] = BCD2UpperCh(hr);
time[1] = BCD2LowerCh(hr);
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[6] = BCD2UpperCh(second);
time[7] = BCD2LowerCh(second);
if(ap)
{
time[9] = ‘P’;
time[10] = ‘M’;
}
else
{
time[9] = ‘A’;
time[10] = ‘M’; [/sociallocker]

More Related Content

Similar to Auto Street Light Intensity Code PIC C

22 Microcontroller Programs
22 Microcontroller Programs22 Microcontroller Programs
22 Microcontroller Programsbabak danyal
 
2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdfVNEX
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd YearAndrew Kozik
 
Vechicle accident prevention using eye bilnk sensor ppt
Vechicle accident prevention using eye bilnk sensor pptVechicle accident prevention using eye bilnk sensor ppt
Vechicle accident prevention using eye bilnk sensor pptsatish 486
 
22 microcontroller programs
22 microcontroller programs22 microcontroller programs
22 microcontroller programsbabak danyal
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Rodrigo Almeida
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics Felipe Prado
 
Automatic room light controller with visible counter
Automatic room light controller with visible counterAutomatic room light controller with visible counter
Automatic room light controller with visible counterMafaz Ahmed
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for recordG Lemuel George
 
Programming A Robot Using
Programming A Robot UsingProgramming A Robot Using
Programming A Robot UsingSpitiq
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfSIGMATAX1
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfforwardcom41
 

Similar to Auto Street Light Intensity Code PIC C (20)

22 Microcontroller Programs
22 Microcontroller Programs22 Microcontroller Programs
22 Microcontroller Programs
 
2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
 
EEE UNIT-2 PPT.pdf
EEE UNIT-2 PPT.pdfEEE UNIT-2 PPT.pdf
EEE UNIT-2 PPT.pdf
 
Program LCD ARM
Program LCD ARMProgram LCD ARM
Program LCD ARM
 
Vechicle accident prevention using eye bilnk sensor ppt
Vechicle accident prevention using eye bilnk sensor pptVechicle accident prevention using eye bilnk sensor ppt
Vechicle accident prevention using eye bilnk sensor ppt
 
22 microcontroller programs
22 microcontroller programs22 microcontroller programs
22 microcontroller programs
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
 
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics DEF CON 23 - Rodringo Almeida - embedded system design from electronics
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
 
Direct analog
Direct analogDirect analog
Direct analog
 
Automatic room light controller with visible counter
Automatic room light controller with visible counterAutomatic room light controller with visible counter
Automatic room light controller with visible counter
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Mikroc gps
Mikroc gpsMikroc gps
Mikroc gps
 
chapter 4
chapter 4chapter 4
chapter 4
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
Programming A Robot Using
Programming A Robot UsingProgramming A Robot Using
Programming A Robot Using
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
ESD -DAY 24.pptx
ESD -DAY 24.pptxESD -DAY 24.pptx
ESD -DAY 24.pptx
 

More from annaipowerelectronic

Structure Hydra has a tubular body, with only one opening the mouth.pdf
Structure Hydra has a tubular body, with only one opening the mouth.pdfStructure Hydra has a tubular body, with only one opening the mouth.pdf
Structure Hydra has a tubular body, with only one opening the mouth.pdfannaipowerelectronic
 
Quality management ensures that an organization, product or service .pdf
Quality management ensures that an organization, product or service .pdfQuality management ensures that an organization, product or service .pdf
Quality management ensures that an organization, product or service .pdfannaipowerelectronic
 
public class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfpublic class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfannaipowerelectronic
 
Microsoft Excel is a spreadsheet program used to store and retrieve .pdf
Microsoft Excel is a spreadsheet program used to store and retrieve .pdfMicrosoft Excel is a spreadsheet program used to store and retrieve .pdf
Microsoft Excel is a spreadsheet program used to store and retrieve .pdfannaipowerelectronic
 
Mean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdf
Mean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdfMean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdf
Mean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdfannaipowerelectronic
 
Moles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdf
Moles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdfMoles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdf
Moles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdfannaipowerelectronic
 
Lyme disease is a bacterial infection which is caused by bacteria ca.pdf
Lyme disease is a bacterial infection which is caused by bacteria ca.pdfLyme disease is a bacterial infection which is caused by bacteria ca.pdf
Lyme disease is a bacterial infection which is caused by bacteria ca.pdfannaipowerelectronic
 
import java.util.Scanner; import java.util.Random; public clas.pdf
import java.util.Scanner; import java.util.Random; public clas.pdfimport java.util.Scanner; import java.util.Random; public clas.pdf
import java.util.Scanner; import java.util.Random; public clas.pdfannaipowerelectronic
 
above molecule has 12 signlas. .pdf
                     above molecule has 12 signlas.                   .pdf                     above molecule has 12 signlas.                   .pdf
above molecule has 12 signlas. .pdfannaipowerelectronic
 
Hi,I have added a loop for adding values to list. Highlighted the .pdf
Hi,I have added a loop for adding values to list. Highlighted the .pdfHi,I have added a loop for adding values to list. Highlighted the .pdf
Hi,I have added a loop for adding values to list. Highlighted the .pdfannaipowerelectronic
 
D. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdf
D. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdfD. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdf
D. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdfannaipowerelectronic
 
Cracking of petrolium In petroleum geology and chemistry, cracki.pdf
Cracking of petrolium In petroleum geology and chemistry, cracki.pdfCracking of petrolium In petroleum geology and chemistry, cracki.pdf
Cracking of petrolium In petroleum geology and chemistry, cracki.pdfannaipowerelectronic
 
can you provide any aditional information apart from thisSolutio.pdf
can you provide any aditional information apart from thisSolutio.pdfcan you provide any aditional information apart from thisSolutio.pdf
can you provide any aditional information apart from thisSolutio.pdfannaipowerelectronic
 
AnswerMajority of Americans have faster advancing into above 85 y.pdf
AnswerMajority of Americans have faster advancing into above 85 y.pdfAnswerMajority of Americans have faster advancing into above 85 y.pdf
AnswerMajority of Americans have faster advancing into above 85 y.pdfannaipowerelectronic
 
AnswerA compilation error is generated The method f(int) is und.pdf
AnswerA compilation error is generated The method f(int) is und.pdfAnswerA compilation error is generated The method f(int) is und.pdf
AnswerA compilation error is generated The method f(int) is und.pdfannaipowerelectronic
 
a)   There is a cluster of SNP’s with similar p value in the intron .pdf
a)   There is a cluster of SNP’s with similar p value in the intron .pdfa)   There is a cluster of SNP’s with similar p value in the intron .pdf
a)   There is a cluster of SNP’s with similar p value in the intron .pdfannaipowerelectronic
 
A HRIS, which is otherwise called a human resource information syste.pdf
A HRIS, which is otherwise called a human resource information syste.pdfA HRIS, which is otherwise called a human resource information syste.pdf
A HRIS, which is otherwise called a human resource information syste.pdfannaipowerelectronic
 
4 (110000)^3  =  4 s^2 0.01s = 10^-5 MoleslitSolution.pdf
4  (110000)^3  =  4  s^2  0.01s = 10^-5 MoleslitSolution.pdf4  (110000)^3  =  4  s^2  0.01s = 10^-5 MoleslitSolution.pdf
4 (110000)^3  =  4 s^2 0.01s = 10^-5 MoleslitSolution.pdfannaipowerelectronic
 

More from annaipowerelectronic (20)

Structure Hydra has a tubular body, with only one opening the mouth.pdf
Structure Hydra has a tubular body, with only one opening the mouth.pdfStructure Hydra has a tubular body, with only one opening the mouth.pdf
Structure Hydra has a tubular body, with only one opening the mouth.pdf
 
Quality management ensures that an organization, product or service .pdf
Quality management ensures that an organization, product or service .pdfQuality management ensures that an organization, product or service .pdf
Quality management ensures that an organization, product or service .pdf
 
public class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfpublic class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdf
 
Microsoft Excel is a spreadsheet program used to store and retrieve .pdf
Microsoft Excel is a spreadsheet program used to store and retrieve .pdfMicrosoft Excel is a spreadsheet program used to store and retrieve .pdf
Microsoft Excel is a spreadsheet program used to store and retrieve .pdf
 
Mean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdf
Mean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdfMean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdf
Mean = xffS = Sqrt((x-x)2fn)intervalMidpoint(x)frequency.pdf
 
Moles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdf
Moles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdfMoles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdf
Moles of Be = mass of Bemolar mass of Be= (0.33 g)(9.012 gmol).pdf
 
Lyme disease is a bacterial infection which is caused by bacteria ca.pdf
Lyme disease is a bacterial infection which is caused by bacteria ca.pdfLyme disease is a bacterial infection which is caused by bacteria ca.pdf
Lyme disease is a bacterial infection which is caused by bacteria ca.pdf
 
import java.util.Scanner; import java.util.Random; public clas.pdf
import java.util.Scanner; import java.util.Random; public clas.pdfimport java.util.Scanner; import java.util.Random; public clas.pdf
import java.util.Scanner; import java.util.Random; public clas.pdf
 
above molecule has 12 signlas. .pdf
                     above molecule has 12 signlas.                   .pdf                     above molecule has 12 signlas.                   .pdf
above molecule has 12 signlas. .pdf
 
Hi,I have added a loop for adding values to list. Highlighted the .pdf
Hi,I have added a loop for adding values to list. Highlighted the .pdfHi,I have added a loop for adding values to list. Highlighted the .pdf
Hi,I have added a loop for adding values to list. Highlighted the .pdf
 
D. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdf
D. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdfD. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdf
D. ICANNThe Internet Assigned Numbers Authority (IANA) is a depart.pdf
 
Cracking of petrolium In petroleum geology and chemistry, cracki.pdf
Cracking of petrolium In petroleum geology and chemistry, cracki.pdfCracking of petrolium In petroleum geology and chemistry, cracki.pdf
Cracking of petrolium In petroleum geology and chemistry, cracki.pdf
 
can you provide any aditional information apart from thisSolutio.pdf
can you provide any aditional information apart from thisSolutio.pdfcan you provide any aditional information apart from thisSolutio.pdf
can you provide any aditional information apart from thisSolutio.pdf
 
brasstinSolutionbrasstin.pdf
brasstinSolutionbrasstin.pdfbrasstinSolutionbrasstin.pdf
brasstinSolutionbrasstin.pdf
 
AnswerMajority of Americans have faster advancing into above 85 y.pdf
AnswerMajority of Americans have faster advancing into above 85 y.pdfAnswerMajority of Americans have faster advancing into above 85 y.pdf
AnswerMajority of Americans have faster advancing into above 85 y.pdf
 
AnswerA compilation error is generated The method f(int) is und.pdf
AnswerA compilation error is generated The method f(int) is und.pdfAnswerA compilation error is generated The method f(int) is und.pdf
AnswerA compilation error is generated The method f(int) is und.pdf
 
a)   There is a cluster of SNP’s with similar p value in the intron .pdf
a)   There is a cluster of SNP’s with similar p value in the intron .pdfa)   There is a cluster of SNP’s with similar p value in the intron .pdf
a)   There is a cluster of SNP’s with similar p value in the intron .pdf
 
A HRIS, which is otherwise called a human resource information syste.pdf
A HRIS, which is otherwise called a human resource information syste.pdfA HRIS, which is otherwise called a human resource information syste.pdf
A HRIS, which is otherwise called a human resource information syste.pdf
 
4 (110000)^3  =  4 s^2 0.01s = 10^-5 MoleslitSolution.pdf
4  (110000)^3  =  4  s^2  0.01s = 10^-5 MoleslitSolution.pdf4  (110000)^3  =  4  s^2  0.01s = 10^-5 MoleslitSolution.pdf
4 (110000)^3  =  4 s^2 0.01s = 10^-5 MoleslitSolution.pdf
 
2009.88Solution2009.88.pdf
2009.88Solution2009.88.pdf2009.88Solution2009.88.pdf
2009.88Solution2009.88.pdf
 

Recently uploaded

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Auto Street Light Intensity Code PIC C

  • 1. Code for auto intensity control of street lights: Code for this project is written in Mikro C for pic. Complete C code for auto intensity control of street lights is given below : [sociallocker]// LCD module connections sbit LCD_RS at RB2_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections unsigned short read_ds1307(unsigned short address) { unsigned short r_data; I2C1_Start(); I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 –> 0xD0 I2C1_Wr(address); I2C1_Repeated_Start(); I2C1_Wr(0xD1); //0x68 followed by 1 –> 0xD1 r_data=I2C1_Rd(0); I2C1_Stop(); return(r_data); } void write_ds1307(unsigned short address,unsigned short w_data) { I2C1_Start(); // issue I2C start signal //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 –> 0xD0 I2C1_Wr(0xD0); // send byte via I2C (device address + W)
  • 2. I2C1_Wr(address); // send byte (address of DS1307 location) I2C1_Wr(w_data); // send data (data to be written) I2C1_Stop(); // issue I2C stop signal } unsigned char BCD2UpperCh(unsigned char bcd) { return ((bcd >> 4) + ‘0’); } unsigned char BCD2LowerCh(unsigned char bcd) { return ((bcd & 0x0F) + ‘0’); } int Binary2BCD(int a) { int t1, t2; t1 = a%10; t1 = t1 & 0x0F; a = a/10; t2 = a%10; t2 = 0x0F & t2; t2 = t2 << 4; t2 = 0xF0 & t2; t1 = t1 | t2; return t1; } int BCD2Binary(int a) { int r,t; t = a & 0x0F; r = t; a = 0xF0 & a; t = a >> 4; t = 0x0F & t; r = t*10 + r; return r; }
  • 3. int second; int minute; int hour; int hr; int ap; int light; int pwm; int ir; int adc_value = 0; unsigned short set_count = 0; short set; char time[] = “00:00:00 PM”; void main() { I2C1_Init(100000); //DS1307 I2C is running at 100KHz TRISD = 0x07; PORTD = 0x00; TRISE.F0 = 1; TRISC.F2 = 0; // designate PORTC pins as output PORTC.F2 = 0; // set PORTC to 0 Adc_Init(); Lcd_Init(); PWM1_Init(5000); PWM1_Start(); // start PWM1 // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_out(1,1,”Time:”); do { set = 0; if(PORTD.F0 == 0) { Delay_ms(100); if(PORTD.F0 == 0) { set_count++;
  • 4. if(set_count >= 4) { set_count = 0; } } } if(set_count) { if(PORTD.F1 == 0) { Delay_ms(100); if(PORTD.F1 == 0) set = 1; } if(PORTD.F2 == 0) { Delay_ms(100); if(PORTA.F2 == 0) set = -1; } if(set_count && set) { switch(set_count) { case 1: hour = BCD2Binary(hour); hour = hour + set; hour = Binary2BCD(hour); if((hour & 0x1F) >= 0x13) { hour = hour & 0b11100001; hour = hour ^ 0x20; } else if((hour & 0x1F) <= 0x00) { hour = hour | 0b00010010;
  • 5. hour = hour ^ 0x20; } write_ds1307(2, hour); //write hour break; case 2: minute = BCD2Binary(minute); minute = minute + set; if(minute >= 60) minute = 0; if(minute < 0) minute = 59; minute = Binary2BCD(minute); write_ds1307(1, minute); //write min break; case 3: if(abs(set)) write_ds1307(0,0×00); //Reset second to 0 sec. and start Oscillator break; } } } second = read_ds1307(0); minute = read_ds1307(1); hour = read_ds1307(2); hr = hour & 0b00011111; ap = hour & 0b00100000; time[0] = BCD2UpperCh(hr); time[1] = BCD2LowerCh(hr); time[3] = BCD2UpperCh(minute); time[4] = BCD2LowerCh(minute); time[6] = BCD2UpperCh(second); time[7] = BCD2LowerCh(second); if(ap) { time[9] = ‘P’; time[10] = ‘M’;
  • 6. } else { time[9] = ‘A’; time[10] = ‘M’; [/sociallocker] Solution Code for auto intensity control of street lights: Code for this project is written in Mikro C for pic. Complete C code for auto intensity control of street lights is given below : [sociallocker]// LCD module connections sbit LCD_RS at RB2_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections unsigned short read_ds1307(unsigned short address) { unsigned short r_data; I2C1_Start(); I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 –> 0xD0 I2C1_Wr(address); I2C1_Repeated_Start(); I2C1_Wr(0xD1); //0x68 followed by 1 –> 0xD1 r_data=I2C1_Rd(0); I2C1_Stop();
  • 7. return(r_data); } void write_ds1307(unsigned short address,unsigned short w_data) { I2C1_Start(); // issue I2C start signal //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 –> 0xD0 I2C1_Wr(0xD0); // send byte via I2C (device address + W) I2C1_Wr(address); // send byte (address of DS1307 location) I2C1_Wr(w_data); // send data (data to be written) I2C1_Stop(); // issue I2C stop signal } unsigned char BCD2UpperCh(unsigned char bcd) { return ((bcd >> 4) + ‘0’); } unsigned char BCD2LowerCh(unsigned char bcd) { return ((bcd & 0x0F) + ‘0’); } int Binary2BCD(int a) { int t1, t2; t1 = a%10; t1 = t1 & 0x0F; a = a/10; t2 = a%10; t2 = 0x0F & t2; t2 = t2 << 4; t2 = 0xF0 & t2; t1 = t1 | t2; return t1; } int BCD2Binary(int a) { int r,t; t = a & 0x0F;
  • 8. r = t; a = 0xF0 & a; t = a >> 4; t = 0x0F & t; r = t*10 + r; return r; } int second; int minute; int hour; int hr; int ap; int light; int pwm; int ir; int adc_value = 0; unsigned short set_count = 0; short set; char time[] = “00:00:00 PM”; void main() { I2C1_Init(100000); //DS1307 I2C is running at 100KHz TRISD = 0x07; PORTD = 0x00; TRISE.F0 = 1; TRISC.F2 = 0; // designate PORTC pins as output PORTC.F2 = 0; // set PORTC to 0 Adc_Init(); Lcd_Init(); PWM1_Init(5000); PWM1_Start(); // start PWM1 // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_out(1,1,”Time:”); do {
  • 9. set = 0; if(PORTD.F0 == 0) { Delay_ms(100); if(PORTD.F0 == 0) { set_count++; if(set_count >= 4) { set_count = 0; } } } if(set_count) { if(PORTD.F1 == 0) { Delay_ms(100); if(PORTD.F1 == 0) set = 1; } if(PORTD.F2 == 0) { Delay_ms(100); if(PORTA.F2 == 0) set = -1; } if(set_count && set) { switch(set_count) { case 1: hour = BCD2Binary(hour); hour = hour + set; hour = Binary2BCD(hour); if((hour & 0x1F) >= 0x13)
  • 10. { hour = hour & 0b11100001; hour = hour ^ 0x20; } else if((hour & 0x1F) <= 0x00) { hour = hour | 0b00010010; hour = hour ^ 0x20; } write_ds1307(2, hour); //write hour break; case 2: minute = BCD2Binary(minute); minute = minute + set; if(minute >= 60) minute = 0; if(minute < 0) minute = 59; minute = Binary2BCD(minute); write_ds1307(1, minute); //write min break; case 3: if(abs(set)) write_ds1307(0,0×00); //Reset second to 0 sec. and start Oscillator break; } } } second = read_ds1307(0); minute = read_ds1307(1); hour = read_ds1307(2); hr = hour & 0b00011111; ap = hour & 0b00100000; time[0] = BCD2UpperCh(hr); time[1] = BCD2LowerCh(hr); time[3] = BCD2UpperCh(minute);
  • 11. time[4] = BCD2LowerCh(minute); time[6] = BCD2UpperCh(second); time[7] = BCD2LowerCh(second); if(ap) { time[9] = ‘P’; time[10] = ‘M’; } else { time[9] = ‘A’; time[10] = ‘M’; [/sociallocker]