PIC Microcontroller
Thursday, January 20, 2022
Real Time Clock With PIC16F877A
This Project will demonstrate the real time clock interface with PIC 16F877A
To do this project we need following software:
CODE
//DS1307 Real Time Clock with PIC16F877A
// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD module connections
unsigned char *text, second, second10, minute,
minute10,
hour, hour10, date, date10,
month, month10,
year, year10, day, i = 0;
void
display()
{
//Split data into tow parts
second10 = (second & 0x70) >> 4;
second = second & 0x0F;
minute10 = (minute & 0x70) >> 4;
minute = minute & 0x0F;
hour10 = (hour & 0x30) >> 4;
hour = hour & 0x0F;
date10 = (date & 0x30) >> 4;
date = date & 0x0F;
month10 = (month & 0x10) >> 4;
month = month & 0x0F;
year10 = (year & 0xF0) >> 4;
year = year & 0x0F;
//Display Time
Lcd_Chr(1, 13, second + 48);
Lcd_Chr(1, 12, second10 + 48);
Lcd_Chr(1, 10, minute + 48);
Lcd_Chr(1, 9, minute10 + 48);
Lcd_Chr(1, 7, hour + 48);
Lcd_Chr(1, 6, hour10 + 48);
//Display calendar
Lcd_Chr(2, 7, date + 48);
Lcd_Chr(2, 6, date10 + 48);
Lcd_Chr(2, 10, month + 48);
Lcd_Chr(2, 9, month10 + 48);
Lcd_Chr(2, 15, year + 48);
Lcd_Chr(2, 14, year10 + 48);
}
void
main()
{
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1, "REAL TIME CLOCK");
LCD_Out(2,1, "GSM MAHFUZ LIKHON");
delay_ms(2000);
LCD_Cmd(_LCD_CLEAR);
TRISB = 3;
Lcd_Init(); //
Initialize LCD
Lcd_Cmd(_LCD_CLEAR); //
Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn
cursor off
I2C1_Init(100000); //
initialize I2C at 100KHz
return_:
text = "TIME: : :" ;
Lcd_Out(1, 1, text);
text = "DATE: / /20" ;
Lcd_Out(2, 1, text);
write_value(0, 0); //Reset
seconds and start oscillator
while(1)
{
if(i == 1)
{
Lcd_Cmd(_LCD_CLEAR);
text = "Adjust Minute:";
Lcd_Out(1, 2, text);
minute = minute + minute10 * 10;
while(1){
if (Button(&PORTB, 0, 100, 0)) i++;
if(i!=1){
minute = ((minute/10) << 4) + (minute % 10);
write_value( 1 , minute);
goto return_;}
if (Button(&PORTB, 1, 100, 0)) minute++;
if (minute > 59) minute = 0;
Lcd_Chr(2, 8, (minute/10) + 48);
Lcd_Chr(2, 9, (minute % 10) + 48);}
}
if(i == 2)
{
Lcd_Cmd(_LCD_CLEAR);
text = "Adjust Hour:";
Lcd_Out(1, 2, text);
hour = hour + hour10 * 10;
while(1){
if (Button(&PORTB, 0, 100, 0)) i++;
if(i!=2){
hour = ((hour/10) << 4) + (hour % 10);
write_value( 2 , hour);
goto return_;}
if (Button(&PORTB, 1, 100, 0)) hour++;
if (hour > 23) hour = 0;
Lcd_Chr(2, 8, (hour/10) + 48);
Lcd_Chr(2, 9, (hour % 10) + 48);}
}
if(i == 3)
{
Lcd_Cmd(_LCD_CLEAR);
text = "Adjust Date:";
Lcd_Out(1, 2, text);
date = date + date10 * 10;
while(1){
if (Button(&PORTB, 0, 100, 0)) i++;
if(i!=3){
date = ((date/10) << 4) + (date % 10);
write_value( 4 , date);
goto return_;}
if (Button(&PORTB, 1, 100, 0)) date++;
if (date > 31) date = 1;
Lcd_Chr(2, 8, (date/10) + 48);
Lcd_Chr(2, 9, (date % 10) + 48);}
}
if(i == 4)
{
Lcd_Cmd(_LCD_CLEAR);
text = "Adjust Month:";
Lcd_Out(1, 2, text);
month = month + month10 * 10;
while(1){
if (Button(&PORTB, 0, 100, 0)) i++;
if(i!=4){
month = ((month/10) << 4) + (month % 10);
write_value( 5 , month);
goto return_;}
if (Button(&PORTB, 1, 100, 0)) month++;
if (month > 12) month = 1;
Lcd_Chr(2, 8, (month/10) + 48);
Lcd_Chr(2, 9, (month % 10) + 48);}
}
if(i == 5)
{
Lcd_Cmd(_LCD_CLEAR);
text = "Adjust Year:";
Lcd_Out(1, 2, text);
year = year + year10 * 10;
while(1){
if (Button(&PORTB, 0, 100, 0)) {i++;
if (i > 5) i = 0;}
if(i!=5){
year = ((year/10) << 4) + (year % 10);
write_value( 6 , year);
goto return_;}
if (Button(&PORTB, 1, 100, 0))
year++;
if (year > 99) year = 0;
Lcd_Chr(2, 7, 2 + 48);
Lcd_Chr(2, 8, 0 + 48);
Lcd_Chr(2, 9, (year/10) + 48);
Lcd_Chr(2, 10, (year % 10) + 48);}
}
if (Button(&PORTB, 0, 100, 0)) i++;
display();
}
}
Schematic
Video
Tuesday, August 7, 2018
Pulse Width Modulation Based on Analog Input using PIC18F2550
What is PWM
CODE
float valADC;
float valADC1;
float valADC2;
char x[4];
void main()
{
// Set PORTA as Input
TRISA = 0b11111111;
PORTA = 0;
// Set PORTC as Output
TRISC = 0b00000000;
PORTC = 0;
// Initializing UART
UART1_Init(9600);
// Initializing ADC
ADC_Init();
// Initializing PWM
PWM1_Init(5000);
// Starting PWM
PWM1_Start();
while(1)
{
valADC = ADC_read(0);
valADC1 = valADC/1023;
valADC2 = valADC1*255;
PWM1_Set_Duty(valADC2);
IntToStr(ValADC2,x);
UART1_Write_Text("Analog Input_1 is: ");
UART1_Write_Text(x);
strcpy(x,"");
UART1_Write(13);
delay_ms(1000);
}
}
Schematic
Sunday, July 8, 2018
40V DC Voltmeter using PIC16F877a
7. Soil Moisture Sensor
CODE
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
unsigned int k,j,i;
char *l,*m,n[7],o[7];
void main()
{
int t;
ADCON1=0x04;
PORTA = 0;
TRISA = 0X01;
PORTB = 0x00;
TRISB = 0x00;
LCD_Init();
ADC_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1, " ABDUR ROUF ");
LCD_Out(2,1, " VOLTMETER ");
delay_ms(2000);
LCD_Cmd(_LCD_CLEAR);
while (1)
{
t=ADC_Read(0);
k = t;
k =k*0.458; //k*0.458;
j = k/10;
i =k%10;
inttostr(j,o);
inttostr(i,n);
l =ltrim(o);
m =ltrim(n);
if(j<=9)
{
lcd_out(1,1,"***Voltmeter***");
lcd_out(2,1,"Volt:");
lcd_out(2,8,l);
lcd_out(2,9,".");
lcd_out(2,10,m);
lcd_out(2,12,"V");
}
else
{
lcd_out(1,1,"***Voltmeter***");
lcd_out(2,1,"Volt:");
lcd_out(2,7,l);
lcd_out(2,9,".");
lcd_out(2,10,m);
lcd_out(2,12,"V");
}
}
}
Schematic
Saturday, July 7, 2018
Automatic Irrigation System Using Soil Moisture Sensor and PIC16F887
7. Soil Moisture Sensor
12. Header for connect LCD
13. 10K potentiometer
CODE
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD module connections
double source=0;
double temp=0;
int view=0;
char txt[6];
void main()
{
TRISC = 0x00;
PORTC = 0x00;
ADC_Init(); // Initialize ADC
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
// clear LCD
Lcd_Out(1, 1, " EEE 332 ");
Lcd_Out(2, 1, " ABDUR ROUF ");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, " SOIL MOISTURE ");
Lcd_Out(2, 1, " MICROCONTROLLER");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
// char code for degree
// Display "C" for Celsius
while(1)
{
source=Adc_Read(1);
if(source>600)
{
PORTC = 0b11111101; //motor on
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,5, "Dry Soil");
Lcd_Out(2,5, "Motor On");
}
if(source<=600)
{
PORTC = 0b00000000;
delay_ms(500); //motor on
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,5, "Humid Soil");
Lcd_Out(2,5, "Motor OFF");
}
}
}
Schematic
Gas Leakage Detection System Using PIC18F452
7. MQ2 Gas Sensor
12. Header for connect LCD
13. 10K potentiometer
Schematic 1 |
Line Follower Robot using Arduino
This project was a part of Line Follower Robot Competition
-
In this project we will interface soil moisture sensor with PIC16F887. The micro controller PIC16F887 is a very popular micro contr...
-
Today I will interface LM35 Temperature sensor with PIC16F887. It is a very basic and simple project. In this tutorial we will use the fo...
-
As we all are playing with electronics and micro controller, we all know what is voltmeter. It is a meter which is used to measure volt. T...