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.

PIC18F452 Working Problem

Status
Not open for further replies.
See the original mikroBasic code and check if month_, day, year holds raw BCD data from RTC or transformed data. I will also check it.

day and month data from RTC are converted to decimal and sent to the function. Also y always will be 2010. Is it correct or do you want to send year data from RTC ?

I need the information to be sent from RTC even the year to get calculations right.
 

Try this code.


Code - [expand]
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
program prayer_time
 
 
' Lcd module connections
dim LCD_RS as sbit at LATD0_bit
    LCD_EN as sbit at LATD1_bit
    LCD_D4 as sbit at LATD4_bit
    LCD_D5 as sbit at LATD5_bit
    LCD_D6 as sbit at LATD6_bit
    LCD_D7 as sbit at LATD7_bit
 
    LCD_RS_Direction as sbit at TRISD0_bit
    LCD_EN_Direction as sbit at TRISD1_bit
    LCD_D4_Direction as sbit at TRISD4_bit
    LCD_D5_Direction as sbit at TRISD5_bit
    LCD_D6_Direction as sbit at TRISD6_bit
    LCD_D7_Direction as sbit at TRISD7_bit
' End Lcd module connections
 
 
'////////////////////////////////////////////////////////////////////////////////////////
' RTC Definitions
    hours, minutes, seconds, day, week, month, year as byte    ' Global date/time variables
    oldstate as byte
' RTC Definitions
const RTC_ADDR = 0xD0
 
  ' Configure user buttons
  'TRISA0_bit = 1                    ' Set RA0 pin as input.
'{**************************************************************************************************
'* DS1307 Functions
'**************************************************************************************************}
 
'{**************************************************************************************************
'* Read data from RTC DS1307
'* input : addres of RTC register
'* output: value of of RTC register
'**************************************************************************************************}
sub function RTC_Read(dim addr as byte) as byte
dim value as byte
 
  I2C1_Start()                   ' Issue start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(addr)                  ' Start from address 2
  I2C1_Start()                   ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307 for reading R/W=1
 
  value = I2C1_Rd(0)             ' Read seconds byte
  I2C1_Stop()                    ' Issue stop signal
 
  result = value
end sub
 
'{**************************************************************************************************
'* Write data from DS1307
'* input : addres of RTC register, value of of RTC register
'**************************************************************************************************}
sub procedure RTC_Write(dim addr as byte, dim value as byte)
 
  I2C1_Start()         ' Issue start signal
  I2C1_Wr(RTC_ADDR)    ' Address DS1307
  I2C1_Wr(addr)        ' Start from address
  I2C1_Wr(value)       ' Write value to RTC register
  I2C1_Stop()          ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Read time from RTC DS1307
'* input : pointer to variables where RTC data will be stored
'* output: variables with RTC data
'**************************************************************************************************}
sub procedure Read_Time(dim p_hours as ^byte, dim p_minutes as ^byte, dim p_seconds as ^byte,
              dim p_day as ^byte, dim p_week as ^byte, dim p_month as ^byte, dim p_year as ^byte)
 
  I2C1_Start()                ' Issue start signal
  I2C1_Wr(RTC_ADDR)           ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(0)                  ' Start from address 0
  I2C1_Repeated_Start()       ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR + 1)       ' Address DS1307 for reading R/W=1
 
  p_seconds^ = I2C1_Rd(1)     ' Read seconds byte
  p_minutes^ = I2C1_Rd(1)     ' Read minutes byte
  p_hours^ = I2C1_Rd(1)       ' Read hours byte
  p_week^ = I2C1_Rd(1)
  p_day^ = I2C1_Rd(1)
  p_month^ = I2C1_Rd(1)
  p_year^ = I2C1_Rd(0)
 
  I2C1_Stop()                 ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Write time to RTC DS1307
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Write_Time(dim c_hours as byte, dim c_minutes as byte, dim c_seconds as byte,
               dim c_day as byte, dim c_week as byte, dim c_month as byte, dim c_year as byte)
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address (REG0)
   I2C1_Wr(0x80)                    ' write $80 to REG0. (pause counter + 0 sec)
 
   I2C1_Wr(c_minutes)               ' write 0 to minutes word to (REG1)
   I2C1_Wr(c_hours)                 ' write 17 to hours word (24-hours mode)(REG2)
   I2C1_Wr(c_week)                  ' write 2 - Monday (REG3)
   I2C1_Wr(c_day)                   ' write 4 to date word (REG4)
   I2C1_Wr(c_month)                 ' write 5 (May) to month word (REG5)
   I2C1_Wr(c_year)                  ' write 01 to year word (REG6)
   I2C1_Stop()                      ' issue stop signal
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address 0
   I2C1_Wr(0 or c_seconds)          ' write 0 to REG0 (enable counting + 0 sec)
   I2C1_Stop()                      ' issue stop signal
end sub
 
'{**************************************************************************************************
'* Show on the LCD display
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Show_Time()
dim txt as string[4]
 
  seconds  =  ((seconds and 0x70) >> 4)*10 + (seconds and 0x0F)
  minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
  hours    =  ((hours and 0x30) >> 4)*10 + (hours and 0x0F)
  week     =  (week and 0x07)
  day      =  ((day and 0xF0) >> 4)*10 + (day and 0x0F)
  month    =  ((month and 0x10) >> 4)*10 + (month and 0x0F)
  year     =  ((year and 0xF0) >> 4)*10+(year and 0x0F)
 
  select case week
     case 1
      txt = "Sun"
     case 2
      txt = "Mon"
     case 3
      txt = "Tue"
     case 4
      txt = "Wed"
     case 5
      txt = "Thu"
     case 6
      txt = "Fri"
     case 7
      txt = "Sat"
  end select
 
  LCD_Out(1,1, txt)
  Lcd_Chr(1, 6, (day div 10)   + 48)    ' Print tens digit of day variable
  Lcd_Chr(1, 7, (day mod 10)   + 48)    ' Print oness digit of day variable
  Lcd_Chr(1, 9, (month div 10) + 48)
  Lcd_Chr(1,10, (month mod 10) + 48)
  Lcd_Chr(1,14, (year div 10)  + 48)
  Lcd_Chr(1,15, (year mod 10)  + 48)
 
  Lcd_Chr(2, 6, (hours div 10)   + 48)
  Lcd_Chr(2, 7, (hours mod 10)   + 48)
  Lcd_Chr(2, 9, (minutes div 10) + 48)
  Lcd_Chr(2,10, (minutes mod 10) + 48)
  Lcd_Chr(2,12, (seconds div 10) + 48)
  Lcd_Chr(2,13, (seconds mod 10) + 48)
end sub
 
 
  
'/////////////////////////////////////////////////////////////////////
 
 
Dim y, L1 as longint
Dim D_, L, ty, Lambda, Obliquity, Alpha, ST, Dec1, noon, utnoon, dhrtime, asrtime, asralt, durinalarc, marbtime, EshaArc, M, eshatime, fajrtime, shroq, ard, tol as float
    i, farq as byte
    day_, month_, dhr, dhr1, asr, asr1, fjr, fjr1, marb, marb1, esha, esha1 as byte
Dim x, x1 as byte[48]
Dim sec, minutes_, hr, week_day, dday, mn, year_ as short    'edited
Dim str,str1,strzoherh,strzoherm,strasrh,strasrm,strmagrebh,strmagrebm,strfajrh,strfajrm as String[20]
Dim ssec, sminutes, shr, sweek_day, sdday, smn, syear as String[20]
 
 
sub procedure awqat()
    ard = 34.54
    tol = 31.522
    farq = 2
    D_ = ((367 * y) - (floor((1.75) * (y + floor((month_ + 9) / 12)))) + floor(275 * (month_ / 9)) + day - 730531.5)
    L = 280.461+0.9856474 * D_
    L1 = L
    L = L - L1
    L1 = L1 mod 360
    L = L1 + L
    M = 357.528 + 0.9856003 * D_
    L1 = M
    M = M - L1
    L1 = L1 mod 360
    M = L1 + M
    Obliquity = 23.439 - 0.0000004 * D_
    Lambda = L + 1.915 * sin(M * PI / 180) + 0.02 * sin(2 * M * PI / 180)
    L1 = Lambda
    Lambda = Lambda - L1
    L1 = L1 mod 360
    Lambda = L1 + Lambda
    Alpha = atan(cos(Obliquity * PI / 180) * tan(Lambda * PI / 180)) * 180/PI
    Alpha = Alpha - (360 * floor(Alpha / 360))
    Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90))
    ST = 100.46 + 0.985647352 * D_
    L1 = ST
    ST = ST - L1
    L1 = L1 mod 360
    ST = L1 + ST
    Dec1 = asin(sin(Obliquity * PI / 180) * sin(Lambda * PI / 180)) * 180 / PI
    noon = Alpha - ST
    
    if noon >= 0 then
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
    else
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
        noon = 360 - noon
    end if
    
    utnoon = noon - tol
    dhrtime = (utnoon/15)+farq
    dhr1 = dhrtime
    dhrtime = dhrtime - dhr1
    dhr = floor(dhrtime * 60)
    dhrtime = (utnoon / 15) + 3
    asralt = atan(1 + tan((ard - Dec1) * PI / 180)) * 180 / PI
    asrtime = acos((sin((90 - asralt) * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * COS(ard * PI / 180))) * 180 / PI
    asrtime = (asrtime / 15) + dhrtime
    asr1 = asrtime
    asrtime = asrtime - asr1
    asr=floor(asrtime * 60)
    durinalarc = acos((sin( - 0.8333 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    shroq = dhrtime - durinalarc / 15
 
    marbtime = dhrtime + durinalarc / 15
    marb1 = marbtime
    marbtime = marbtime - marb1
    marb = floor(marbtime * 60)
    EshaArc = acos((sin(-18 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    eshatime = dhrtime + EshaArc / 15
    esha1 = eshatime
    eshatime = eshatime - esha1
    esha = floor(eshatime * 60)
    fajrtime = dhrtime - EshaArc / 15
    fjr1 = fajrtime
    fajrtime = fajrtime - fjr1
    fjr = floor(fajrtime * 60)
    'dhr = Dec2Bcd(dhr)
    'dhr1 = Dec2Bcd(dhr1)
    'fjr = Dec2Bcd(fjr)
    'fjr1 = Dec2Bcd(fjr1)
    
    if asr1 > 12 then
        asr1 = asr1 - 12
    end if
    
    if marb1 > 12 then
        marb1 = marb1 - 12
    end if
    
    if esha1 > 12 then
        esha1 = esha1 - 12
    end if 
                 '
    'asr = Dec2Bcd(asr)
    'asr1 = Dec2Bcd(asr1)
    'marb = Dec2Bcd(marb)
    'marb1= Dec2Bcd(marb1)
    'esha = Dec2Bcd(esha)
    'esha1 = Dec2Bcd(esha1)
end sub
 
 
sub procedure Read_Time_(Dim byref sec, minutes, hr, week_day, dday, mn, year as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(0)
    I2C1_Repeated_Start()
    I2C1_Wr(0xD1)
    sec = I2C1_Rd(1)
    minutes = I2C1_Rd(1)
    hr = I2C1_Rd(1)
    week_day = I2C1_Rd(1)
    dday = I2C1_Rd(1)
    mn = I2C1_Rd(1)
    year = I2C1_Rd(0)
    I2C1_Stop()
end sub
 
 
sub procedure Write_Time_(Dim address as short, Dim data_wr as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(address)
    I2C1_Wr(data_wr)
    I2C1_Stop()
end sub
 
 
sub procedure showpray()
        LCD_Out(1,1,"F")
        LCD_Out_cp(strfajrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strfajrm)
 
        LCD_Out_cp(" Z")
        LCD_Out_cp(strzoherh)
        LCD_Out_cp(":")
        LCD_Out_cp(strzoherm)
 
        LCD_Out_cp(" A")
        LCD_Out_cp(strasrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strasrm)
 
        LCD_Out(2,1," M ")
        LCD_Out_cp(strmagrebh)
        LCD_Out_cp(":")
        LCD_Out_cp(strmagrebm)
 
        LCD_Out_cp(" E ")
        LCD_Out_cp(str1)
        LCD_Out_cp(":")
        LCD_Out_cp(str)
 
end sub
 
main:
 
    TRISB = 0
    PORTB = 0
    TRISC.0 = 0
    TRISC.1 = 0
    TRISC.2 = 0
    TRISA.0 = 0
    TRISC.3 = 1
    TRISC.4 = 1
    TRISD = 0
 
    PORTA = 0x00
    PORTB = 0x00
    PORTC = 0x00
    PORTD = 0x00
    PORTE = 0x00
 
    LATA = 0x00
    LATB = 0x00
    LATC = 0x00
    LATD = 0x00
    LATE = 0x00
  
    LCD_Init()
    LCD_Cmd(_LCD_CURSOR_OFF)
    LCD_Cmd(_LCD_CLEAR)
    LCD_Out(1,1,"Prayer Time")
    Delay_ms(2000)
    LCD_Cmd(_LCD_CLEAR)
    
    I2C1_Init(100000)
  
    while true
    
        Read_Time(hr,minutes,sec,dday, week_day, mn, year)
        
        'day = Bcd2Dec(dday)
        'month_= Bcd2Dec(mn)
        'y = 2014
        
        sec  =  ((sec and 0x70) >> 4)*10 + (sec and 0x0F)
        minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
        hr    =  ((hr and 0x30) >> 4)*10 + (hr and 0x0F)
        week_day     =  (week_day and 0x07)
        day      =  ((dday and 0xF0) >> 4)*10 + (dday and 0x0F)
        mn    =  ((mn and 0x10) >> 4)*10 + (mn and 0x0F)
        year     =  ((year and 0xF0) >> 4)*10+(year and 0x0F)
        
        
 
        month_ = mn
        y = 2000+ year
        
        
        awqat()
 
        for i = 0 to 47
            x[i] = 0
            x1[i] = 0
        next i
        
        memset(@x, 0, sizeof(x))
        memset(@x1, 0, sizeof(x1))
        
        for i = 0 to 7
            x[i] = dhr.i
            x1[i] = esha.i
        next i
        
        for i = 0 to 7
            x[i+8] = dhr1.i
            x1[i+8] = esha1.i
        next i
        
        for i = 0 to 7
            x[i+16] = fjr.i
            x1[i+16] = marb.i
        next i
        
        for i = 0 to 7
            x[i+24] = fjr1.i
            x1[i+24] = marb1.i
        next i
        
        for i = 0 to 7
            x[i+32] = minutes.i
            x1[i+32] = asr.i
        next i
        
        for i = 0 to 7
            x[i+40] = hr.i
            x1[i+40] = asr1.i
        next i
        
        for i = 0 to  47
            PORTB.0 = x[i]
            PORTC.0 = x1[i]
            PORTB.1 = 0
            PORTC.1 = 0
            Delay_us(20)
            PORTB.1 = 1
            PORTC.1 = 1
        next i
        
        PORTA.0 = 1
        Delay_ms(300)
        PORTB.2 = 0
        PORTC.2 = 0
        Delay_us(20)
        PORTB.2 = 1
        PORTC.2 = 1
        PORTA.0 = 0
        Delay_ms(300)
        
        'LCD_Out(1,1,"Esha")
        IntToStr(esha, str)
        IntToStr(esha1, str1)
        IntToStr(dhr1, strzoherh)
        IntToStr(dhrtime, strzoherm)
        IntToStr(asr1, strasrh)
        IntToStr(asrtime, strasrm)
        IntToStr(marb1, strmagrebh)
        IntToStr(marb, strmagrebm)
        IntToStr(fjr1, strfajrh)
        IntToStr(fajrtime, strfajrm)
        
        
        Ltrim(str)
        Ltrim(str1)
        Ltrim(strmagrebh)
        Ltrim(strmagrebm)
        Ltrim(strasrh)
        Ltrim(strasrm)
        Ltrim(strzoherh)
        Ltrim(strzoherm)
        Ltrim(strfajrh)
        Ltrim(strfajrm)
 
        '///////////////////////////////////////////////////////////
        
        Lcd_Cmd(_LCD_CLEAR)               ' Prepare and output static text on LCD
  LCD_Chr(1,8,".")
  LCD_Chr(1,11,".")
  LCD_Out(2,1,"Time:")
  LCD_Chr(2,8,":")
  LCD_Chr(2,11,":")
  LCD_Out(1,12,"201")
 
  ' Start the test examples
  while(TRUE)                           ' Endless loop
  '  if (Button(PORTA, 0, 1, 0)) then    ' Detect logical one
  '    oldstate = 1                      ' Update flag
  '  end if
   ' if (oldstate and Button(PORTA, 0, 1, 1)) then    ' Detect one-to-zero transition
 ' Write TIME    11  : 15  : 00  : 24.  tuesday april  2012
      Write_Time(0x11, 0x15, 0x00, 0x24, 0x03,   0x04, 0x12)
      oldstate = 0                      ' Update flag
   ' end if
 
    Read_Time(@hours, @minutes, @seconds, @day, @week, @month, @year)
    Show_Time()
    Delay_mS(1000)
    
    '////////////////////////////////////////////////////////////
     showpray()
 
    Delay_mS(5000)
    wend
    wend
end.

 

Try this code.


Code - [expand]
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
program prayer_time
 
 
' Lcd module connections
dim LCD_RS as sbit at LATD0_bit
    LCD_EN as sbit at LATD1_bit
    LCD_D4 as sbit at LATD4_bit
    LCD_D5 as sbit at LATD5_bit
    LCD_D6 as sbit at LATD6_bit
    LCD_D7 as sbit at LATD7_bit
 
    LCD_RS_Direction as sbit at TRISD0_bit
    LCD_EN_Direction as sbit at TRISD1_bit
    LCD_D4_Direction as sbit at TRISD4_bit
    LCD_D5_Direction as sbit at TRISD5_bit
    LCD_D6_Direction as sbit at TRISD6_bit
    LCD_D7_Direction as sbit at TRISD7_bit
' End Lcd module connections
 
 
'////////////////////////////////////////////////////////////////////////////////////////
' RTC Definitions
    hours, minutes, seconds, day, week, month, year as byte    ' Global date/time variables
    oldstate as byte
' RTC Definitions
const RTC_ADDR = 0xD0
 
  ' Configure user buttons
  'TRISA0_bit = 1                    ' Set RA0 pin as input.
'{**************************************************************************************************
'* DS1307 Functions
'**************************************************************************************************}
 
'{**************************************************************************************************
'* Read data from RTC DS1307
'* input : addres of RTC register
'* output: value of of RTC register
'**************************************************************************************************}
sub function RTC_Read(dim addr as byte) as byte
dim value as byte
 
  I2C1_Start()                   ' Issue start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(addr)                  ' Start from address 2
  I2C1_Start()                   ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307 for reading R/W=1
 
  value = I2C1_Rd(0)             ' Read seconds byte
  I2C1_Stop()                    ' Issue stop signal
 
  result = value
end sub
 
'{**************************************************************************************************
'* Write data from DS1307
'* input : addres of RTC register, value of of RTC register
'**************************************************************************************************}
sub procedure RTC_Write(dim addr as byte, dim value as byte)
 
  I2C1_Start()         ' Issue start signal
  I2C1_Wr(RTC_ADDR)    ' Address DS1307
  I2C1_Wr(addr)        ' Start from address
  I2C1_Wr(value)       ' Write value to RTC register
  I2C1_Stop()          ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Read time from RTC DS1307
'* input : pointer to variables where RTC data will be stored
'* output: variables with RTC data
'**************************************************************************************************}
sub procedure Read_Time(dim p_hours as ^byte, dim p_minutes as ^byte, dim p_seconds as ^byte,
              dim p_day as ^byte, dim p_week as ^byte, dim p_month as ^byte, dim p_year as ^byte)
 
  I2C1_Start()                ' Issue start signal
  I2C1_Wr(RTC_ADDR)           ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(0)                  ' Start from address 0
  I2C1_Repeated_Start()       ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR + 1)       ' Address DS1307 for reading R/W=1
 
  p_seconds^ = I2C1_Rd(1)     ' Read seconds byte
  p_minutes^ = I2C1_Rd(1)     ' Read minutes byte
  p_hours^ = I2C1_Rd(1)       ' Read hours byte
  p_week^ = I2C1_Rd(1)
  p_day^ = I2C1_Rd(1)
  p_month^ = I2C1_Rd(1)
  p_year^ = I2C1_Rd(0)
 
  I2C1_Stop()                 ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Write time to RTC DS1307
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Write_Time(dim c_hours as byte, dim c_minutes as byte, dim c_seconds as byte,
               dim c_day as byte, dim c_week as byte, dim c_month as byte, dim c_year as byte)
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address (REG0)
   I2C1_Wr(0x80)                    ' write $80 to REG0. (pause counter + 0 sec)
 
   I2C1_Wr(c_minutes)               ' write 0 to minutes word to (REG1)
   I2C1_Wr(c_hours)                 ' write 17 to hours word (24-hours mode)(REG2)
   I2C1_Wr(c_week)                  ' write 2 - Monday (REG3)
   I2C1_Wr(c_day)                   ' write 4 to date word (REG4)
   I2C1_Wr(c_month)                 ' write 5 (May) to month word (REG5)
   I2C1_Wr(c_year)                  ' write 01 to year word (REG6)
   I2C1_Stop()                      ' issue stop signal
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address 0
   I2C1_Wr(0 or c_seconds)          ' write 0 to REG0 (enable counting + 0 sec)
   I2C1_Stop()                      ' issue stop signal
end sub
 
'{**************************************************************************************************
'* Show on the LCD display
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Show_Time()
dim txt as string[4]
 
  seconds  =  ((seconds and 0x70) >> 4)*10 + (seconds and 0x0F)
  minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
  hours    =  ((hours and 0x30) >> 4)*10 + (hours and 0x0F)
  week     =  (week and 0x07)
  day      =  ((day and 0xF0) >> 4)*10 + (day and 0x0F)
  month    =  ((month and 0x10) >> 4)*10 + (month and 0x0F)
  year     =  ((year and 0xF0) >> 4)*10+(year and 0x0F)
 
  select case week
     case 1
      txt = "Sun"
     case 2
      txt = "Mon"
     case 3
      txt = "Tue"
     case 4
      txt = "Wed"
     case 5
      txt = "Thu"
     case 6
      txt = "Fri"
     case 7
      txt = "Sat"
  end select
 
  LCD_Out(1,1, txt)
  Lcd_Chr(1, 6, (day div 10)   + 48)    ' Print tens digit of day variable
  Lcd_Chr(1, 7, (day mod 10)   + 48)    ' Print oness digit of day variable
  Lcd_Chr(1, 9, (month div 10) + 48)
  Lcd_Chr(1,10, (month mod 10) + 48)
  Lcd_Chr(1,14, (year div 10)  + 48)
  Lcd_Chr(1,15, (year mod 10)  + 48)
 
  Lcd_Chr(2, 6, (hours div 10)   + 48)
  Lcd_Chr(2, 7, (hours mod 10)   + 48)
  Lcd_Chr(2, 9, (minutes div 10) + 48)
  Lcd_Chr(2,10, (minutes mod 10) + 48)
  Lcd_Chr(2,12, (seconds div 10) + 48)
  Lcd_Chr(2,13, (seconds mod 10) + 48)
end sub
 
 
  
'/////////////////////////////////////////////////////////////////////
 
 
Dim y, L1 as longint
Dim D_, L, ty, Lambda, Obliquity, Alpha, ST, Dec1, noon, utnoon, dhrtime, asrtime, asralt, durinalarc, marbtime, EshaArc, M, eshatime, fajrtime, shroq, ard, tol as float
    i, farq as byte
    day_, month_, dhr, dhr1, asr, asr1, fjr, fjr1, marb, marb1, esha, esha1 as byte
Dim x, x1 as byte[48]
Dim sec, minutes_, hr, week_day, dday, mn, year_ as short    'edited
Dim str,str1,strzoherh,strzoherm,strasrh,strasrm,strmagrebh,strmagrebm,strfajrh,strfajrm as String[20]
Dim ssec, sminutes, shr, sweek_day, sdday, smn, syear as String[20]
 
 
sub procedure awqat()
    ard = 34.54
    tol = 31.522
    farq = 2
    D_ = ((367 * y) - (floor((1.75) * (y + floor((month_ + 9) / 12)))) + floor(275 * (month_ / 9)) + day - 730531.5)
    L = 280.461+0.9856474 * D_
    L1 = L
    L = L - L1
    L1 = L1 mod 360
    L = L1 + L
    M = 357.528 + 0.9856003 * D_
    L1 = M
    M = M - L1
    L1 = L1 mod 360
    M = L1 + M
    Obliquity = 23.439 - 0.0000004 * D_
    Lambda = L + 1.915 * sin(M * PI / 180) + 0.02 * sin(2 * M * PI / 180)
    L1 = Lambda
    Lambda = Lambda - L1
    L1 = L1 mod 360
    Lambda = L1 + Lambda
    Alpha = atan(cos(Obliquity * PI / 180) * tan(Lambda * PI / 180)) * 180/PI
    Alpha = Alpha - (360 * floor(Alpha / 360))
    Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90))
    ST = 100.46 + 0.985647352 * D_
    L1 = ST
    ST = ST - L1
    L1 = L1 mod 360
    ST = L1 + ST
    Dec1 = asin(sin(Obliquity * PI / 180) * sin(Lambda * PI / 180)) * 180 / PI
    noon = Alpha - ST
    
    if noon >= 0 then
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
    else
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
        noon = 360 - noon
    end if
    
    utnoon = noon - tol
    dhrtime = (utnoon/15)+farq
    dhr1 = dhrtime
    dhrtime = dhrtime - dhr1
    dhr = floor(dhrtime * 60)
    dhrtime = (utnoon / 15) + 3
    asralt = atan(1 + tan((ard - Dec1) * PI / 180)) * 180 / PI
    asrtime = acos((sin((90 - asralt) * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * COS(ard * PI / 180))) * 180 / PI
    asrtime = (asrtime / 15) + dhrtime
    asr1 = asrtime
    asrtime = asrtime - asr1
    asr=floor(asrtime * 60)
    durinalarc = acos((sin( - 0.8333 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    shroq = dhrtime - durinalarc / 15
 
    marbtime = dhrtime + durinalarc / 15
    marb1 = marbtime
    marbtime = marbtime - marb1
    marb = floor(marbtime * 60)
    EshaArc = acos((sin(-18 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    eshatime = dhrtime + EshaArc / 15
    esha1 = eshatime
    eshatime = eshatime - esha1
    esha = floor(eshatime * 60)
    fajrtime = dhrtime - EshaArc / 15
    fjr1 = fajrtime
    fajrtime = fajrtime - fjr1
    fjr = floor(fajrtime * 60)
    'dhr = Dec2Bcd(dhr)
    'dhr1 = Dec2Bcd(dhr1)
    'fjr = Dec2Bcd(fjr)
    'fjr1 = Dec2Bcd(fjr1)
    
    if asr1 > 12 then
        asr1 = asr1 - 12
    end if
    
    if marb1 > 12 then
        marb1 = marb1 - 12
    end if
    
    if esha1 > 12 then
        esha1 = esha1 - 12
    end if 
                 '
    'asr = Dec2Bcd(asr)
    'asr1 = Dec2Bcd(asr1)
    'marb = Dec2Bcd(marb)
    'marb1= Dec2Bcd(marb1)
    'esha = Dec2Bcd(esha)
    'esha1 = Dec2Bcd(esha1)
end sub
 
 
sub procedure Read_Time_(Dim byref sec, minutes, hr, week_day, dday, mn, year as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(0)
    I2C1_Repeated_Start()
    I2C1_Wr(0xD1)
    sec = I2C1_Rd(1)
    minutes = I2C1_Rd(1)
    hr = I2C1_Rd(1)
    week_day = I2C1_Rd(1)
    dday = I2C1_Rd(1)
    mn = I2C1_Rd(1)
    year = I2C1_Rd(0)
    I2C1_Stop()
end sub
 
 
sub procedure Write_Time_(Dim address as short, Dim data_wr as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(address)
    I2C1_Wr(data_wr)
    I2C1_Stop()
end sub
 
 
sub procedure showpray()
        LCD_Out(1,1,"F")
        LCD_Out_cp(strfajrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strfajrm)
 
        LCD_Out_cp(" Z")
        LCD_Out_cp(strzoherh)
        LCD_Out_cp(":")
        LCD_Out_cp(strzoherm)
 
        LCD_Out_cp(" A")
        LCD_Out_cp(strasrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strasrm)
 
        LCD_Out(2,1," M ")
        LCD_Out_cp(strmagrebh)
        LCD_Out_cp(":")
        LCD_Out_cp(strmagrebm)
 
        LCD_Out_cp(" E ")
        LCD_Out_cp(str1)
        LCD_Out_cp(":")
        LCD_Out_cp(str)
 
end sub
 
main:
 
    TRISB = 0
    PORTB = 0
    TRISC.0 = 0
    TRISC.1 = 0
    TRISC.2 = 0
    TRISA.0 = 0
    TRISC.3 = 1
    TRISC.4 = 1
    TRISD = 0
 
    PORTA = 0x00
    PORTB = 0x00
    PORTC = 0x00
    PORTD = 0x00
    PORTE = 0x00
 
    LATA = 0x00
    LATB = 0x00
    LATC = 0x00
    LATD = 0x00
    LATE = 0x00
  
    LCD_Init()
    LCD_Cmd(_LCD_CURSOR_OFF)
    LCD_Cmd(_LCD_CLEAR)
    LCD_Out(1,1,"Prayer Time")
    Delay_ms(2000)
    LCD_Cmd(_LCD_CLEAR)
    
    I2C1_Init(100000)
  
    while true
    
        Read_Time(hr,minutes,sec,dday, week_day, mn, year)
        
        'day = Bcd2Dec(dday)
        'month_= Bcd2Dec(mn)
        'y = 2014
        
        sec  =  ((sec and 0x70) >> 4)*10 + (sec and 0x0F)
        minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
        hr    =  ((hr and 0x30) >> 4)*10 + (hr and 0x0F)
        week_day     =  (week_day and 0x07)
        day      =  ((dday and 0xF0) >> 4)*10 + (dday and 0x0F)
        mn    =  ((mn and 0x10) >> 4)*10 + (mn and 0x0F)
        year     =  ((year and 0xF0) >> 4)*10+(year and 0x0F)
        
        
 
        month_ = mn
        y = 2000+ year
        
        
        awqat()
 
        for i = 0 to 47
            x[i] = 0
            x1[i] = 0
        next i
        
        memset(@x, 0, sizeof(x))
        memset(@x1, 0, sizeof(x1))
        
        for i = 0 to 7
            x[i] = dhr.i
            x1[i] = esha.i
        next i
        
        for i = 0 to 7
            x[i+8] = dhr1.i
            x1[i+8] = esha1.i
        next i
        
        for i = 0 to 7
            x[i+16] = fjr.i
            x1[i+16] = marb.i
        next i
        
        for i = 0 to 7
            x[i+24] = fjr1.i
            x1[i+24] = marb1.i
        next i
        
        for i = 0 to 7
            x[i+32] = minutes.i
            x1[i+32] = asr.i
        next i
        
        for i = 0 to 7
            x[i+40] = hr.i
            x1[i+40] = asr1.i
        next i
        
        for i = 0 to  47
            PORTB.0 = x[i]
            PORTC.0 = x1[i]
            PORTB.1 = 0
            PORTC.1 = 0
            Delay_us(20)
            PORTB.1 = 1
            PORTC.1 = 1
        next i
        
        PORTA.0 = 1
        Delay_ms(300)
        PORTB.2 = 0
        PORTC.2 = 0
        Delay_us(20)
        PORTB.2 = 1
        PORTC.2 = 1
        PORTA.0 = 0
        Delay_ms(300)
        
        'LCD_Out(1,1,"Esha")
        IntToStr(esha, str)
        IntToStr(esha1, str1)
        IntToStr(dhr1, strzoherh)
        IntToStr(dhrtime, strzoherm)
        IntToStr(asr1, strasrh)
        IntToStr(asrtime, strasrm)
        IntToStr(marb1, strmagrebh)
        IntToStr(marb, strmagrebm)
        IntToStr(fjr1, strfajrh)
        IntToStr(fajrtime, strfajrm)
        
        
        Ltrim(str)
        Ltrim(str1)
        Ltrim(strmagrebh)
        Ltrim(strmagrebm)
        Ltrim(strasrh)
        Ltrim(strasrm)
        Ltrim(strzoherh)
        Ltrim(strzoherm)
        Ltrim(strfajrh)
        Ltrim(strfajrm)
 
        '///////////////////////////////////////////////////////////
        
        Lcd_Cmd(_LCD_CLEAR)               ' Prepare and output static text on LCD
  LCD_Chr(1,8,".")
  LCD_Chr(1,11,".")
  LCD_Out(2,1,"Time:")
  LCD_Chr(2,8,":")
  LCD_Chr(2,11,":")
  LCD_Out(1,12,"201")
 
  ' Start the test examples
  while(TRUE)                           ' Endless loop
  '  if (Button(PORTA, 0, 1, 0)) then    ' Detect logical one
  '    oldstate = 1                      ' Update flag
  '  end if
   ' if (oldstate and Button(PORTA, 0, 1, 1)) then    ' Detect one-to-zero transition
 ' Write TIME    11  : 15  : 00  : 24.  tuesday april  2012
      Write_Time(0x11, 0x15, 0x00, 0x24, 0x03,   0x04, 0x12)
      oldstate = 0                      ' Update flag
   ' end if
 
    Read_Time(@hours, @minutes, @seconds, @day, @week, @month, @year)
    Show_Time()
    Delay_mS(1000)
    
    '////////////////////////////////////////////////////////////
     showpray()
 
    Delay_mS(5000)
    wend
    wend
end.


It displayed the same values, nothing changed
the values have to be around
F:4.20
Z:12.39
A:4.18
M:7.25
E:8.44
After setting the time, and buttons for setting the time are not working!
 

Try this code.


Code - [expand]
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
program prayer_time
 
 
' Lcd module connections
dim LCD_RS as sbit at LATD0_bit
    LCD_EN as sbit at LATD1_bit
    LCD_D4 as sbit at LATD4_bit
    LCD_D5 as sbit at LATD5_bit
    LCD_D6 as sbit at LATD6_bit
    LCD_D7 as sbit at LATD7_bit
 
    LCD_RS_Direction as sbit at TRISD0_bit
    LCD_EN_Direction as sbit at TRISD1_bit
    LCD_D4_Direction as sbit at TRISD4_bit
    LCD_D5_Direction as sbit at TRISD5_bit
    LCD_D6_Direction as sbit at TRISD6_bit
    LCD_D7_Direction as sbit at TRISD7_bit
' End Lcd module connections
 
 
'////////////////////////////////////////////////////////////////////////////////////////
' RTC Definitions
    hours, minutes, seconds, day, week_day, month, year as byte    ' Global date/time variables
    oldstate as byte
' RTC Definitions
const RTC_ADDR = 0xD0
 
  ' Configure user buttons
  'TRISA0_bit = 1                    ' Set RA0 pin as input.
'{**************************************************************************************************
'* DS1307 Functions
'**************************************************************************************************}
 
'{**************************************************************************************************
'* Read data from RTC DS1307
'* input : addres of RTC register
'* output: value of of RTC register
'**************************************************************************************************}
sub function RTC_Read(dim addr as byte) as byte
dim value as byte
 
  I2C1_Start()                   ' Issue start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(addr)                  ' Start from address 2
  I2C1_Start()                   ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307 for reading R/W=1
 
  value = I2C1_Rd(0)             ' Read seconds byte
  I2C1_Stop()                    ' Issue stop signal
 
  result = value
end sub
 
'{**************************************************************************************************
'* Write data from DS1307
'* input : addres of RTC register, value of of RTC register
'**************************************************************************************************}
sub procedure RTC_Write(dim addr as byte, dim value as byte)
 
  I2C1_Start()         ' Issue start signal
  I2C1_Wr(RTC_ADDR)    ' Address DS1307
  I2C1_Wr(addr)        ' Start from address
  I2C1_Wr(value)       ' Write value to RTC register
  I2C1_Stop()          ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Read time from RTC DS1307
'* input : pointer to variables where RTC data will be stored
'* output: variables with RTC data
'**************************************************************************************************}
sub procedure Read_Time(dim p_hours as ^byte, dim p_minutes as ^byte, dim p_seconds as ^byte,
              dim p_day as ^byte, dim p_week as ^byte, dim p_month as ^byte, dim p_year as ^byte)
 
  I2C1_Start()                ' Issue start signal
  I2C1_Wr(RTC_ADDR)           ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(0)                  ' Start from address 0
  I2C1_Repeated_Start()       ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR + 1)       ' Address DS1307 for reading R/W=1
 
  p_seconds^ = I2C1_Rd(1)     ' Read seconds byte
  p_minutes^ = I2C1_Rd(1)     ' Read minutes byte
  p_hours^ = I2C1_Rd(1)       ' Read hours byte
  p_week^ = I2C1_Rd(1)
  p_day^ = I2C1_Rd(1)
  p_month^ = I2C1_Rd(1)
  p_year^ = I2C1_Rd(0)
 
  I2C1_Stop()                 ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Write time to RTC DS1307
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Write_Time(dim c_hours as byte, dim c_minutes as byte, dim c_seconds as byte,
               dim c_day as byte, dim c_week as byte, dim c_month as byte, dim c_year as byte)
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address (REG0)
   I2C1_Wr(0x80)                    ' write $80 to REG0. (pause counter + 0 sec)
 
   I2C1_Wr(c_minutes)               ' write 0 to minutes word to (REG1)
   I2C1_Wr(c_hours)                 ' write 17 to hours word (24-hours mode)(REG2)
   I2C1_Wr(c_week)                  ' write 2 - Monday (REG3)
   I2C1_Wr(c_day)                   ' write 4 to date word (REG4)
   I2C1_Wr(c_month)                 ' write 5 (May) to month word (REG5)
   I2C1_Wr(c_year)                  ' write 01 to year word (REG6)
   I2C1_Stop()                      ' issue stop signal
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address 0
   I2C1_Wr(0 or c_seconds)          ' write 0 to REG0 (enable counting + 0 sec)
   I2C1_Stop()                      ' issue stop signal
end sub
 
'{**************************************************************************************************
'* Show on the LCD display
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Show_Time()
dim txt as string[4]
 
  select case week_day
     case 1
      txt = "Sun"
     case 2
      txt = "Mon"
     case 3
      txt = "Tue"
     case 4
      txt = "Wed"
     case 5
      txt = "Thu"
     case 6
      txt = "Fri"
     case 7
      txt = "Sat"
  end select
 
  LCD_Out(1,1, txt)
  Lcd_Chr(1, 6, (day div 10)   + 48)    ' Print tens digit of day variable
  Lcd_Chr(1, 7, (day mod 10)   + 48)    ' Print oness digit of day variable
  Lcd_Chr(1, 9, (month div 10) + 48)
  Lcd_Chr(1,10, (month mod 10) + 48)
  Lcd_Chr(1,14, (year div 10)  + 48)
  Lcd_Chr(1,15, (year mod 10)  + 48)
 
  Lcd_Chr(2, 6, (hours div 10)   + 48)
  Lcd_Chr(2, 7, (hours mod 10)   + 48)
  Lcd_Chr(2, 9, (minutes div 10) + 48)
  Lcd_Chr(2,10, (minutes mod 10) + 48)
  Lcd_Chr(2,12, (seconds div 10) + 48)
  Lcd_Chr(2,13, (seconds mod 10) + 48)
end sub
 
 
  
'/////////////////////////////////////////////////////////////////////
 
 
Dim y, L1 as longint
Dim D_, L, ty, Lambda, Obliquity, Alpha, ST, Dec1, noon, utnoon, dhrtime, asrtime, asralt, durinalarc, marbtime, EshaArc, M, eshatime, fajrtime, shroq, ard, tol as float
    i, farq as byte
    day_, month_, dhr, dhr1, asr, asr1, fjr, fjr1, marb, marb1, esha, esha1 as byte
Dim x, x1 as byte[48]
Dim sec, minutes_, hr, dday, mn, year_ as short    'edited
Dim str,str1,strzoherh,strzoherm,strasrh,strasrm,strmagrebh,strmagrebm,strfajrh,strfajrm as String[20]
Dim ssec, sminutes, shr, sweek_day, sdday, smn, syear as String[20]
 
 
sub procedure awqat()
    ard = 34.54
    tol = 31.522
    farq = 2
    D_ = ((367 * y) - (floor((1.75) * (y + floor((month_ + 9) / 12)))) + floor(275 * (month_ / 9)) + day - 730531.5)
    L = 280.461+0.9856474 * D_
    L1 = L
    L = L - L1
    L1 = L1 mod 360
    L = L1 + L
    M = 357.528 + 0.9856003 * D_
    L1 = M
    M = M - L1
    L1 = L1 mod 360
    M = L1 + M
    Obliquity = 23.439 - 0.0000004 * D_
    Lambda = L + 1.915 * sin(M * PI / 180) + 0.02 * sin(2 * M * PI / 180)
    L1 = Lambda
    Lambda = Lambda - L1
    L1 = L1 mod 360
    Lambda = L1 + Lambda
    Alpha = atan(cos(Obliquity * PI / 180) * tan(Lambda * PI / 180)) * 180/PI
    Alpha = Alpha - (360 * floor(Alpha / 360))
    Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90))
    ST = 100.46 + 0.985647352 * D_
    L1 = ST
    ST = ST - L1
    L1 = L1 mod 360
    ST = L1 + ST
    Dec1 = asin(sin(Obliquity * PI / 180) * sin(Lambda * PI / 180)) * 180 / PI
    noon = Alpha - ST
    
    if noon >= 0 then
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
    else
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
        noon = 360 - noon
    end if
    
    utnoon = noon - tol
    dhrtime = (utnoon/15)+farq
    dhr1 = dhrtime
    dhrtime = dhrtime - dhr1
    dhr = floor(dhrtime * 60)
    dhrtime = (utnoon / 15) + 3
    asralt = atan(1 + tan((ard - Dec1) * PI / 180)) * 180 / PI
    asrtime = acos((sin((90 - asralt) * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * COS(ard * PI / 180))) * 180 / PI
    asrtime = (asrtime / 15) + dhrtime
    asr1 = asrtime
    asrtime = asrtime - asr1
    asr=floor(asrtime * 60)
    durinalarc = acos((sin( - 0.8333 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    shroq = dhrtime - durinalarc / 15
 
    marbtime = dhrtime + durinalarc / 15
    marb1 = marbtime
    marbtime = marbtime - marb1
    marb = floor(marbtime * 60)
    EshaArc = acos((sin(-18 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    eshatime = dhrtime + EshaArc / 15
    esha1 = eshatime
    eshatime = eshatime - esha1
    esha = floor(eshatime * 60)
    fajrtime = dhrtime - EshaArc / 15
    fjr1 = fajrtime
    fajrtime = fajrtime - fjr1
    fjr = floor(fajrtime * 60)
    'dhr = Dec2Bcd(dhr)
    'dhr1 = Dec2Bcd(dhr1)
    'fjr = Dec2Bcd(fjr)
    'fjr1 = Dec2Bcd(fjr1)
    
    if asr1 > 12 then
        asr1 = asr1 - 12
    end if
    
    if marb1 > 12 then
        marb1 = marb1 - 12
    end if
    
    if esha1 > 12 then
        esha1 = esha1 - 12
    end if 
                 '
    'asr = Dec2Bcd(asr)
    'asr1 = Dec2Bcd(asr1)
    'marb = Dec2Bcd(marb)
    'marb1= Dec2Bcd(marb1)
    'esha = Dec2Bcd(esha)
    'esha1 = Dec2Bcd(esha1)
end sub
 
 
sub procedure Read_Time_(Dim byref seconds, minutes, hours, week_day, day, month, year as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(0)
    I2C1_Repeated_Start()
    I2C1_Wr(0xD1)
    seconds = I2C1_Rd(1)
    minutes = I2C1_Rd(1)
    hours = I2C1_Rd(1)
    week_day = I2C1_Rd(1)
    day = I2C1_Rd(1)
    month = I2C1_Rd(1)
    year = I2C1_Rd(0)
    I2C1_Stop()
end sub
 
 
sub procedure Write_Time_(Dim address as short, Dim data_wr as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(address)
    I2C1_Wr(data_wr)
    I2C1_Stop()
end sub
 
 
sub procedure showpray()
        LCD_Out(1,1,"F")
        LCD_Out_cp(strfajrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strfajrm)
 
        LCD_Out_cp(" Z")
        LCD_Out_cp(strzoherh)
        LCD_Out_cp(":")
        LCD_Out_cp(strzoherm)
 
        LCD_Out_cp(" A")
        LCD_Out_cp(strasrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strasrm)
 
        LCD_Out(2,1," M ")
        LCD_Out_cp(strmagrebh)
        LCD_Out_cp(":")
        LCD_Out_cp(strmagrebm)
 
        LCD_Out_cp(" E ")
        LCD_Out_cp(str1)
        LCD_Out_cp(":")
        LCD_Out_cp(str)
 
end sub
 
main:
 
    TRISB = 0
    PORTB = 0
    TRISC.0 = 0
    TRISC.1 = 0
    TRISC.2 = 0
    TRISA.0 = 0
    TRISC.3 = 1
    TRISC.4 = 1
    TRISD = 0
 
    PORTA = 0x00
    PORTB = 0x00
    PORTC = 0x00
    PORTD = 0x00
    PORTE = 0x00
 
    LATA = 0x00
    LATB = 0x00
    LATC = 0x00
    LATD = 0x00
    LATE = 0x00
  
    LCD_Init()
    LCD_Cmd(_LCD_CURSOR_OFF)
    LCD_Cmd(_LCD_CLEAR)
    LCD_Out(1,1,"Prayer Time")
    Delay_ms(2000)
    LCD_Cmd(_LCD_CLEAR)
    
    I2C1_Init(100000)
  
    while true
    
        Read_Time(seconds,minutes,hours,week_day,day,month,year)
        
        'day = Bcd2Dec(dday)
        'month_= Bcd2Dec(mn)
        'y = 2014
        
        seconds  =  ((seconds and 0x70) >> 4)*10 + (seconds and 0x0F)
        minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
        hours    =  ((hours and 0x30) >> 4)*10 + (hours and 0x0F)
        week_day =  (week_day and 0x07)
        day      =  ((day and 0xF0) >> 4)*10 + (day and 0x0F)
        month    =  ((month and 0x10) >> 4)*10 + (month and 0x0F)
        year     =  ((year and 0xF0) >> 4)*10+(year and 0x0F)
        
        
 
        month_ = month
        y = 2000 + year
        
        
        awqat()
 
        for i = 0 to 47
            x[i] = 0
            x1[i] = 0
        next i
        
        memset(@x, 0, sizeof(x))
        memset(@x1, 0, sizeof(x1))
        
        for i = 0 to 7
            x[i] = dhr.i
            x1[i] = esha.i
        next i
        
        for i = 0 to 7
            x[i+8] = dhr1.i
            x1[i+8] = esha1.i
        next i
        
        for i = 0 to 7
            x[i+16] = fjr.i
            x1[i+16] = marb.i
        next i
        
        for i = 0 to 7
            x[i+24] = fjr1.i
            x1[i+24] = marb1.i
        next i
        
        for i = 0 to 7
            x[i+32] = minutes.i
            x1[i+32] = asr.i
        next i
        
        for i = 0 to 7
            x[i+40] = hr.i
            x1[i+40] = asr1.i
        next i
        
        for i = 0 to  47
            PORTB.0 = x[i]
            PORTC.0 = x1[i]
            PORTB.1 = 0
            PORTC.1 = 0
            Delay_us(20)
            PORTB.1 = 1
            PORTC.1 = 1
        next i
        
        PORTA.0 = 1
        Delay_ms(300)
        PORTB.2 = 0
        PORTC.2 = 0
        Delay_us(20)
        PORTB.2 = 1
        PORTC.2 = 1
        PORTA.0 = 0
        Delay_ms(300)
        
        'LCD_Out(1,1,"Esha")
        IntToStr(esha, str)
        IntToStr(esha1, str1)
        IntToStr(dhr1, strzoherh)
        IntToStr(dhrtime, strzoherm)
        IntToStr(asr1, strasrh)
        IntToStr(asrtime, strasrm)
        IntToStr(marb1, strmagrebh)
        IntToStr(marb, strmagrebm)
        IntToStr(fjr1, strfajrh)
        IntToStr(fajrtime, strfajrm)
        
        
        Ltrim(str)
        Ltrim(str1)
        Ltrim(strmagrebh)
        Ltrim(strmagrebm)
        Ltrim(strasrh)
        Ltrim(strasrm)
        Ltrim(strzoherh)
        Ltrim(strzoherm)
        Ltrim(strfajrh)
        Ltrim(strfajrm)
 
        '///////////////////////////////////////////////////////////
        
        Lcd_Cmd(_LCD_CLEAR)               ' Prepare and output static text on LCD
  LCD_Chr(1,8,".")
  LCD_Chr(1,11,".")
  LCD_Out(2,1,"Time:")
  LCD_Chr(2,8,":")
  LCD_Chr(2,11,":")
  LCD_Out(1,12,"201")
 
 
    Show_Time()
    showpray()
 
 
 
    wend
end.

 

Try this code.


Code - [expand]
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
program prayer_time
 
 
' Lcd module connections
dim LCD_RS as sbit at LATD0_bit
    LCD_EN as sbit at LATD1_bit
    LCD_D4 as sbit at LATD4_bit
    LCD_D5 as sbit at LATD5_bit
    LCD_D6 as sbit at LATD6_bit
    LCD_D7 as sbit at LATD7_bit
 
    LCD_RS_Direction as sbit at TRISD0_bit
    LCD_EN_Direction as sbit at TRISD1_bit
    LCD_D4_Direction as sbit at TRISD4_bit
    LCD_D5_Direction as sbit at TRISD5_bit
    LCD_D6_Direction as sbit at TRISD6_bit
    LCD_D7_Direction as sbit at TRISD7_bit
' End Lcd module connections
 
 
'////////////////////////////////////////////////////////////////////////////////////////
' RTC Definitions
    hours, minutes, seconds, day, week_day, month, year as byte    ' Global date/time variables
    oldstate as byte
' RTC Definitions
const RTC_ADDR = 0xD0
 
  ' Configure user buttons
  'TRISA0_bit = 1                    ' Set RA0 pin as input.
'{**************************************************************************************************
'* DS1307 Functions
'**************************************************************************************************}
 
'{**************************************************************************************************
'* Read data from RTC DS1307
'* input : addres of RTC register
'* output: value of of RTC register
'**************************************************************************************************}
sub function RTC_Read(dim addr as byte) as byte
dim value as byte
 
  I2C1_Start()                   ' Issue start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(addr)                  ' Start from address 2
  I2C1_Start()                   ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR)              ' Address DS1307 for reading R/W=1
 
  value = I2C1_Rd(0)             ' Read seconds byte
  I2C1_Stop()                    ' Issue stop signal
 
  result = value
end sub
 
'{**************************************************************************************************
'* Write data from DS1307
'* input : addres of RTC register, value of of RTC register
'**************************************************************************************************}
sub procedure RTC_Write(dim addr as byte, dim value as byte)
 
  I2C1_Start()         ' Issue start signal
  I2C1_Wr(RTC_ADDR)    ' Address DS1307
  I2C1_Wr(addr)        ' Start from address
  I2C1_Wr(value)       ' Write value to RTC register
  I2C1_Stop()          ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Read time from RTC DS1307
'* input : pointer to variables where RTC data will be stored
'* output: variables with RTC data
'**************************************************************************************************}
sub procedure Read_Time(dim p_hours as ^byte, dim p_minutes as ^byte, dim p_seconds as ^byte,
              dim p_day as ^byte, dim p_week as ^byte, dim p_month as ^byte, dim p_year as ^byte)
 
  I2C1_Start()                ' Issue start signal
  I2C1_Wr(RTC_ADDR)           ' Address DS1307, see DS1307 datasheet
  I2C1_Wr(0)                  ' Start from address 0
  I2C1_Repeated_Start()       ' Issue repeated start signal
  I2C1_Wr(RTC_ADDR + 1)       ' Address DS1307 for reading R/W=1
 
  p_seconds^ = I2C1_Rd(1)     ' Read seconds byte
  p_minutes^ = I2C1_Rd(1)     ' Read minutes byte
  p_hours^ = I2C1_Rd(1)       ' Read hours byte
  p_week^ = I2C1_Rd(1)
  p_day^ = I2C1_Rd(1)
  p_month^ = I2C1_Rd(1)
  p_year^ = I2C1_Rd(0)
 
  I2C1_Stop()                 ' Issue stop signal
end sub
 
'{**************************************************************************************************
'* Write time to RTC DS1307
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Write_Time(dim c_hours as byte, dim c_minutes as byte, dim c_seconds as byte,
               dim c_day as byte, dim c_week as byte, dim c_month as byte, dim c_year as byte)
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address (REG0)
   I2C1_Wr(0x80)                    ' write $80 to REG0. (pause counter + 0 sec)
 
   I2C1_Wr(c_minutes)               ' write 0 to minutes word to (REG1)
   I2C1_Wr(c_hours)                 ' write 17 to hours word (24-hours mode)(REG2)
   I2C1_Wr(c_week)                  ' write 2 - Monday (REG3)
   I2C1_Wr(c_day)                   ' write 4 to date word (REG4)
   I2C1_Wr(c_month)                 ' write 5 (May) to month word (REG5)
   I2C1_Wr(c_year)                  ' write 01 to year word (REG6)
   I2C1_Stop()                      ' issue stop signal
 
   I2C1_Start()                     ' issue start signal
   I2C1_Wr(RTC_ADDR)                ' address DS1307
   I2C1_Wr(0)                       ' start from word at address 0
   I2C1_Wr(0 or c_seconds)          ' write 0 to REG0 (enable counting + 0 sec)
   I2C1_Stop()                      ' issue stop signal
end sub
 
'{**************************************************************************************************
'* Show on the LCD display
'* input : variables with RTC data
'**************************************************************************************************}
sub procedure Show_Time()
dim txt as string[4]
 
  select case week_day
     case 1
      txt = "Sun"
     case 2
      txt = "Mon"
     case 3
      txt = "Tue"
     case 4
      txt = "Wed"
     case 5
      txt = "Thu"
     case 6
      txt = "Fri"
     case 7
      txt = "Sat"
  end select
 
  LCD_Out(1,1, txt)
  Lcd_Chr(1, 6, (day div 10)   + 48)    ' Print tens digit of day variable
  Lcd_Chr(1, 7, (day mod 10)   + 48)    ' Print oness digit of day variable
  Lcd_Chr(1, 9, (month div 10) + 48)
  Lcd_Chr(1,10, (month mod 10) + 48)
  Lcd_Chr(1,14, (year div 10)  + 48)
  Lcd_Chr(1,15, (year mod 10)  + 48)
 
  Lcd_Chr(2, 6, (hours div 10)   + 48)
  Lcd_Chr(2, 7, (hours mod 10)   + 48)
  Lcd_Chr(2, 9, (minutes div 10) + 48)
  Lcd_Chr(2,10, (minutes mod 10) + 48)
  Lcd_Chr(2,12, (seconds div 10) + 48)
  Lcd_Chr(2,13, (seconds mod 10) + 48)
end sub
 
 
  
'/////////////////////////////////////////////////////////////////////
 
 
Dim y, L1 as longint
Dim D_, L, ty, Lambda, Obliquity, Alpha, ST, Dec1, noon, utnoon, dhrtime, asrtime, asralt, durinalarc, marbtime, EshaArc, M, eshatime, fajrtime, shroq, ard, tol as float
    i, farq as byte
    day_, month_, dhr, dhr1, asr, asr1, fjr, fjr1, marb, marb1, esha, esha1 as byte
Dim x, x1 as byte[48]
Dim sec, minutes_, hr, dday, mn, year_ as short    'edited
Dim str,str1,strzoherh,strzoherm,strasrh,strasrm,strmagrebh,strmagrebm,strfajrh,strfajrm as String[20]
Dim ssec, sminutes, shr, sweek_day, sdday, smn, syear as String[20]
 
 
sub procedure awqat()
    ard = 34.54
    tol = 31.522
    farq = 2
    D_ = ((367 * y) - (floor((1.75) * (y + floor((month_ + 9) / 12)))) + floor(275 * (month_ / 9)) + day - 730531.5)
    L = 280.461+0.9856474 * D_
    L1 = L
    L = L - L1
    L1 = L1 mod 360
    L = L1 + L
    M = 357.528 + 0.9856003 * D_
    L1 = M
    M = M - L1
    L1 = L1 mod 360
    M = L1 + M
    Obliquity = 23.439 - 0.0000004 * D_
    Lambda = L + 1.915 * sin(M * PI / 180) + 0.02 * sin(2 * M * PI / 180)
    L1 = Lambda
    Lambda = Lambda - L1
    L1 = L1 mod 360
    Lambda = L1 + Lambda
    Alpha = atan(cos(Obliquity * PI / 180) * tan(Lambda * PI / 180)) * 180/PI
    Alpha = Alpha - (360 * floor(Alpha / 360))
    Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90))
    ST = 100.46 + 0.985647352 * D_
    L1 = ST
    ST = ST - L1
    L1 = L1 mod 360
    ST = L1 + ST
    Dec1 = asin(sin(Obliquity * PI / 180) * sin(Lambda * PI / 180)) * 180 / PI
    noon = Alpha - ST
    
    if noon >= 0 then
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
    else
        noon = fabs(noon)
        L1 = fabs(noon)
        noon = noon - L1
        L1 = L1 mod 360
        noon = noon + L1
        noon = 360 - noon
    end if
    
    utnoon = noon - tol
    dhrtime = (utnoon/15)+farq
    dhr1 = dhrtime
    dhrtime = dhrtime - dhr1
    dhr = floor(dhrtime * 60)
    dhrtime = (utnoon / 15) + 3
    asralt = atan(1 + tan((ard - Dec1) * PI / 180)) * 180 / PI
    asrtime = acos((sin((90 - asralt) * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * COS(ard * PI / 180))) * 180 / PI
    asrtime = (asrtime / 15) + dhrtime
    asr1 = asrtime
    asrtime = asrtime - asr1
    asr=floor(asrtime * 60)
    durinalarc = acos((sin( - 0.8333 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    shroq = dhrtime - durinalarc / 15
 
    marbtime = dhrtime + durinalarc / 15
    marb1 = marbtime
    marbtime = marbtime - marb1
    marb = floor(marbtime * 60)
    EshaArc = acos((sin(-18 * PI / 180) - sin(Dec1 * PI / 180) * sin(ard * PI / 180)) / (cos(Dec1 * PI / 180) * cos(ard * PI / 180))) * 180 / PI
    eshatime = dhrtime + EshaArc / 15
    esha1 = eshatime
    eshatime = eshatime - esha1
    esha = floor(eshatime * 60)
    fajrtime = dhrtime - EshaArc / 15
    fjr1 = fajrtime
    fajrtime = fajrtime - fjr1
    fjr = floor(fajrtime * 60)
    'dhr = Dec2Bcd(dhr)
    'dhr1 = Dec2Bcd(dhr1)
    'fjr = Dec2Bcd(fjr)
    'fjr1 = Dec2Bcd(fjr1)
    
    if asr1 > 12 then
        asr1 = asr1 - 12
    end if
    
    if marb1 > 12 then
        marb1 = marb1 - 12
    end if
    
    if esha1 > 12 then
        esha1 = esha1 - 12
    end if 
                 '
    'asr = Dec2Bcd(asr)
    'asr1 = Dec2Bcd(asr1)
    'marb = Dec2Bcd(marb)
    'marb1= Dec2Bcd(marb1)
    'esha = Dec2Bcd(esha)
    'esha1 = Dec2Bcd(esha1)
end sub
 
 
sub procedure Read_Time_(Dim byref seconds, minutes, hours, week_day, day, month, year as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(0)
    I2C1_Repeated_Start()
    I2C1_Wr(0xD1)
    seconds = I2C1_Rd(1)
    minutes = I2C1_Rd(1)
    hours = I2C1_Rd(1)
    week_day = I2C1_Rd(1)
    day = I2C1_Rd(1)
    month = I2C1_Rd(1)
    year = I2C1_Rd(0)
    I2C1_Stop()
end sub
 
 
sub procedure Write_Time_(Dim address as short, Dim data_wr as short)
    I2C1_Start()
    I2C1_Wr(0xD0)
    I2C1_Wr(address)
    I2C1_Wr(data_wr)
    I2C1_Stop()
end sub
 
 
sub procedure showpray()
        LCD_Out(1,1,"F")
        LCD_Out_cp(strfajrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strfajrm)
 
        LCD_Out_cp(" Z")
        LCD_Out_cp(strzoherh)
        LCD_Out_cp(":")
        LCD_Out_cp(strzoherm)
 
        LCD_Out_cp(" A")
        LCD_Out_cp(strasrh)
        LCD_Out_cp(":")
        LCD_Out_cp(strasrm)
 
        LCD_Out(2,1," M ")
        LCD_Out_cp(strmagrebh)
        LCD_Out_cp(":")
        LCD_Out_cp(strmagrebm)
 
        LCD_Out_cp(" E ")
        LCD_Out_cp(str1)
        LCD_Out_cp(":")
        LCD_Out_cp(str)
 
end sub
 
main:
 
    TRISB = 0
    PORTB = 0
    TRISC.0 = 0
    TRISC.1 = 0
    TRISC.2 = 0
    TRISA.0 = 0
    TRISC.3 = 1
    TRISC.4 = 1
    TRISD = 0
 
    PORTA = 0x00
    PORTB = 0x00
    PORTC = 0x00
    PORTD = 0x00
    PORTE = 0x00
 
    LATA = 0x00
    LATB = 0x00
    LATC = 0x00
    LATD = 0x00
    LATE = 0x00
  
    LCD_Init()
    LCD_Cmd(_LCD_CURSOR_OFF)
    LCD_Cmd(_LCD_CLEAR)
    LCD_Out(1,1,"Prayer Time")
    Delay_ms(2000)
    LCD_Cmd(_LCD_CLEAR)
    
    I2C1_Init(100000)
  
    while true
    
        Read_Time(seconds,minutes,hours,week_day,day,month,year)
        
        'day = Bcd2Dec(dday)
        'month_= Bcd2Dec(mn)
        'y = 2014
        
        seconds  =  ((seconds and 0x70) >> 4)*10 + (seconds and 0x0F)
        minutes  =  ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F)
        hours    =  ((hours and 0x30) >> 4)*10 + (hours and 0x0F)
        week_day =  (week_day and 0x07)
        day      =  ((day and 0xF0) >> 4)*10 + (day and 0x0F)
        month    =  ((month and 0x10) >> 4)*10 + (month and 0x0F)
        year     =  ((year and 0xF0) >> 4)*10+(year and 0x0F)
        
        
 
        month_ = month
        y = 2000 + year
        
        
        awqat()
 
        for i = 0 to 47
            x[i] = 0
            x1[i] = 0
        next i
        
        memset(@x, 0, sizeof(x))
        memset(@x1, 0, sizeof(x1))
        
        for i = 0 to 7
            x[i] = dhr.i
            x1[i] = esha.i
        next i
        
        for i = 0 to 7
            x[i+8] = dhr1.i
            x1[i+8] = esha1.i
        next i
        
        for i = 0 to 7
            x[i+16] = fjr.i
            x1[i+16] = marb.i
        next i
        
        for i = 0 to 7
            x[i+24] = fjr1.i
            x1[i+24] = marb1.i
        next i
        
        for i = 0 to 7
            x[i+32] = minutes.i
            x1[i+32] = asr.i
        next i
        
        for i = 0 to 7
            x[i+40] = hr.i
            x1[i+40] = asr1.i
        next i
        
        for i = 0 to  47
            PORTB.0 = x[i]
            PORTC.0 = x1[i]
            PORTB.1 = 0
            PORTC.1 = 0
            Delay_us(20)
            PORTB.1 = 1
            PORTC.1 = 1
        next i
        
        PORTA.0 = 1
        Delay_ms(300)
        PORTB.2 = 0
        PORTC.2 = 0
        Delay_us(20)
        PORTB.2 = 1
        PORTC.2 = 1
        PORTA.0 = 0
        Delay_ms(300)
        
        'LCD_Out(1,1,"Esha")
        IntToStr(esha, str)
        IntToStr(esha1, str1)
        IntToStr(dhr1, strzoherh)
        IntToStr(dhrtime, strzoherm)
        IntToStr(asr1, strasrh)
        IntToStr(asrtime, strasrm)
        IntToStr(marb1, strmagrebh)
        IntToStr(marb, strmagrebm)
        IntToStr(fjr1, strfajrh)
        IntToStr(fajrtime, strfajrm)
        
        
        Ltrim(str)
        Ltrim(str1)
        Ltrim(strmagrebh)
        Ltrim(strmagrebm)
        Ltrim(strasrh)
        Ltrim(strasrm)
        Ltrim(strzoherh)
        Ltrim(strzoherm)
        Ltrim(strfajrh)
        Ltrim(strfajrm)
 
        '///////////////////////////////////////////////////////////
        
        Lcd_Cmd(_LCD_CLEAR)               ' Prepare and output static text on LCD
  LCD_Chr(1,8,".")
  LCD_Chr(1,11,".")
  LCD_Out(2,1,"Time:")
  LCD_Chr(2,8,":")
  LCD_Chr(2,11,":")
  LCD_Out(1,12,"201")
 
 
    Show_Time()
    showpray()
 
 
 
    wend
end.


Time and Date aren't displaying at all, showing wrong reading in proteus interface

side question
how can I declare a 2d array in mikrobasic


'Dim May as short[32][6]={{4,5,12,4,7,8},{20,57,39,18,25,48},{19,56,39,18,26,49},{18,55,39,18,26,50},{17,55,39,18,27,51},{15,54,39,18,28,52},{14,53,39,18,28,53},{13,52,39,18,29,54},{12,51,39,18,30,55},{11,51,39,18,30,55},{10,50,39,18,31,56},{9,49,39,18,32,57},{8,48,39,18,32,59},{6,47,39,18,33,8},{4,46,39,18,34,1},{3,45,39,18,35,2},{2,45,39,18,36,3},{1,44,39,18,36,4},{1,44,39,18,37,5},{2,43,39,18,37,6},{59,43,39,18,38,6},{59,42,39,18,39,7},{58,42,39,18,39,8},{57,41,39,18,40,9},{56,41,40,19,41,10},{55,41,40,19,41,11},{55,40,40,19,42,12},{54,40,40,19,43,12},{53,39,40,19,43,13},{53,39,40,19,44,14},{52,38,40,19,44,15}}
 

Attachments

  • lcd122.JPG
    lcd122.JPG
    48.4 KB · Views: 47

Try this method.

Code:
Dim my2DArray as char[32][6]

Edit: Try attached project. It displays some data. Also it displays Date and Time.
 

Attachments

  • Prayer Time partly fixed.rar
    193.3 KB · Views: 48
  • sim ss.png
    sim ss.png
    43.9 KB · Views: 51
Last edited:

Try this method.

Code:
Dim my2DArray as char[32][6]

Edit: Try attached project. It displays some data. Also it displays Date and Time.

What about the buttons for changing time and date since the formulas are used to calculate pray time depending on the time and date and I need to change it to today date and time
 

You have to write code for buttons. 3 buttons are needed to set date and time. One is to enter set mode and another to increment and one more to decrement.

Two buttons can also be used.
 

You have to write code for buttons. 3 buttons are needed to set date and time. One is to enter set mode and another to increment and one more to decrement.

Two buttons can also be used.

This is the piece of code responsible for changing time and date in the last code but I commented it since the code didn't compile.

Code:
  ' Start the test examples
  while(TRUE)                           ' Endless loop
    if (Button(PORTA, 0, 1, 0)) then    ' Detect logical one
      oldstate = 1                      ' Update flag
    end if
    if (oldstate and Button(PORTA, 0, 1, 1)) then    ' Detect one-to-zero transition
 ' Write TIME    11  : 15  : 00  : 24.  tuesday april  2012
      Write_Time(0x11, 0x15, 0x00, 0x24, 0x03,   0x04, 0x12)
      oldstate = 0                      ' Update flag
    end if

    Read_Time(@hours, @minutes, @seconds, @day, @week, @month, @year)
    Show_Time()
    Delay_mS(10)

I searched for a method called Button but couldn't find it
 

You have to select the Buttons library in Library manager.
 

You have to select the Buttons library in Library manager.

I have this code to change date and time, how can I implement it in the mikrobasic code,
It's written in mikroc pro

Code:
   do
   {
     set = 0;
     if(PORTA.F0 == 0)
     {
         Delay_ms(100);
         if(PORTA.F0 == 0)
         {
             set_count++;
             if(set_count >= 7)
             {
                set_count = 0;
             }
         }
     }
     if(set_count)
     {
        if(PORTA.F1 == 0)
        {
          Delay_ms(100);
          if(PORTA.F1 == 0)
              set = 1;
        }
        
        if(PORTA.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,0x00); //Reset second to 0 sec. and start Oscillator
                    break;
            case 4:
                     day = BCD2Binary(day);
                     day = day + set;
                     day = Binary2BCD(day);
                     if(day >= 0x32)
                        day = 1;
                     if(day <= 0)
                        day = 0x31;
                     write_ds1307(4, day); // write date 17
                     break;
            case 5:
                    month = BCD2Binary(month);
                    month = month + set;
                    month = Binary2BCD(month);
                    if(month > 0x12)
                      month = 1;
                    if(month <= 0)
                      month = 0x12;
                    write_ds1307(5,month); // write month 6 June
                    break;
            case 6:
                    year = BCD2Binary(year);
                    year = year + set;
                    year = Binary2BCD(year);
                    if(year <= -1)
                       year = 0x99;
                    if(year >= 0x50)
                       year = 0;
                    write_ds1307(6, year); // write year
                    break;
          }
        }
     }
 

Try like this

Code:
if(PORTA.F0 == 0)
     {

is replaced with

Code:
if(PORTA.0 = 0)
     {

When you are writing time to RTC you will have to convert your decimal value to bcd value and write to RTC. You have to use
Code:
Dec2Bcd()
function.

Don't use BCD2Binary() etc...

Change
Code:
Write_Time()
function with this function and pass decimal values to the function.

Code:
sub procedure Write_Time(dim c_hours as byte, dim c_minutes as byte, dim c_seconds as byte,
               dim c_day as byte, dim c_week as byte, dim c_month as byte, dim c_year as byte)

    I2C1_Start()                     ' issue start signal
    I2C1_Wr(RTC_ADDR)                ' address DS1307
    I2C1_Wr(0)                       ' start from word at address (REG0)
    I2C1_Wr(0x80)                    ' write $80 to REG0. (pause counter + 0 sec)

    I2C1_Wr(Dec2Bcd(c_minutes))               ' write 0 to minutes word to (REG1)
    I2C1_Wr(Dec2Bcd(c_hours))                 ' write 17 to hours word (24-hours mode)(REG2)
    I2C1_Wr(Dec2Bcd(c_week))                  ' write 2 - Monday (REG3)
    I2C1_Wr(Dec2Bcd(c_day))                   ' write 4 to date word (REG4)
    I2C1_Wr(Dec2Bcd(c_month))                 ' write 5 (May) to month word (REG5)
    I2C1_Wr(Dec2Bcd(c_year))                  ' write 01 to year word (REG6)
    I2C1_Stop()                      ' issue stop signal

    I2C1_Start()                     ' issue start signal
    I2C1_Wr(RTC_ADDR)                ' address DS1307
    I2C1_Wr(0)                       ' start from word at address 0
    I2C1_Wr(0 or Dec2Bcd(c_seconds))          ' write 0 to REG0 (enable counting + 0 sec)
    I2C1_Stop()                      ' issue stop signal
end sub

Also use only three buttons to set date and time. Remember clock is running in 24 hour format. Also use six variables like

Code:
Dim sSec, sMin, sHr, sWeek, sDay, sMonth, sYear as byte
for setting time. These variable should increment and decrement in their boundaries when buttons are pressed and when set button is pressed 2nd time then these variables should be passed to Write_Time() function for writing time to RTC.

If set button pressed 1st time system eneters time set mode and pressing again exits set mode and enters run mode. You also have to make changes to Display time during setting.
 
Last edited:

Try like this

Code:
if(PORTA.F0 == 0)
     {

is replaced with

Code:
if(PORTA.0 = 0)
     {

When you are writing time to RTC you will have to convert your decimal value to bcd value and write to RTC. You have to use
Code:
Dec2Bcd()
function.

Don't use BCD2Binary() etc...

Change
Code:
Write_Time()
function with this function and pass decimal values to the function.

Code:
sub procedure Write_Time(dim c_hours as byte, dim c_minutes as byte, dim c_seconds as byte,
               dim c_day as byte, dim c_week as byte, dim c_month as byte, dim c_year as byte)

    I2C1_Start()                     ' issue start signal
    I2C1_Wr(RTC_ADDR)                ' address DS1307
    I2C1_Wr(0)                       ' start from word at address (REG0)
    I2C1_Wr(0x80)                    ' write $80 to REG0. (pause counter + 0 sec)

    I2C1_Wr(Dec2Bcd(c_minutes))               ' write 0 to minutes word to (REG1)
    I2C1_Wr(Dec2Bcd(c_hours))                 ' write 17 to hours word (24-hours mode)(REG2)
    I2C1_Wr(Dec2Bcd(c_week))                  ' write 2 - Monday (REG3)
    I2C1_Wr(Dec2Bcd(c_day))                   ' write 4 to date word (REG4)
    I2C1_Wr(Dec2Bcd(c_month))                 ' write 5 (May) to month word (REG5)
    I2C1_Wr(Dec2Bcd(c_year))                  ' write 01 to year word (REG6)
    I2C1_Stop()                      ' issue stop signal

    I2C1_Start()                     ' issue start signal
    I2C1_Wr(RTC_ADDR)                ' address DS1307
    I2C1_Wr(0)                       ' start from word at address 0
    I2C1_Wr(0 or Dec2Bcd(c_seconds))          ' write 0 to REG0 (enable counting + 0 sec)
    I2C1_Stop()                      ' issue stop signal
end sub

Also use only three buttons to set date and time. Remember clock is running in 24 hour format. Also use six variables like

Code:
Dim sSec, sMin, sHr, sWeek, sDay, sMonth, sYear as byte
for setting time. These variable should increment and decrement in their boundaries when buttons are pressed and when set button is pressed 2nd time then these variables should be passed to Write_Time() function for writing time to RTC.

If set button pressed 1st time system eneters time set mode and pressing again exits set mode and enters run mode. You also have to make changes to Display time during setting.

Now I have a deadline closing in, so I need to do this one way or the other.
Attached a code that display the time and date just fine and has button for correcting the time and date.
the code has an array for Prayers time in May, by value.

I declared a method to grab the time for each pray from the array, the problem is that I couldn't display these values on the LCD, it shows only black spaces, attached the code

this is the method and the array

Code:
void displayMay()
{

date3=read_ds1307(4); // read date
//date2= Bcd2Dec16(date3);
date2=5;

//if (month==5) {

if (date2<21) { fager[2]=4 ;} else  { fager[2]=3; }
fager[1]=((May[date2][0])/10)%10  ;
fager[0]=(May[date2][0])%10  ;

shrouq[2]=5;
shrouq[1]=((May[date2][1])/10)%10  ;
shrouq[0]=(May[date2][1])%10    ;

zoher[3]=1  ;
zoher[2]=2  ;
zoher[1]=((May[date2][2])/10)%10  ;
zoher[0]=(May[date2][2])%10    ;

aser[2]=4;
aser[1]=((May[date2][3])/10)%10  ;
aser[0]=(May[date2][3])%10 ;

maghreb[2]=7;
maghreb[1]=((May[date2][4])/10)%10  ;
maghreb[0]=(May[date2][4])%10 ;

if (date2<14) { isha[2]=8 ;} else  { isha[2]=9; }
isha[1]=((May[date2][5])/10)%10  ;
isha[0]=(May[date2][5])%10 ;
//}

//isha[2]='5';
//char ap1[0]=Dec2Bcd(isha[2]);
//IntToStr()



        //LCD_Out(1,1,"Esha")


        Ltrim(isha);


                LCD_Out(2,1,"F :");
        Lcd_Chr_Cp(isha[0]);
        Lcd_Chr_Cp(isha[1]);
        Lcd_Chr_Cp(isha[2]);
        Lcd_Chr_Cp('4');
        //LCD_Out(2,1,isha);
      //  LCD_Out_cp(":")
       // LCD_Out_cp(strfajrm)
        
//Ltrim(isha[2]);
//Lcd_out(2, 6, isha[2]);
//Lcd_out(2, 9, "jjj");

}


array
Code:
const unsigned  short May [32][6]={{4,5,12,4,7,8},{20,57,39,18,25,48},{19,56,39,18,26,49},{18,55,39,18,26,50},{17,55,39,18,27,51},{15,54,39,18,28,52},{14,53,39,18,28,53},{13,52,39,18,29,54},{12,51,39,18,30,55},{11,51,39,18,30,55},{10,50,39,18,31,56},{9,49,39,18,32,57},{8,48,39,18,32,59},{6,47,39,18,33,8},{4,46,39,18,34,1},{3,45,39,18,35,2},{2,45,39,18,36,3},{1,44,39,18,36,4},{1,44,39,18,37,5},{2,43,39,18,37,6},{59,43,39,18,38,6},{59,42,39,18,39,7},{58,42,39,18,39,8},{57,41,39,18,40,9},{56,41,40,19,41,10},{55,41,40,19,41,11},{55,40,40,19,42,12},{54,40,40,19,43,12},{53,39,40,19,43,13},{53,39,40,19,44,14},{52,38,40,19,44,15}};

I'm trying this for one month only May, since If it worked for it I can make it work for all others.

Please take a look at my code
 

Attachments

  • Digital Clock.rar
    319 KB · Views: 34

The array contains bcd values. It has to be converted to character by adding 48 to each array element and terminating the arry element with '\0' and then sending it to LCD_Out() for printing.
 

The array contains bcd values. It has to be converted to character by adding 48 to each array element and terminating the arry element with '\0' and then sending it to LCD_Out() for printing.

Do you have similar project with such method to do this ?!
 

You have to do like this.

Code:
shrouq[2]=5;
shrouq[1]=((May[date2][1])/10)%10  ;
shrouq[0]=(May[date2][1])%10    ;

shrouq is a 3 element array. Now make it 4 element array

unsigned short shrouq[4];
char ste[17]

Now do like this. (As each element of the array contains only values 0 to 9.

Code:
shrouq[2]=5 + 48;
shrouq[1]=(((May[date2][1])/10)%10) + 48  ;
shrouq[0]=((May[date2][1])%10) + 48   ;
shrouq[3] = '\0';

then

Code:
IntToStr(shrouq, str);
Ltrim(str);
LCD_Out(1,1,str);

This is surely solve your problem but make sure RTC is working properly.

- - - Updated - - -

Edit:

You have to do like this. Also replace RTC code with RTC code from libstock.

Code:
const short Jan[32][6] = {{5,6,11,2,4,6},{7,41,45,31,52,14},{7,41,45,32,53,15},{7,41,46,32,54,15},{7,41,46,33,55,16},{8,41,47,34,55,17},{8,41,47,35,56,17},{8,41,48,35,57,18},{8,41,48,36,58,19},{8,42,49,37,59,19},{8,42,49,38,0,20},{8,42,50,38,1,21},{8,42,50,39,2,21},{8,42,51,40,2,22},{9,42,51,41,3,23},{9,42,52,41,4,23},{9,42,52,42,5,24},{9,42,52,43,6,25},{9,41,52,44,7,26},{8,41,53,44,8,26},{8,40,53,45,9,27},{8,40,53,46,9,28},{7,39,54,47,10,29},{7,39,54,48,11,30},{7,38,54,48,12,30},{7,38,54,49,13,31},{7,38,54,50,14,32},{6,37,55,51,15,33},{6,37,55,52,15,34},{6,36,55,53,16,35},{5,36,56,53,17,35},{5,35,56,54,18,36}};

char dummy[32][6];

unsigned short fager[4];
unsigned short shrouq[4];
unsigned short zoher[5];
unsigned short aser[4];
unsigned short maghreb[4];
unsigned short isha[4];

char ten = 10, fortyEight = 48;

char i = 0, j = 0;

void main() {

	memset(fager, '\0', sizeof(fager));
    	memset(shrouq, '\0', sizeof(shrouq));
   	memset(zoher, '\0', sizeof(zoher));
    	memset(aser, '\0', sizeof(aser));
    	memset(maghreb, '\0', sizeof(maghreb));
    	memset(isha, '\0', sizeof(isha));

	while(1) {

	}
}



if(month == 1) { //Jan
          
		for(i = 0; i < 32; i++) {
			for(j = 0; j < 6; j++) {
				dummy[i][j] = Jan[i][j]
			}
		}

                fager[2] = dummy[0][0] + fortyEight;
                fager[1] = 0 + fortyEight;
                fager[0] = dummy[date][0] + fortyEight;
                               
                shrouq[2] = dummy[0][1] + fortyEight;
                shrouq[1] = ((((dummy[date][1]) / ten) % ten)) + fortyEight;
                shrouq[0] = ((dummy[date][1] % ten)) + fortyEight;
                               
                zoher[3] = 1 + fortyEight;
                zoher[2] = 1 + fortyEight;
                zoher[1] = ((((dummy[date][2]) / ten) % ten)) + fortyEight;
                zoher[0] = (((dummy[date][2]) % ten)) + fortyEight;
                               
                aser[2] = 2 + fortyEight;
                aser[1] = ((((dummy[date][3]) / ten) % ten)) + fortyEight;
                aser[0] = (((dummy[date][3]) % ten)) + fortyEight;
                                
                if (date < ten) { 
                    maghreb[2] = 4 + fortyEight;
                }
                else {
                    maghreb[2] = 5 + fortyEight;
                }
                
                maghreb[1] = ((((dummy[date][4]) / ten) % ten)) + fortyEight;
                maghreb[0] = (((dummy[date][4]) % ten)) + fortyEight;
                                
                isha[2] = 6;
                isha[1] = ((((dummy[date][5]) / ten) % ten)) + fortyEight;
                isha[0] = (((dummy[date][5]) % ten)) + fortyEight;         
          }
 

You have to do like this.

Code:
shrouq[2]=5;
shrouq[1]=((May[date2][1])/10)%10  ;
shrouq[0]=(May[date2][1])%10    ;

shrouq is a 3 element array. Now make it 4 element array

unsigned short shrouq[4];
char ste[17]

Now do like this. (As each element of the array contains only values 0 to 9.

Code:
shrouq[2]=5 + 48;
shrouq[1]=(((May[date2][1])/10)%10) + 48  ;
shrouq[0]=((May[date2][1])%10) + 48   ;
shrouq[3] = '\0';

then

Code:
IntToStr(shrouq, str);
Ltrim(str);
LCD_Out(1,1,str);

This is surely solve your problem but make sure RTC is working properly.

- - - Updated - - -

Edit:

You have to do like this. Also replace RTC code with RTC code from libstock.

Code:
const short Jan[32][6] = {{5,6,11,2,4,6},{7,41,45,31,52,14},{7,41,45,32,53,15},{7,41,46,32,54,15},{7,41,46,33,55,16},{8,41,47,34,55,17},{8,41,47,35,56,17},{8,41,48,35,57,18},{8,41,48,36,58,19},{8,42,49,37,59,19},{8,42,49,38,0,20},{8,42,50,38,1,21},{8,42,50,39,2,21},{8,42,51,40,2,22},{9,42,51,41,3,23},{9,42,52,41,4,23},{9,42,52,42,5,24},{9,42,52,43,6,25},{9,41,52,44,7,26},{8,41,53,44,8,26},{8,40,53,45,9,27},{8,40,53,46,9,28},{7,39,54,47,10,29},{7,39,54,48,11,30},{7,38,54,48,12,30},{7,38,54,49,13,31},{7,38,54,50,14,32},{6,37,55,51,15,33},{6,37,55,52,15,34},{6,36,55,53,16,35},{5,36,56,53,17,35},{5,35,56,54,18,36}};

char dummy[32][6];

unsigned short fager[4];
unsigned short shrouq[4];
unsigned short zoher[5];
unsigned short aser[4];
unsigned short maghreb[4];
unsigned short isha[4];

char ten = 10, fortyEight = 48;

char i = 0, j = 0;

void main() {

	memset(fager, '\0', sizeof(fager));
    	memset(shrouq, '\0', sizeof(shrouq));
   	memset(zoher, '\0', sizeof(zoher));
    	memset(aser, '\0', sizeof(aser));
    	memset(maghreb, '\0', sizeof(maghreb));
    	memset(isha, '\0', sizeof(isha));

	while(1) {

	}
}



if(month == 1) { //Jan
          
		for(i = 0; i < 32; i++) {
			for(j = 0; j < 6; j++) {
				dummy[i][j] = Jan[i][j]
			}
		}

                fager[2] = dummy[0][0] + fortyEight;
                fager[1] = 0 + fortyEight;
                fager[0] = dummy[date][0] + fortyEight;
                               
                shrouq[2] = dummy[0][1] + fortyEight;
                shrouq[1] = ((((dummy[date][1]) / ten) % ten)) + fortyEight;
                shrouq[0] = ((dummy[date][1] % ten)) + fortyEight;
                               
                zoher[3] = 1 + fortyEight;
                zoher[2] = 1 + fortyEight;
                zoher[1] = ((((dummy[date][2]) / ten) % ten)) + fortyEight;
                zoher[0] = (((dummy[date][2]) % ten)) + fortyEight;
                               
                aser[2] = 2 + fortyEight;
                aser[1] = ((((dummy[date][3]) / ten) % ten)) + fortyEight;
                aser[0] = (((dummy[date][3]) % ten)) + fortyEight;
                                
                if (date < ten) { 
                    maghreb[2] = 4 + fortyEight;
                }
                else {
                    maghreb[2] = 5 + fortyEight;
                }
                
                maghreb[1] = ((((dummy[date][4]) / ten) % ten)) + fortyEight;
                maghreb[0] = (((dummy[date][4]) % ten)) + fortyEight;
                                
                isha[2] = 6;
                isha[1] = ((((dummy[date][5]) / ten) % ten)) + fortyEight;
                isha[0] = (((dummy[date][5]) % ten)) + fortyEight;         
          }

you really helped me, thanks a lot man.
One last request, I want to understand advanced PIC topics like serial interrupt and other things and how to implement these in code, can you recommend a good tutorial website or a book, from where I can get a good knowledge regarding these topics.

Can you tell me what's you profession ?! and how you gain that kind of knowledge
 

Two good books for PIC are

Programming and Customizing the PIC Microcontroller 3rd Edition by Myke Predko and

Microprocessors from Assembly Language to C Using the PIC18Fxx2 by Robert B. Reese


And by the way did the RTC work and also did it display the Prayer times ?

I am attaching the file I edited. Make a timer interrupt of 5 seconds and display RTC date and time for 5 seconds and Prayer times for 5 seconds.

- - - Updated - - -

I made a mistake in post #76.

This is wrong. shrouq is a string. No need for conversion.

Code:
IntToStr(shrouq, str);
Ltrim(str);
LCD_Out(1,1,str);

It should be

Code:
LCD_Out(1,1,shrouq);

117296d1431117756-rtc.png


In the code I see that RC3 and RC4 (I2C pins) are used for some other purpose. Please change those code by shifting those to PORTA or PORTB pins.

Embedded Circuit designing and Programming is my profession.

- - - Updated - - -

7 Segment version. Year data written to RTC is not correct. Display still blinks. Test in hardware and reply. Maybe it is a Proteus problem. It displays all datas. Don't know why the last two 7 Segment displays are used.

BCD to Seven Segment decoder needed pullup resistors on output lines as they are open collector outputs.

117304d1431122973-rtc-ssd.png
 

Attachments

  • RTC DS1307 Fixed rev1.rar
    133.4 KB · Views: 56
  • RTC DS1307 Fixed rev5.rar
    193.7 KB · Views: 51
  • rtc.png
    rtc.png
    37 KB · Views: 65
  • RTC DS1307 SSD.rar
    151.3 KB · Views: 46
  • rtc ssd.png
    rtc ssd.png
    32.8 KB · Views: 63
Last edited:

Two good books for PIC are

Programming and Customizing the PIC Microcontroller 3rd Edition by Myke Predko and

Microprocessors from Assembly Language to C Using the PIC18Fxx2 by Robert B. Reese


And by the way did the RTC work and also did it display the Prayer times ?

I am attaching the file I edited. Make a timer interrupt of 5 seconds and display RTC date and time for 5 seconds and Prayer times for 5 seconds.

- - - Updated - - -

I made a mistake in post #76.

This is wrong. shrouq is a string. No need for conversion.

Code:
IntToStr(shrouq, str);
Ltrim(str);
LCD_Out(1,1,str);

It should be

Code:
LCD_Out(1,1,shrouq);

117296d1431117756-rtc.png


In the code I see that RC3 and RC4 (I2C pins) are used for some other purpose. Please change those code by shifting those to PORTA or PORTB pins.

Embedded Circuit designing and Programming is my profession.

- - - Updated - - -

7 Segment version. Year data written to RTC is not correct. Display still blinks. Test in hardware and reply. Maybe it is a Proteus problem. It displays all datas. Don't know why the last two 7 Segment displays are used.

BCD to Seven Segment decoder needed pullup resistors on output lines as they are open collector outputs.

117304d1431122973-rtc-ssd.png

Thanks a lot for everything
The LCD version works just fine for me, I did everything as you said and it worked like a charm, regarding the 7 segment version it needs more work and I will try it soon and report back to you.

Thanks again for your help and continuous support
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top