-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKP_InputFunctions.c
1577 lines (1517 loc) · 40.4 KB
/
KP_InputFunctions.c
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-------------------------------------------------------------------------
* Developed for Enersys Energy Solutions Private Limited, Hyderabad, Indiaresearch
* research on Auto Feeder.
* If you use the code cite the paper
* Appana, D. K., Alam, M. W., & Basnet, B. (2016) "A Novel Design of Feeder System
* for Aqua Culture Suitable for Shrimp Farming," International Journal of Hybrid
* Information Technology, 9(4), 199-212.
* http://www.sersc.org/journals/IJHIT/vol9_no4_2016/18.pdf
* (c) Copyright 2016 Enersys Energy Solutions, All rights reserved
*-------------------------------------------------------------------------*/
#include "INIT.h"
#include "KP_InputFunctions.h"
#include "XLCD2.h"
#include "UART.h"
#include "RTC.h"
#include "flags.h"
#include "StringManipulated.h"
#include "timer.h"
#include "Ex_EEPROM.h"
#include "24lc256.h"
#include "main.h"
#include "uart.h"
#include <reset.h>
#include"adcMUX.h"
#define ShowScreen(x,y,z) Xaxis = x, Yaxis = y, Zaxis = z
void ChangePassword( void );
extern void PCPutInt1(unsigned long int i);
extern void Switch_OFF_FEEDER(void);
unsigned char EnteredPW[5], *pEnteredPW = 0;
unsigned char CursorPos =0, KPHBuff[4], KPMBuff[4], *pHour =0, *pMin =0;
unsigned char KPHBuff_off[4];
unsigned char KPMBuff_off[4];
extern unsigned char Yaxis, Xaxis, Zaxis, KP_Data, CIndex;
unsigned char MasterPW[5] = "8722";
extern FlowControl Bits;
extern Time SystemTime;
extern Time Each_Auto_Shift_Time;
LCDflags Lcd = { 0b00000000000 };
unsigned char Lcd_Z = 0;
extern char Line1Buff[16];
extern Time ONTime[], OFFTime[], FirstONTime, No_Of_ON_Hours, No_Of_OFF_Hours;
unsigned char position = AUTO;
//unsigned char Feed_Loaded = FALSE;
/*12345678901234567890*/
static const char SPAC[] = " "; /* Black Spcace */
static const char MPWD[] = " MASTER PASSWORD ";
static const char PA_[] = " ENTER PASSWORD ";
static const char MENU[] = " MENU "; /* Main Menu Name */
static const char PE_[] = " ____ ";
static const char HardReset[] = "< DEFAULT SETTINGS ";
static const char Time_[] = " HH:MM - __:__ ";
static const char Date_[] = "DD:MM:YY - __:__:__ ";
static const char Ero[] = " Error ";
static const char RE_[] = " ->Yes '0' Cnl ";
static const char SETTIME[]= " SET TIME >"; /* Set Time Screen name */
static const char SETDATE[]= "< SET DATE >"; /* Set Date Screen name */
static const char AUTO_P_SETTNGS_[] = "< AUTO+ SETTINGS >";
static const char NO_OF_SHIFTS_[] = " No. OF SHIFTS ";
static const char ON_TIME_[]= " ON TIME - __:__ "; //" ON TIME - HH:MM ";
static const char OFF_TIME_[]= " OFF TIME - __:__ "; //" OFF TIME - HH:MM ";
static const char CHNG_PSWD[] = "< CHANGE PASSWORD ";
static const char CHNG_PSWD_1[] = " CHANGE PASSWORD ";
static const char SAVE_CANCEL[] = " SAVE CANCEL ";
static const char AUTO_[] = "< AUTO >";
static const char AUTO_PLUS_[] = "< AUTO+ ";
static const char MANUAL_[] = " MANUAL >";
static const char ENTER_CANCEL[] = " ENTER CANCEL ";
static const char OPP_MODE_[] = " OPERATION MODE >";
static const char OPP_MODE_1[] = " OPERATION MODE ";
static const char AUTO_MODE_[] = "< AUTO SETTINGS >";
static const char PWR_FAIL_ADJ_[] = "< ADJ PWR FAIL TIME>";
static const char ENABLE_[] = " ENABLE >";
static const char DISABLE_[] = "< DISABLE ";
static const char PWR_LOG_[] = "< POWER FAIL LOG >";
static const char HLV_CUT_MENU[] = "< HLV CUT >";
static const char HLV_CUT_[] = " HLV CUT ";
static const char HV_CUT_[] = " HV CUT : ___ ";
static const char LV_CUT_[] = " LV CUT : ___ ";
static const char NOOFSHI_[] = " _ ";
static const char CALIB_[] = "< CALIBRATION >";
static const char R_PHASE_VOL_[] = " R PHASE: ___._ V ";
static const char Y_PHASE_VOL_[] = " Y PHASE: ___._ V ";
static const char B_PHASE_VOL_[] = " B PHASE: ___._ V ";
static const char LOAD2LOAD[] = "<LOAD TO LOAD DELAY>"; // Masterscreen3 - Set Load to Load Delay
static const char RSTMENUPWD[] = "< RESET PASSWORD >"; // Masterscreen5 - Reset Menu Password.
static const char RSTMENUPWD_[] = " RESTORE PASSWORD ";
unsigned int Load_Delay = 10;
unsigned char process_lcd = 0;
unsigned char process_lcd_buff[20];
static unsigned char *ptr;
unsigned char value_entered = 0;
unsigned char temp_noofshifts = 0;
unsigned char process_time_buff[8][9];
unsigned char shifts_count = 0;
unsigned char No_of_Sifts = DFLT_NO_OF_SHIFTS;
unsigned char HLV_mode = DFLT_HLV_MODE;
unsigned int temp_HV = 0, temp_LV = 0;
float User_Ent_R_phase = 0;
float User_Ent_Y_phase = 0;
float User_Ent_B_phase = 0;
float Mult_Fact_R = 0.3;
float Temp_Mult_Fact_R = 0;
float Temp_Mult_Fact_Y = 0;
extern unsigned long int Calib_RMS_R_ph, Calib_RMS_Y_ph, Calib_RMS_B_ph;
float Mult_Fact_Y = 0.3;
float Mult_Fact_B = 0.3;
extern unsigned char Master_Mode;
unsigned int R_int = 0;
unsigned char R_float = 0;
unsigned int Y_int = 0;
unsigned char Y_float = 0;
unsigned int B_int = 0;
unsigned char B_float = 0;
void PasswordEnter( unsigned char PswdType )
{
if( Lcd.Z0 == 0)
{
XLCDL1home();
XLCDPutRamString(SPAC);
XLCDL2home();
if(PswdType == 0) XLCDPutRamString(PA_);
else if(PswdType == 1) XLCDPutRamString(MPWD);
XLCDL4home();
XLCDPutRamString(SPAC);
XLCDL3home();
XLCDPutRamString(PE_);
Lcd.Z0 = 1,KP_Data = 0,CursorPos = 0;
MoveLeft(12);
XLCD_BLINKOON();
pEnteredPW = EnteredPW;
}
if(Lcd.Z0 == 1)
{
if(KP_Data > 47 && KP_Data < 58 && CursorPos < 4)
{
CursorPos++;
XLCDPut('*');
*pEnteredPW++ = KP_Data;
if(CursorPos == 4) XLCD_CURSOR_OFF();
KP_Data =0;
}
else if ( KP_Data == 'E' && CursorPos == 4)
{
if( !PswdType ) // check for main password
{
if( MemoryCMP(ExstingPW,EnteredPW) )
{
Lcd.Z0 = 0, KP_Data = 0, pEnteredPW = 0;
Bits.PassWord = 1, ShowScreen(0,1,0);
}
else
{
ShowScreen(0,0,0),Bits.PassWord = 0; /* Go to the Main Menu if Wrong Password is pressed */
Lcd.Z0 = 0, KP_Data = 0;
}
}
else if( PswdType ) // check for Hard reset password
{
if( MemoryCMP(MasterPW,EnteredPW) )
{
Lcd.Z0 = 0,KP_Data =0,pEnteredPW = 0;
process_lcd = 1;
if(Xaxis == 0) ShowScreen(0,1,0);
else
Lcd.Z12 = 1;
}
else
{
ShowScreen(0,2,0); /* Go to the Main Menu if Wrong Password is pressed */
Lcd.Z0 = 0, KP_Data =0;
}
}
MemoryClear(EnteredPW);
}
else if (KP_Data == 'C')
{
Bits.PassWord = 0, pEnteredPW = 0; /* Go to the Main Menu if Wrong Password is pressed */
Lcd.Z0 = 0,KP_Data =0;
Master_Mode = 0;
MemoryClear(EnteredPW);
ShowScreen(0,0,0);
}
}
}
void MenuFunction(void )
{
XLCD_CURSOR_OFF();
XLCDL1home();
XLCDPutRamString(SPAC);
XLCDL2home();
XLCDPutRamString(MENU);
XLCDL3home();
if(Master_Mode == 0)
MenuScreens( );
else if(Master_Mode == 1)
Master_MenuScreens( );
if( KP_Data == 'E')
Zaxis = Xaxis + 1;
XLCDL4home();
XLCDPutRamString(SPAC);
}
void MenuScreens( void )
{
switch(Xaxis)
{
case 0: XLCDPutRamString(OPP_MODE_);
break;
case 1: XLCDPutRamString(AUTO_P_SETTNGS_);
break;
case 2: XLCDPutRamString(AUTO_MODE_);
break;
case 3: XLCDPutRamString(HLV_CUT_MENU);
break;
case 4: XLCDPutRamString(CHNG_PSWD);
break;
default:XLCDPutRamString(SPAC);
}
}
void CustomScreens( void )
{
switch(Zaxis)
{
case 1: SetOperationMode();
break;
case 2: Auto_Plus_Settings();
break;
case 3: AutoSettings(); // set Duration Mode: ON/OFF time base or No of Hours
break;
case 4: Change_HLV_Cut();
break;
case 5: ChangePassword();
break;
default:ErrorScreen();
break;
}
}
void Master_MenuScreens( void )
{
switch(Xaxis)
{
case 0: XLCDPutRamString(SETTIME);
break;
case 1: XLCDPutRamString(SETDATE);
break;
case 2: XLCDPutRamString(LOAD2LOAD);
break;
case 3: XLCDPutRamString(CALIB_);
break;
case 4: XLCDPutRamString(RSTMENUPWD);
break;
case 5: XLCDPutRamString(HardReset);
break;
default:XLCDPutRamString(SPAC);
}
}
void Master_CustomScreens( void )
{
switch(Zaxis)
{
case 1: SetTime(); // set RTC time and system time
break;
case 2: SetDate(); // set RTC date
break;
case 3: SetLoadDelay(); // set load delay
break;
case 4: Calibration();
break;
case 5: ResetMenuPassword(); // Reset Menu Password
break;
case 6: SetHardResetFunction();
break;
default:ErrorScreen();
break;
}
}
void SetTime(void)
{
unsigned char bHour =0, bMin =0;
if( Lcd.Z0 == 0)
{
memset(process_lcd_buff,0x00,20);
XLCDL1home();
XLCDPutRamString(SETTIME);
XLCDL3home();
XLCDPutRamString(SPAC);
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
XLCDL2home();
XLCDPutRamString(Time_);
MoveLeft(9);
Lcd.Z0 = 1,KP_Data = 0,CursorPos = 0;
XLCD_BLINKOON();
value_entered = 0;
ptr = process_lcd_buff;
}
if(Lcd.Z0 == 1)
{
if(KP_Data == 'U' && CursorPos>0)
{
ptr--;
KP_Data = 0;
CursorPos--;
MoveLeft(1)
if(CursorPos == 1)
MoveLeft(1)
}
else if(KP_Data == 'D' && CursorPos < 3 && CursorPos<value_entered)
{
ptr++;
KP_Data = 0;
CursorPos++;
MoveRight(1)
if(CursorPos == 2)
MoveRight(1)
}
else if( KP_Data > 47 && KP_Data < 58 && CursorPos < 4)
{
CursorPos++;
value_entered++;
XLCDPut(KP_Data);
*ptr++ = KP_Data;
KP_Data = 0;
if(CursorPos == 2)
MoveRight(1)
if(CursorPos == 4)
{
ptr--;
MoveLeft(1)
CursorPos--;
}
}
if( KP_Data == 'C')
{
Lcd.Z0 = 0,KP_Data =0;
value_entered = 0;
CursorPos = 0;
ShowScreen(Zaxis-1,1,0);
}
else if (KP_Data == 'S' && value_entered >= 4)
{
bHour = ConvertSTRING_CHAR(&process_lcd_buff[0],2);
bMin = ConvertSTRING_CHAR(&process_lcd_buff[2],2);
if( bHour < 24 && bMin < 60)
{
SystemTime.Hours = bHour,SystemTime.Minutes = bMin,Bits.RTCSetNewTime = 1;
W_RTC_Time(SystemTime.Hours, SystemTime.Minutes, 0);
Char_WriteEEPROM_ex(1, _RTCSetNewTime); // To check whether Time is set
Char_WriteEEPROM_ex(bHour, eepromsysTimeHr);
Char_WriteEEPROM_ex(bMin, eepromsysTimeMin);
if(Operation_mode == AUTO)
Check_Present_Auto_Shift_Time();
else if(Operation_mode == AUTO_PLUS)
{
Decide_AutoPlus_Shift_Position();
}
}
Lcd.Z0 = 0,KP_Data =0,pMin =0, pHour =0;
value_entered = 0;
CursorPos = 0;
ShowScreen(Zaxis-1,1,0);
}
}
}
void SetONOFFTime(unsigned char WHAT_TIME)
{
if( Lcd.Z0 == 0)
{
memset(&process_time_buff[WHAT_TIME][0],0x00,9);
XLCDL1home();
MemoryClear((unsigned char*)Line1Buff);
sprintf(Line1Buff, " SHIFT: %d ",(WHAT_TIME+1));
XLCDPutRamString(Line1Buff);
XLCDL4home();
if(shifts_count+1==temp_noofshifts)
XLCDPutRamString(SAVE_CANCEL);
else
XLCDPutRamString(ENTER_CANCEL);
XLCDL3home();
XLCDPutRamString(OFF_TIME_);
XLCDL2home();
XLCDPutRamString(ON_TIME_);
MoveLeft(7);
Lcd.Z0 = 1,KP_Data = 0;
XLCD_BLINKOON();
ptr = &process_time_buff[WHAT_TIME][0];
value_entered = 0;
CursorPos = 0;
}
if(Lcd.Z0 == 1)
{
if(KP_Data == 'U' && CursorPos>0)
{
ptr--;
KP_Data = 0;
CursorPos--;
MoveLeft(1)
if(CursorPos == 1 || CursorPos == 5)
MoveLeft(1)
else if(CursorPos == 3)
MoveRight(25)
}
else if(KP_Data == 'D' && CursorPos < 7 && CursorPos<value_entered)
{
ptr++;
KP_Data = 0;
CursorPos++;
MoveRight(1)
if(CursorPos == 2 || CursorPos == 6)
MoveRight(1)
else if(CursorPos == 4)
MoveLeft(25)
}
else if( KP_Data > 47 && KP_Data < 58 && CursorPos < 8)
{
CursorPos++;
value_entered++;
XLCDPut(KP_Data);
*ptr++ = KP_Data;
KP_Data = 0;
if(CursorPos == 2|| CursorPos == 6)
MoveRight(1)
else if(CursorPos == 4)
MoveLeft(25)
if(CursorPos == 8)
{
CursorPos--;
MoveLeft(1)
ptr--;
}
}
else if( KP_Data == 'C')
{
Lcd.Z0 = 0,KP_Data =0;
value_entered = 0;
CursorPos = 0;
shifts_count = 0;
process_lcd = 0;
ShowScreen(Zaxis-1,1,0);
}
else if( (KP_Data == 'E') && ((shifts_count+1)<temp_noofshifts) && (value_entered >= 8) )
{
KP_Data = 0;
Lcd.Z0 = 0;
value_entered = 0;
CursorPos = 0;
if(ValidateTime())
shifts_count++;
else
{
WrongValues_errorScreen(0);
}
}
else if( (shifts_count+1==temp_noofshifts) && (KP_Data == 'S') && (value_entered >= 8) )
{
KP_Data = 0;
Lcd.Z0 = 0;
value_entered = 0;
CursorPos = 0;
if(ValidateTime())
shifts_count++;
else
{
WrongValues_errorScreen(0);
}
}
}
}
void SetHardResetFunction( void )
{
if( Lcd.Z12 == 0 )
PasswordEnter( 1 );
else if( Lcd.Z12 == 1 )
{
if( Lcd.Z11 == 0 )
{
XLCDL2home();
XLCDPutRamString(HardReset);
XLCDL3home();
XLCDPutRamString(ENTER_CANCEL);
Lcd.Z11 = 1,KP_Data = 0;
}
else if(Lcd.Z11 == 1)
{
if( KP_Data == 'C')
ShowScreen(Zaxis-1,1,0),Lcd.Z11 = 0,KP_Data =0,Lcd.Z12 = 0;
else if (KP_Data == 'E')
{
Char_WriteEEPROM_ex(0xFF, EE_Compile_Len); /* To Check whether System is starting for the first time */
TimerDelay_10ms(5);
// Reset();
// PORStatReset;
__asm__ volatile ("reset") ;
}
}
}
}
void ChangePassword( void )
{
if( Lcd.Z7 == 0)
{
XLCDL2home();
XLCDPutRamString(" ENTER NEW PASSWORD ");
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
XLCDL3home();
XLCDPutRamString(PE_);
MoveLeft(12); /* */
XLCD_BLINKOON(); /* Blinking the cursor */
Lcd.Z7 = 1,KP_Data = 0,CursorPos =0;
pEnteredPW = EnteredPW;
}
else if(Lcd.Z7 == 1)
{
if( KP_Data > 47 && KP_Data < 58 ) /* Checking if any numerical values are pressed */
{
CursorPos++; /* Counting the number of characters */
if(CursorPos > 0 && CursorPos < 5) /* only first 4 characters are taken as password */
{
XLCDPut('*'); /* Masking the key by '*' */
*pEnteredPW++ = KP_Data;
*pEnteredPW ='\0';
}
if(CursorPos == 4)
XLCD_CURSOR_OFF();
KP_Data =0;
}
if (CursorPos >= 4 && KP_Data == 'S')
{
String_WriteEEPROM_ex(LCD_KEY, EnteredPW, 4); // write default password
StringCopy(EnteredPW,ExstingPW);
MemoryClear(EnteredPW);
Lcd.Z7 = 0,KP_Data =0,pEnteredPW =0,ShowScreen(Zaxis-1,1,0);
}
else if (KP_Data == 'C')
{
MemoryClear(EnteredPW);
Lcd.Z7 = 0,KP_Data =0,pEnteredPW =0,ShowScreen(Zaxis-1,1,0);
}
}
}
void SetLoadDelay(void)
{
if(Lcd.Z12 == 0)
{
MemoryClear((unsigned char *)Line1Buff);
XLCDL1home();
XLCDPutRamString(SPAC);
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
XLCDL3home();
XLCDPutRamString(SPAC);
XLCDL2home();
sprintf(Line1Buff," DELAY: %03d SEC ",Load_Delay);
XLCDPutRamString(Line1Buff);
sprintf(Line1Buff,"%03d",Load_Delay);
strcpy((char *)KPHBuff,(const char*)Line1Buff);
MoveLeft(10);
Lcd.Z12 = 1, KP_Data = 0,CursorPos = 0;
XLCD_BLINKOON();
ptr = KPHBuff;
MemoryClear((unsigned char *)Line1Buff);
}
else if(Lcd.Z12 == 1)
{
if( KP_Data > 47 && KP_Data < 58 && CursorPos < 3)
{
CursorPos++;
XLCDPut(KP_Data);
*ptr++ = KP_Data;
if(CursorPos == 3)
XLCD_CURSOR_OFF();
KP_Data =0;
}
else if(KP_Data == 'S')
{
if(CursorPos == 3)
{
Load_Delay = ConvertSTRING_Int((unsigned char*)&KPHBuff[0],3);
ptr = (unsigned char*)&Load_Delay;
String_WriteEEPROM_ex(2,ptr, EE_LOAD_DELAY); // write Load delay values
Lcd.Z12 = 0,CursorPos = 0;
ShowScreen(Zaxis-1,1,0);
}
KP_Data = 0;
}
else if(KP_Data == 'U' && CursorPos > 0)
{
CursorPos--;
ptr--;
KP_Data = 0;
MoveLeft(1);
if(CursorPos != 3)
XLCD_BLINKOON();
}
else if(KP_Data == 'D' && CursorPos <3)
{
CursorPos++;
ptr++;
KP_Data = 0;
MoveRight(1);
if(CursorPos == 3)
XLCD_CURSOR_OFF();
}
else if(KP_Data == 'C')
{
KP_Data = 0, Lcd.Z12 = 0, CursorPos = 0;
XLCD_CURSOR_OFF();
ShowScreen(Zaxis-1,1,0);
}
}
}
void ResetMenuPassword(void)
{
if(Lcd.Z13 == 0)
{
XLCDL1home();
XLCDPutRamString(SPAC);
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
XLCDL3home();
XLCDPutRamString(SPAC);
XLCDL2home();
XLCDPutRamString(RSTMENUPWD_);
Lcd.Z13 = 1,KP_Data = 0;
}
else if(Lcd.Z13 == 1)
{
if(KP_Data == 'S')
{
Lcd.Z13 = 0;
strcpy((char*)ExstingPW,LCD_PASSWORD);
String_WriteEEPROM_ex(4,(unsigned char*)LCD_PASSWORD,LCD_KEY); // Writing Default Password - LCD.
ShowScreen(Zaxis-1,1,0);
}
else if(KP_Data == 'C')
{
ShowScreen(Zaxis-1,1,0);
Lcd.Z13 = 0;
}
KP_Data = 0;
}
}
void ErrorScreen(void )
{
XLCDL1home();
XLCDPutRamString(Ero);
XLCDL2home();
XLCDPutRamString(SPAC);
}
void SetOperationMode(void)
{
if( Lcd.Z15 == 0 )
{
XLCDL1home();
XLCDPutRamString(OPP_MODE_1);
XLCDL2home();
XLCDPutRamString(SPAC);
XLCDL3home();
if(Operation_mode == MANUAL)
XLCDPutRamString(MANUAL_), CursorPos = 0;
else if(Operation_mode == AUTO)
XLCDPutRamString(AUTO_), CursorPos = 1;
else if(Operation_mode == AUTO_PLUS)
XLCDPutRamString(AUTO_PLUS_), CursorPos = 2;
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
Lcd.Z15 = 1,KP_Data = 0;
position = Operation_mode;
}
else if( Lcd.Z15 == 1 )
{
if( ((KP_Data == 'D') && (CursorPos==0)) || ((KP_Data == 'U') && (CursorPos==2)) )
{
if(KP_Data == 'D')
CursorPos++;
else
CursorPos--;
KP_Data = 0;
XLCDL3home();
XLCDPutRamString(AUTO_);
position = AUTO;
}
else if( KP_Data == 'D' && (CursorPos==1) )
{
KP_Data = 0;
CursorPos++;
XLCDL3home();
XLCDPutRamString(AUTO_PLUS_);
position = AUTO_PLUS;
}
else if( KP_Data == 'U' && (CursorPos==1) )
{
CursorPos--;
XLCDL3home();
XLCDPutRamString(MANUAL_);
position = MANUAL;
}
else if( KP_Data == 'S' )
{
if(Operation_mode != position) // if operation mode is changed
{
Manual_On_set = FALSE;
Char_WriteEEPROM_ex(Manual_On_set, EE_MAN_ON_SET);
Load_Status = 0;
Char_WriteEEPROM_ex(Load_Status, EE_LOAD_STATUS);
Switch_OFF_FEEDER();
}
Operation_mode = position;
if(Operation_mode == AUTO || Operation_mode == AUTO_PLUS)
{
Manual_On_set = FALSE;
Char_WriteEEPROM_ex(Manual_On_set, EE_MAN_ON_SET);
}
if(Operation_mode == AUTO)
Check_Present_Auto_Shift_Time();
else if(Operation_mode == AUTO_PLUS)
Decide_AutoPlus_Shift_Position();
Char_WriteEEPROM_ex(Operation_mode,EE_OPR_MODE);
ShowScreen(Zaxis-1,1,0), Lcd.Z15 = 0;
}
else if( KP_Data == 'C' )
{
ShowScreen(Zaxis-1,1,0), Lcd.Z15 = 0;
}
}
}
void AutoSettings(void)
{
unsigned char h1 = 0,m1 = 0;
unsigned char h2 = 0,m2 = 0;
unsigned char h3 = 0,m3 = 0;
if(process_lcd == 0)
{
memset(process_lcd_buff,0x00,20);
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
XLCDL1home();
// R_PHASE_VOL_[] = " R PHASE: ___._ V ";
sprintf(Line1Buff, " ON TIME - %02d:%02d ",FirstONTime.Hours,FirstONTime.Minutes);
XLCDPutRamString(Line1Buff);
XLCDL2home();
sprintf(Line1Buff, " RUN HOURS - %02d:%02d ",No_Of_ON_Hours.Hours,No_Of_ON_Hours.Minutes);
XLCDPutRamString(Line1Buff);
XLCDL3home();
sprintf(Line1Buff, " OFF HOURS - %02d:%02d ",No_Of_OFF_Hours.Hours,No_Of_OFF_Hours.Minutes);
XLCDPutRamString(Line1Buff);
MoveLeft(27);
XLCD_BLINKOON();
process_lcd = 1,KP_Data = 0;
CursorPos = 0;
sprintf((char*)process_lcd_buff, "%02d%02d%02d%02d%02d%02d",FirstONTime.Hours,FirstONTime.Minutes,No_Of_ON_Hours.Hours,No_Of_ON_Hours.Minutes,No_Of_OFF_Hours.Hours,No_Of_OFF_Hours.Minutes);
ptr = process_lcd_buff;
putsUART1((unsigned int *)process_lcd_buff);
}
else if(process_lcd == 1)
{
if(KP_Data == 'U' && CursorPos>0)
{
ptr--;
KP_Data = 0;
CursorPos--;
MoveLeft(1)
if(CursorPos == 1 || CursorPos == 5 || CursorPos == 9)
MoveLeft(1)
else if(CursorPos == 7)
MoveRight(25)
else if(CursorPos == 3)
MoveLeft(35)
}
else if(KP_Data == 'D' && CursorPos < 11)
{
ptr++;
KP_Data = 0;
CursorPos++;
MoveRight(1)
if(CursorPos == 2 || CursorPos == 6 || CursorPos == 10)
MoveRight(1)
else if(CursorPos == 4)
MoveRight(35)
else if(CursorPos == 8)
MoveLeft(25)
}
else if( KP_Data > 47 && KP_Data < 58 && CursorPos < 12)
{
CursorPos++;
XLCDPut(KP_Data);
*ptr++ = KP_Data;
KP_Data = 0;
if(CursorPos == 2 || CursorPos == 6 || CursorPos == 10)
MoveRight(1)
else if(CursorPos == 4)
MoveRight(35)
else if(CursorPos == 8)
MoveLeft(25)
if(CursorPos == 12)
{
CursorPos--;
ptr--;
MoveLeft(1)
}
}
else if(KP_Data == 'S')
{
h1 = ConvertSTRING_CHAR(&process_lcd_buff[0],2);
m1 = ConvertSTRING_CHAR(&process_lcd_buff[2],2);
h2 = ConvertSTRING_CHAR(&process_lcd_buff[4],2);
m2 = ConvertSTRING_CHAR(&process_lcd_buff[6],2);
h3 = ConvertSTRING_CHAR(&process_lcd_buff[8],2);
m3 = ConvertSTRING_CHAR(&process_lcd_buff[10],2);
// PCPutInt1(h1);
// PCPutInt1(m1);
// PCPutInt1(h2);
// PCPutInt1(m2);
// PCPutInt1(h3);
// PCPutInt1(m3);
// PCPutInt1(CursorPos);
if( h1 < 24 && h2 < 24 && h3 <24 && m1 < 60 && m2 < 60 && m3 < 60 && ((60*(h2+h3)+m2+m3)<=1440) && ((60*(h2+h3)+m2+m3)>1))
{
putsUART1((unsigned int*)"\n\rSuccess");
FirstONTime.Hours = h1;
FirstONTime.Minutes = m1;
No_Of_ON_Hours.Hours = h2;
No_Of_ON_Hours.Minutes = m2;
No_Of_OFF_Hours.Hours = h3;
No_Of_OFF_Hours.Minutes = m3;
Char_WriteEEPROM_ex(FirstONTime.Hours, EE_FIRST_ONTIME_HH);
Char_WriteEEPROM_ex(FirstONTime.Minutes, EE_FIRST_ONTIME_MM);
Char_WriteEEPROM_ex(No_Of_ON_Hours.Hours, EE_ON_HOURS_HH);
Char_WriteEEPROM_ex(No_Of_ON_Hours.Minutes, EE_ON_HOURS_MM);
Char_WriteEEPROM_ex(No_Of_OFF_Hours.Hours, EE_OFF_HOURS_HH);
Char_WriteEEPROM_ex(No_Of_OFF_Hours.Minutes, EE_OFF_HOURS_MM);
process_lcd = 0,KP_Data =0,CursorPos = 0;
Operation_mode = position;
Char_WriteEEPROM_ex(position,EE_OPR_MODE);
Each_Auto_Shift_Time.Value = No_Of_ON_Hours.Value + No_Of_OFF_Hours.Value;
CheckTimeBoundaries(&Each_Auto_Shift_Time);
Calc_No_Of_Auto_Shits_Cnts();
Check_Present_Auto_Shift_Time();
ShowScreen(Zaxis-1,1,0);
}
else
{
putsUART1((unsigned int*)"\n\rfail");
process_lcd = 0,KP_Data =0,CursorPos = 0;
WrongValues_errorScreen(0);
// ShowScreen(Zaxis-1,1,0);
}
}
else if(KP_Data == 'C')
{
process_lcd = 0,KP_Data =0,CursorPos = 0;
ShowScreen(Zaxis-1,1,0);
}
else if(KP_Data == 'E')
{
KP_Data = 0;
if(CursorPos<2)
{
MoveRight(40-CursorPos)
ptr = ptr + 4-CursorPos;
CursorPos = 4;
}
else if(CursorPos<4)
{
MoveRight(39-CursorPos)
ptr = ptr + 4-CursorPos;
CursorPos = 4;
}
else if(CursorPos<6)
{
MoveLeft(16+CursorPos)
ptr = ptr + 8-CursorPos;
CursorPos = 8;
}
else if(CursorPos<8)
{
MoveLeft(17+CursorPos)
ptr = ptr + 8-CursorPos;
CursorPos = 8;
}
}
}
}
void Auto_Plus_Settings(void)
{
if( process_lcd == 0 )
{
XLCDL1home();
XLCDPutRamString(SPAC);
XLCDL2home();
XLCDPutRamString(NO_OF_SHIFTS_);
XLCDL4home();
XLCDPutRamString(ENTER_CANCEL);
XLCDL3home();
XLCDPutRamString(NOOFSHI_);
process_lcd = 1,KP_Data = 0;
// CursorPos = 0;
MoveLeft(11);
XLCD_BLINKOON();
}
else if( process_lcd == 1 ) // for taking no of shits
{
if( KP_Data > 48 && KP_Data < 57 )
{
XLCDPut(KP_Data);
// CursorPos++;
temp_noofshifts = KP_Data - 0x30; // assigning no of shits in to temparory variable
shifts_count = 0;
KP_Data = 0;
MoveLeft(1);
// XLCD_CURSOR_OFF();
}
else if(KP_Data == 'E')
{
process_lcd = 2;
KP_Data = 0;
// CursorPos = 0;
}
else if(KP_Data == 'C')
{
process_lcd = 0,KP_Data =0,CursorPos = 0;
shifts_count = 0;
temp_noofshifts = 0;
ShowScreen(Zaxis-1,1,0);
}
}
else if( process_lcd == 2 ) // for taking no of shits
{
if(shifts_count<temp_noofshifts)
SetONOFFTime(shifts_count);
else // save all shift settings
{
SaveShiftSettings();
Decide_AutoPlus_Shift_Position();
process_lcd = 0,KP_Data =0;//,CursorPos = 0;
shifts_count = 0;
temp_noofshifts = 0;
ShowScreen(Zaxis-1,1,0);
}
}
}
void SetPwrFailAdjust(void)
{
}
void ShowPowerLog(void)
{
}
void SetDate(void)
{
unsigned char bDate =0, bMonth =0, bYear = 0;
if( Lcd.Z0 == 0)
{
memset(process_lcd_buff,0x00,20);
XLCDL1home();
XLCDPutRamString(SETDATE);
XLCDL3home();
XLCDPutRamString(SPAC);
XLCDL4home();
XLCDPutRamString(SAVE_CANCEL);
XLCDL2home();
XLCDPutRamString(Date_);
MoveLeft(9);
Lcd.Z0 = 1,KP_Data = 0,CursorPos = 0;
XLCD_BLINKOON();
value_entered = 0;