-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasmcode.asm
1266 lines (1102 loc) · 26.2 KB
/
asmcode.asm
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
#make_bin#
#LOAD_SEGMENT=FFFFh#
#LOAD_OFFSET=0000h#
#CS=0000h#
#IP=0000h#
#DS=0000h#
#ES=0000h#
#SS=0000h#
#SP=FFFEh#
#AX=0000h#
#BX=0000h#
#CX=0000h#
#DX=0000h#
#SI=0000h#
#DI=0000h#
#BP=0000h#
; add your code here
jmp st1
db 1022 dup(0)
;IVT end
;Data Segment
ADCA equ 00h ;ADC address bit A = 0
ADCB equ 01h ;ADC address bit B = 0
ADCC equ 02h ;ADC address bit C = 0
Hum_set_min equ 0003h
Hum_set_max equ 0004h
Hum_pres equ 0005h
Temp equ 0006h
DegC equ 0007h
TempBCD equ 0008h
PercH equ 0009h
PerBCD equ 000Ah
HumBCD equ 000Bh
0FF0h dw ISR_40
;Data Segment end
prta_55_1 equ 00h ;8255_1 - Humidity & ADCEOC PPI
prtb_55_1 equ 02h
prtc_55_1 equ 04h
creg_55_1 equ 06h
prta_55_2 equ 08h ;8255_2 - Temperature & LCD PPI
prtb_55_2 equ 0Ah
prtc_55_2 equ 0Ch
creg_55_2 equ 0Eh
cnt0_53 equ 10h ;8253
cnt1_53 equ 12h
cnt2_53 equ 14h
creg_53 equ 16h
add0_59 equ 18h
add1_59 equ 1Ah
;main program
st1: cli
; intialize ds, es,ss to start of RAM
mov ax,0200h
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0FFFEH
mov si,ADCA
mov [si],00000000b
mov si,ADCB
mov [si],00000010b
mov si,ADCC
mov [si],00000100b
;Initializing 8253
mov al , 00110110b ;initialising counter 0 in mode 3 with count = 5
out creg_53 , al
mov al,01110100b
out creg_53 ,al
mov al , 10110100b
out creg_53 ,al
mov al , 05h
out cnt0_53 , al
mov al , 00h
out cnt0_53 , al
mov al,50h
out cnt1_53 ,al
mov al,0C3h
out cnt1_53 ,al
mov al,70h
out cnt2_53,al
mov al, 17h
out cnt2_53,al
;8255 Initialize
mov al,92h ; 8255-1 Humidity & ADCEOC port A,B input C output
out creg_55_1,al
mov al, prta_55_1
mov dl, al
mov al,82h ; 8255-2 Temperature & LCD port B input A,C output
out creg_55_2,al
mov al, dl
out prtc_55_2,al
;8259 Initialize
mov al,00010011b
out add0_59,al
mov al,01000000b
out add1_59,al
mov al,00000001b
out add1_59,al
mov al,00000000b
out add1_59,al
;initializing LCD display.
;create delay of more than 100ms after power on
mov cx, 100
call DELAY_MS
mov al,10010010b
out creg_55_1,al ;initialising 8255_1
SEND 30h, 0, 0, 1
SEND 30h, 0, 0, 5
SEND 30h, 0, 0, 1
SEND 38h, 0, 0, 5
;written the display options.
SEND 8h, 0, 0, 1
SEND 1h, 0, 0, 1
;clear screen and cursor home
SEND 6, 0, 0, 2
;end of initialisation.
;to turn on display
SEND 0Fh, 0, 0, 1
call WORKING_
;/////////////////////Macros
;To change Address on ADC
ADCABCTchange MACRO A
PUSH BX
PUSH DX
PUSH CX
MOV CX, A
; Change ADCA
MOV si, ADCA
mov dl, [si]
XOR DL, 1
MOV [si], dl
;Decide to change ADCB every even address
mov ax, cx
mov dl, 2
div dl
cmp ah, 0
jnz donbT
mov si, ADCB
mov dl, [si]
XOR DL, 1
MOV [si], DL
;Decide to change ADCC every at count 4
donbT: cmp cx, 4
jnz doncT
mov si, ADCC
mov dl, [si]
XOR DL, 1
MOV [si], DL
doncT:
POP CX
POP DX
POP BX
ENDM
ADCABCHchange MACRO A
PUSH BX
PUSH DX
PUSH CX
MOV CX, A
; Change ADCA
MOV si, ADCA
mov dl, [si]
XOR DL, 1
MOV [si], dl
;Decide to change ADCB every even address
mov ax, cx
mov dl, 2
div dl
cmp ah, 0
jnz donbH
mov si, ADCB
mov dl, [si]
XOR DL, 1
MOV [si], DL
;Decide to change ADCC every at count 4
donbH: cmp cx, 4
jnz doncH
mov si, ADCC
mov dl, [si]
XOR DL, 1
MOV [si], DL
doncH:
POP CX
POP DX
POP BX
ENDM
;To send command or data to LCD
SEND MACRO PA_DATA, LCD_E, LCD_RS_RW, DELAY
PUSH CX
PUSH DX
in al, prta_55_1
mov dl, al
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
MOV AL, 0
OR AL, LCD_E ;Temp PC7 - LCD Enable Bit
mov cl, 1
ror al, cl
or al, dl ;PA6 - Relay
OUT prtc_55_2, AL
MOV AL, 0
OR AL, LCD_RS_RW ;Humid PC7 - RS ____ PC6 - R/W
mov cl, 2
ror al, cl
OUT prtc_55_1, AL
MOV AL, 80H ;LCD Enable Bit - Set
or al, dl
OUT prtc_55_2, AL
MOV CX, DELAY ;Delay count
call DELAY_MS
MOV AL, PA_DATA ;PA_DATA to PORTA
OUT prta_55_2, AL
NOP
NOP ;Small Delay
MOV AL, 0 ;LCD Enable Bit - Clear
or al, dl
OUT prtc_55_2, AL
MOV CX, 1 ;Delay count
call DELAY_MS
POP DX
POP CX
ENDM
;//////////////////////End of Macros
;Get Temp values from sensors
in al, prta_55_1
mov dl, al
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
mov al,82h ;Re-initialising 8255-2 Temperature & LCD port B input A,C output
out creg_55_2,al
mov ax,0
mov al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
mov bx,0
mov cx,0 ; To get values from 5 sensors
X1: ;Initialize ADCT and subsequent Address
mov si, ADCA
mov al, [si] ;BSR address A
out creg_55_2, al
mov si, ADCB ;BSR address B
mov al, [si]
out creg_55_2, al
mov si, ADCC ;BSR address C
mov al, [si]
out creg_55_2, al
inc cx
ADCABCTchange cx
;ALE - Address Latch enable
mov al, 00001011b ;PC5 - ALE = 1
out creg_55_2, al
mov al, 00001001b ;PC4 = Start = 1 pulse
out creg_55_2, al
NOP ;Delay of 3 Machine cycles = 3*200ns
mov al, 00001010b ;PC5 - ALE = 0
out creg_55_2, al
mov al, 00001000b ;PC4 = Start = 0 pulse
out creg_55_2, al
in al, prta_55_1
mov dl, al
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
mov al,82h ; Re-initialising 8255-2 Temp and LCD port B input A, C output
out creg_55_2,al
mov al, 0
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
Y2: ;Wait for EOC
in al, prta_55_1 ;PA0 of 8255 1 is ADCTEOC
and al, 1 ;Mask all but PA0
cmp al, 1 ;if EOC
jnz Y2
;Read Value from ADCT
in al, prta_55_1
mov dl, al
mov al, 8 ;PC3 = ADC Output Enable = 1
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
in al, prta_55_1
mov dl, al
mov al, 0 ;PC3 = ADC Output Enable = 0
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
in al, prta_55_1
mov dl, al
mov al, 8 ;PC3 = ADC Output Enable = 1
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
in al,prtb_55_2 ;Value from ADCT stored in PORTB 8255_Temp
mov ah, 0
add bx,ax ;Sensor values aggregated
;Output Disable
in al, prta_55_1
mov dl, al
mov al, 0 ;PC3 = ADC Output Disable = 0
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
cmp cx, 4 ;Check whether 5 sensors read
jnz X1
;//////dividing by 5///////
mov ax,bx
mov bl,4
div bl
mov si, Temp
mov [si], al ; register al has final value - Stored in Temp
;Resetting ADC addresses
MOV DL, 00000000b
mov si, ADCA
MOV [si], DL
MOV DL, 00000010b
mov si, ADCB
MOV [si], DL
MOV DL, 00000100b
mov si, ADCC
MOV [si], DL
;Set Hum_set_min and Hum_set_max according to Temp
;LMT85 Vout is inversely proportional to Temp
;Greater Temp ==> Lower Voltage ==> Lower 8-bit value
;Humidity 30.68mv/%RH and 0% = 0.958V
mov si, Temp ;Check value of Temp stored
mov al, [si]
mov ah, 0
cmp ax, 004Eh ;Temp = 5 degC = 1.527V
jl t1
mov si, Hum_set_min
mov [si], 5Ch ;RH 27.5% = 1.8023V
mov si, Hum_set_max
mov [si], 60h ;RH 30% = 1.879V
jmp rangeset
t1: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 004Ch ;Temp = 10 degC = 1.486V
jl t2
mov si, Hum_set_min
mov [si], 60h ;RH 30% = 1.879V
mov si, Hum_set_max
mov [si], 64h ;RH 32.5% = 1.9557V
jmp rangeset
t2: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 004Ah ;Temp = 15 degC = 1.446V
jl t3
mov si, Hum_set_min
mov [si], 64h ;RH 32.5% = 1.9557V
mov si, Hum_set_max
mov [si], 68h ;RH 35% = 2.0325V
jmp rangeset
t3: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0048h ;Temp = 20 degC = 1.405V
jl t4
mov si, Hum_set_min
mov [si], 68h ;RH 35% = 2.0325V
mov si, Hum_set_max
mov [si], 6Ch ;RH 38% = 2.1246V
jmp rangeset
t4: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0046h ;Temp = 25 degC = 1.365V
jl t5
mov si, Hum_set_min
mov [si], 6Ch ;RH 38% = 2.1246V
mov si, Hum_set_max
mov [si], 70h ;RH 40% = 2.186V
jmp rangeset
t5: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0043h ;Temp = 30 degC = 1.324V
jl t6
mov si, Hum_set_min
mov [si], 70h ;RH 40% = 2.186V
mov si, Hum_set_max
mov [si], 74h ;RH 43% = 2.2781V
jmp rangeset
t6: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0041h ;Temp = 35 degC = 1.283V
jl t7
mov si, Hum_set_min
mov [si], 74h ;RH 43% = 2.2781V
mov si, Hum_set_max
mov [si], 78h ;RH 45% = 2.3386V
jmp rangeset
t7: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 003Dh ;Temp = 45 degC = 1.201V
jl t8
mov si, Hum_set_min
mov [si], 78h ;RH 45% = 2.3386V
mov si, Hum_set_max
mov [si], 7Ch ;RH 48% = 2.4316V
jmp rangeset
t8: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0039h ;Temp = 55 degC = 1.118V
jl t9
mov si, Hum_set_min
mov [si], 7Ch ;RH 48% = 2.4316V
mov si, Hum_set_max
mov [si], 80h ;RH 50% = 2.493V
jmp rangeset
t9: ;Temp greater than 55degC
mov si, Hum_set_min
mov [si], 80h ;RH 50% = 2.493V
mov si, Hum_set_max
mov [si], 84h ;RH 53% = 2.5851V
rangeset:
;////////////////Humidity!!!!
;Get Humidity values from sensors
mov bx,0
mov cx,0 ; To get values from 7 sensors
mov al,92h ; Re-initialising 8255-1 Humidity & ADCEOC port A,B input C output
out creg_55_1,al
X2: ;Initialize ADCH and subsequent Address
mov si, ADCA
mov al, [si] ;BSR address A
out creg_55_1, al
mov si, ADCB ;BSR address B
mov al, [si]
out creg_55_1, al
mov si, ADCC ;BSR address C
mov al, [si]
out creg_55_1, al
inc cx
ADCABCHchange cx
;ALE - Address Latch enable
mov al, 00001011b ;PC5 - ALE = 1
out creg_55_1, al
mov al, 00001001b ;PC4 = Start = 1 pulse
out creg_55_1, al
NOP ;Delay of 3 Machine cycles = 3*200ns
mov al, 00001010b ;PC5 - ALE = 0
out creg_55_1, al
mov al, 00001000b ;PC4 = Start = 0 pulse
out creg_55_1, al
mov al,92h ; Re-initialising 8255-1 Humidity & ADCEOC port A,B input C output
out creg_55_1,al
mov al, 0
out prtc_55_1, al
Y4: ;Wait for EOC
in al, prta_55_1 ;PA1 of 8255 1 is ADCHEOC
and al, 2 ;Mask all but PA1
cmp al, 2 ;if EOC
jnz Y4
;Read Value from ADCT
mov al, 8h ;PC3 = ADC Output Enable = 1
out prtc_55_1, al
mov al, 0h ;PC3 = ADC Output Enable = 0
out prtc_55_1, al
NOP
mov al, 8h ;PC3 = ADC Output Enable = 1
out prtc_55_1, al
in al,prtb_55_1 ;Value from ADCH stored in PORTB 8255_Hum
mov ah, 0
add bx,ax ;Sensor values aggregated
;Output Disable
mov al, 0h ; PC3 = ADC Output Disable = 0
out prtc_55_1, al
cmp cx, 4 ;Check whether 7 sensors read
jnz X2
;//////dividing by 7///////
mov ax,bx
mov bl,4
div bl
mov si, Hum_pres
mov [si], al ; register al has final value - Stored in Hum_pres
;Resetting ADC addresses
MOV DL, 00000000b
mov si, ADCA
MOV [si], DL
MOV DL, 00000010b
mov si, ADCB
MOV [si], DL
MOV DL, 00000100b
mov si, ADCC
MOV [si], DL
;Glow LED if Hum_pres < Hum_set_min
mov ax, 0
mov bx, 0
mov si, Hum_pres ;Check value of Hum_pres stored
mov al, [si]
mov si, Hum_set_min
mov bl, [si]
cmp ax, bx
jl z2
mov al,82h ;Re-initialising 8255-2 Temperature & LCD port B input A,C output
out creg_55_2,al
mov al, 0 ;PC6 = 0 = Humid ON
out prtc_55_2, al
jmp displaying
z2:;Stop LED if Hum_pres > Hum_set_max
mov ax, 0
mov bx, 0
mov si, Hum_pres ;Check value of Hum_pres stored
mov al, [si]
mov si, Hum_set_max
mov bl, [si]
cmp ax, bx
jg displaying
mov al,82h ;Re-initialising 8255-2 Temperature & LCD port B input A,C output
out creg_55_2,al
mov al, 40h ;PC6 = 1 = Humid OFF
out prtc_55_2, al
displaying:
CALL DISPLAYING_
ISR_40:
ADCABCT1change MACRO A
PUSH BX
PUSH DX
PUSH CX
MOV CX, A
; Change ADCA
MOV si, ADCA
mov dl, [si]
XOR DL, 1
MOV [si], dl
;Decide to change ADCB every even address
mov ax, cx
mov dl, 2
div dl
cmp ah, 0
jnz donbT1
mov si, ADCB
mov dl, [si]
XOR DL, 1
MOV [si], DL
;Decide to change ADCC every at count 4
donbT1: cmp cx, 4
jnz doncT1
mov si, ADCC
mov dl, [si]
XOR DL, 1
MOV [si], DL
doncT1:
POP CX
POP DX
POP BX
ENDM
ADCABCHchange1 MACRO A
PUSH BX
PUSH DX
PUSH CX
MOV CX, A
; Change ADCA
MOV si, ADCA
mov dl, [si]
XOR DL, 1
MOV [si], dl
;Decide to change ADCB every even address
mov ax, cx
mov dl, 2
div dl
cmp ah, 0
jnz donbH1
mov si, ADCB
mov dl, [si]
XOR DL, 1
MOV [si], DL
;Decide to change ADCC every at count 4
donbH1: cmp cx, 4
jnz doncH1
mov si, ADCC
mov dl, [si]
XOR DL, 1
MOV [si], DL
doncH1:
POP CX
POP DX
POP BX
ENDM
;To send command or data to LCD
SEND1 MACRO PA_DATA, LCD_E, LCD_RS_RW, DELAY
PUSH CX
PUSH DX
in al, prta_55_1
mov dl, al
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
MOV AL, 0
OR AL, LCD_E ;Temp PC7 - LCD Enable Bit
mov cl, 1
ror al, cl
or al, dl ;PA6 - Relay
OUT prtc_55_2, AL
MOV AL, 0
OR AL, LCD_RS_RW ;Humid PC7 - RS ____ PC6 - R/W
mov cl, 2
ror al, cl
OUT prtc_55_1, AL
MOV AL, 80H ;LCD Enable Bit - Set
or al, dl
OUT prtc_55_2, AL
MOV CX, DELAY ;Delay count
call DELAY_MS
MOV AL, PA_DATA ;PA_DATA to PORTA
OUT prta_55_2, AL
NOP
NOP ;Small Delay
MOV AL, 0 ;LCD Enable Bit - Clear
or al, dl
OUT prtc_55_2, AL
MOV CX, 1 ;Delay count
call DELAY_MS
POP DX
POP CX
ENDM
;//////////////////////End of Macros
;Get Temp values from sensors
in al, prta_55_1
mov dl, al
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
mov al,82h ;Re-initialising 8255-2 Temperature & LCD port B input A,C output
out creg_55_2,al
mov ax,0
mov al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
mov bx,0
mov cx,0 ; To get values from 5 sensors
X11: ;Initialize ADCT and subsequent Address
mov si, ADCA
mov al, [si] ;BSR address A
out creg_55_2, al
mov si, ADCB ;BSR address B
mov al, [si]
out creg_55_2, al
mov si, ADCC ;BSR address C
mov al, [si]
out creg_55_2, al
inc cx
ADCABCT1change cx
;ALE - Address Latch enable
mov al, 00001011b ;PC5 - ALE = 1
out creg_55_2, al
mov al, 00001001b ;PC4 = Start = 1 pulse
out creg_55_2, al
NOP ;Delay of 3 Machine cycles = 3*200ns
mov al, 00001010b ;PC5 - ALE = 0
out creg_55_2, al
mov al, 00001000b ;PC4 = Start = 0 pulse
out creg_55_2, al
in al, prta_55_1
mov dl, al
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
mov al,82h ; Re-initialising 8255-2 Temp and LCD port B input A, C output
out creg_55_2,al
mov al, 0
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
Y21: ;Wait for EOC
in al, prta_55_1 ;PA0 of 8255 1 is ADCTEOC
and al, 1 ;Mask all but PA0
cmp al, 1 ;if EOC
jnz Y21
;Read Value from ADCT
in al, prta_55_1
mov dl, al
mov al, 8 ;PC3 = ADC Output Enable = 1
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
in al, prta_55_1
mov dl, al
mov al, 0 ;PC3 = ADC Output Enable = 0
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
in al, prta_55_1
mov dl, al
mov al, 8 ;PC3 = ADC Output Enable = 1
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
in al,prtb_55_2 ;Value from ADCT stored in PORTB 8255_Temp
mov ah, 0
add bx,ax ;Sensor values aggregated
;Output Disable
in al, prta_55_1
mov dl, al
mov al, 0 ;PC3 = ADC Output Disable = 0
and dl, 40h ;RelayH -> PA6 - 8255H _ 1
or al, dl ;Reset Port C of Temp ADC
out prtc_55_2, al
cmp cx, 4 ;Check whether 5 sensors read
jnz X11
;//////dividing by 5///////
mov ax,bx
mov bl,4
div bl
mov si, Temp
mov [si], al ; register al has final value - Stored in Temp
;Resetting ADC addresses
MOV DL, 00000000b
mov si, ADCA
MOV [si], DL
MOV DL, 00000010b
mov si, ADCB
MOV [si], DL
MOV DL, 00000100b
mov si, ADCC
MOV [si], DL
;Set Hum_set_min and Hum_set_max according to Temp
;LMT85 Vout is inversely proportional to Temp
;Greater Temp ==> Lower Voltage ==> Lower 8-bit value
;Humidity 30.68mv/%RH and 0% = 0.958V
mov si, Temp ;Check value of Temp stored
mov al, [si]
mov ah, 0
cmp ax, 004Eh ;Temp = 5 degC = 1.527V
jl t11
mov si, Hum_set_min
mov [si], 5Ch ;RH 27.5% = 1.8023V
mov si, Hum_set_max
mov [si], 60h ;RH 30% = 1.879V
jmp rangeset1
t11: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 004Ch ;Temp = 10 degC = 1.486V
jl t2
mov si, Hum_set_min
mov [si], 60h ;RH 30% = 1.879V
mov si, Hum_set_max
mov [si], 64h ;RH 32.5% = 1.9557V
jmp rangeset1
t21: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 004Ah ;Temp = 15 degC = 1.446V
jl t31
mov si, Hum_set_min
mov [si], 64h ;RH 32.5% = 1.9557V
mov si, Hum_set_max
mov [si], 68h ;RH 35% = 2.0325V
jmp rangeset1
t31: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0048h ;Temp = 20 degC = 1.405V
jl t41
mov si, Hum_set_min
mov [si], 68h ;RH 35% = 2.0325V
mov si, Hum_set_max
mov [si], 6Ch ;RH 38% = 2.1246V
jmp rangeset1
t41: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0046h ;Temp = 25 degC = 1.365V
jl t51
mov si, Hum_set_min
mov [si], 6Ch ;RH 38% = 2.1246V
mov si, Hum_set_max
mov [si], 70h ;RH 40% = 2.186V
jmp rangeset1
t51: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0043h ;Temp = 30 degC = 1.324V
jl t61
mov si, Hum_set_min
mov [si], 70h ;RH 40% = 2.186V
mov si, Hum_set_max
mov [si], 74h ;RH 43% = 2.2781V
jmp rangeset1
t61: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0041h ;Temp = 35 degC = 1.283V
jl t71
mov si, Hum_set_min
mov [si], 74h ;RH 43% = 2.2781V
mov si, Hum_set_max
mov [si], 78h ;RH 45% = 2.3386V
jmp rangeset1
t71: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 003Dh ;Temp = 45 degC = 1.201V
jl t81
mov si, Hum_set_min
mov [si], 78h ;RH 45% = 2.3386V
mov si, Hum_set_max
mov [si], 7Ch ;RH 48% = 2.4316V
jmp rangeset1
t81: mov si, Temp
mov al, [si]
mov ah, 0
cmp ax, 0039h ;Temp = 55 degC = 1.118V
jl t91
mov si, Hum_set_min
mov [si], 7Ch ;RH 48% = 2.4316V
mov si, Hum_set_max
mov [si], 80h ;RH 50% = 2.493V
jmp rangeset1
t91: ;Temp greater than 55degC
mov si, Hum_set_min
mov [si], 80h ;RH 50% = 2.493V
mov si, Hum_set_max
mov [si], 84h ;RH 53% = 2.5851V
rangeset1:
;////////////////Humidity!!!!
;Get Humidity values from sensors
mov bx,0
mov cx,0 ; To get values from 7 sensors
mov al,92h ; Re-initialising 8255-1 Humidity & ADCEOC port A,B input C output
out creg_55_1,al
X21: ;Initialize ADCH and subsequent Address
mov si, ADCA
mov al, [si] ;BSR address A
out creg_55_1, al
mov si, ADCB ;BSR address B
mov al, [si]
out creg_55_1, al
mov si, ADCC ;BSR address C
mov al, [si]
out creg_55_1, al
inc cx
ADCABCHchange1 cx
;ALE - Address Latch enable
mov al, 00001011b ;PC5 - ALE = 1
out creg_55_1, al
mov al, 00001001b ;PC4 = Start = 1 pulse
out creg_55_1, al
NOP ;Delay of 3 Machine cycles = 3*200ns
mov al, 00001010b ;PC5 - ALE = 0
out creg_55_1, al
mov al, 00001000b ;PC4 = Start = 0 pulse
out creg_55_1, al
mov al,92h ; Re-initialising 8255-1 Humidity & ADCEOC port A,B input C output
out creg_55_1,al
mov al, 0
out prtc_55_1, al
Y41: ;Wait for EOC
in al, prta_55_1 ;PA1 of 8255 1 is ADCHEOC
and al, 2 ;Mask all but PA1
cmp al, 2 ;if EOC
jnz Y41
;Read Value from ADCT
mov al, 8h ;PC3 = ADC Output Enable = 1
out prtc_55_1, al
mov al, 0h ;PC3 = ADC Output Enable = 0
out prtc_55_1, al
NOP
mov al, 8h ;PC3 = ADC Output Enable = 1
out prtc_55_1, al
in al,prtb_55_1 ;Value from ADCH stored in PORTB 8255_Hum
mov ah, 0
add bx,ax ;Sensor values aggregated
;Output Disable
mov al, 0h ; PC3 = ADC Output Disable = 0
out prtc_55_1, al
cmp cx, 4 ;Check whether 7 sensors read
jnz X21
;//////dividing by 7///////
mov ax,bx
mov bl,4
div bl
mov si, Hum_pres
mov [si], al ; register al has final value - Stored in Hum_pres
;Resetting ADC addresses
MOV DL, 00000000b
mov si, ADCA
MOV [si], DL
MOV DL, 00000010b
mov si, ADCB