1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| // Software I2C connections
sbit Soft_I2C_Scl_Output at PORTC5_bit;
sbit Soft_I2C_Sda_Output at PORTC4_bit;
sbit Soft_I2C_Scl_Input at PINC5_bit;
sbit Soft_I2C_Sda_Input at PINC4_bit;
sbit Soft_I2C_Scl_Direction at DDC5_bit;
sbit Soft_I2C_Sda_Direction at DDC4_bit;
// End Software I2C connections
// LCD module connections
sbit LCD_RS at PORTD4_bit;
sbit LCD_EN at PORTD3_bit;
sbit LCD_D4 at PORTD5_bit;
sbit LCD_D5 at PORTD6_bit;
sbit LCD_D6 at PORTD7_bit;
sbit LCD_D7 at PORTB0_bit;
sbit LCD_RS_Direction at DDD4_bit;
sbit LCD_EN_Direction at DDD3_bit;
sbit LCD_D4_Direction at DDD5_bit;
sbit LCD_D5_Direction at DDD6_bit;
sbit LCD_D6_Direction at DDD7_bit;
sbit LCD_D7_Direction at DDB0_bit;
// End LCD module connections
int seconds=00,minutes=19,hours=12,day=04,date=18,month=07,year=9;
unsigned char x1,y1;
char welcome=1,time=1;
void welcome_msg(){
/*Lcd_Out(1,1, "Welcome");
Delay_ms(100);
Lcd_Out(1,9, "To");
Delay_ms(100);
Lcd_Out(1,12, "SMART");
Delay_ms(100);
Lcd_Out(2,1, "Home");
Delay_ms(100);
Lcd_Out(2,6, "Irrigation");
Delay_ms(2000);*/
Lcd_Cmd(_LCD_CLEAR);
LCD_Out(1,1,"Date: : :"); //' Prepare and output static text on LCD
Delay_ms(10);
LCD_Out(2,1,"Time: : :");
Delay_ms(10);
LCD_Out(1,12,"201");
//Lcd_Cmd(_LCD_CLEAR);
}
void RTC_Write()
{ seconds = Dec2Bcd (seconds);
hours = Dec2Bcd (hours);
minutes = Dec2Bcd (minutes);
day = Dec2Bcd (day);
date = Dec2Bcd (date);
month = Dec2Bcd (month);
year = Dec2Bcd (year);
Soft_I2C_Start();
Soft_I2C_Write(0xD1);
Soft_I2C_Write(0x00);
Soft_I2C_Stop();
Soft_I2C_Start();
Soft_I2C_Write(0xD0);
Soft_I2C_Write(0x00);
Soft_I2C_Write(0x00); // Sec
Soft_I2C_Write(seconds); // Sec
Soft_I2C_Write(minutes); // min
Soft_I2C_Write(hours); //Hour
Soft_I2C_Write(0x01); //week
//Soft_I2C_Write(0x03); //week
Soft_I2C_Write(day); //day
//Soft_I2C_Write(date); //date
Soft_I2C_Write(Month); //month
Soft_I2C_Write(Year); //year
Soft_I2C_Write(0x90);
Soft_I2C_Stop();
Delay_ms(5);
}
void RTC_Read(){
Soft_I2C_Start();
Soft_I2C_Write(0xD0);
Soft_I2C_Write(0);
Soft_I2C_Start();
Soft_I2C_Write(0xD1);
seconds=Soft_I2C_Read(1);
seconds = Bcd2Dec(seconds);
minutes=Soft_I2C_Read(1);
minutes = Bcd2Dec(minutes);
hours=Soft_I2C_Read(1);
hours = Bcd2Dec(hours);
day=Soft_I2C_Read(1);
day = Bcd2Dec(day);
date=Soft_I2C_Read(1);
date = Bcd2Dec(date);
month=Soft_I2C_Read(1);
month = Bcd2Dec(month);
year=Soft_I2C_Read(1);
year = Bcd2Dec(year);
Soft_I2C_Read(0);
Soft_I2C_Stop(); //' Issue stop signal}
Delay_ms(20);
}
void Display_Time(){
Lcd_Chr(1, 6, (day / 10) + 48); //' Print tens digit of day variable
Lcd_Chr(1, 7, (day % 10) + 48); //' Print oness digit of day variable
Lcd_Chr(1, 9, (month / 10) + 48);
Lcd_Chr(1,10, (month % 10) + 48);
Lcd_Chr(1,15, year + 48); //'56 Print year vaiable + 8 (start from year 2008)*/
Lcd_Chr(2, 6, (hours / 10) + 48);
Lcd_Chr(2, 7, (hours % 10) + 48);
Lcd_Chr(2, 9, (minutes / 10) + 48);
Lcd_Chr(2,10, (minutes % 10) + 48);
Lcd_Chr(2,12, (seconds / 10) + 48);
Lcd_Chr(2,13, (seconds % 10) + 48);
}
void main() {
//RTC_Init();
Soft_I2C_Init();
Delay_ms(5);
Lcd_Init();
Delay_ms(10);
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(10);
while(1){
if(welcome==1){
welcome_msg();
RTC_Write();
welcome=0;
}
RTC_Read();
//Transform_Time(); //' Format date and time
Display_Time(); //' Prepare and display on LCD
}
} |