The code provides auto intensity control of street lights using a PIC microcontroller. It reads the time from a DS1307 real-time clock using I2C communication and displays it on an LCD. Pressing buttons allows the time to be adjusted in hours, minutes or seconds. Light intensity is varied based on the time of day read from the RTC.
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++;
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
{