-
Notifications
You must be signed in to change notification settings - Fork 0
/
assembly_code.asm
executable file
·1363 lines (986 loc) · 18.3 KB
/
assembly_code.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
#LOAD_SEGMENT=0100h#
#LOAD_OFFSET=0000h#
#CS=0100h#
#IP=0000h#
#DS=0000h#
#ES=0000h#
#SS=0000h#
#SP=FFFEh#
#AX=0000h#
#BX=0000h#
#CX=0000h#
#DX=0000h#
#SI=0000h#
#DI=0000h#
#BP=0000h#
;-------------------------IVT-init-----------------------;
mov ax, offset isr0
mov [00200h], ax
mov ax, seg isr0
mov [00202h], ax
mov ax, offset isr1
mov [00204h], ax
mov ax, seg isr1
mov [00206h], ax
mov ax, offset isr2
mov [00208h], ax
mov ax, seg isr2
mov [0020Ah], ax
mov ax, offset isr3
mov [0020Ch], ax
mov ax, seg isr3
mov [0020Eh], ax
;-------------------------IVT-init-----------------------;
jmp start
db 512 dup(0)
;-------------------------Data-segment-----------------------;
cstatea db 00h
cstateb db 00h
lcdln1 db 'Temp(C): '
lcdln2 db 16 dup('-')
lcdln3 db 16 dup('.')
lcdln4 db 16 dup('*')
lcdcnt1 db 9d
lcdcnt2 db 16d
lcdcnt3 db 16d
lcdcnt4 db 16d
flagcount dw 0
vals db 12 dup(0)
ctr dw 0
readyForHour db 1 dup(0)
thp db 1 dup(0)
lcdln11 db 'Humi1(%): '
lcdln22 db 16 dup('-')
lcdln33 db 16 dup('.')
lcdln44 db 16 dup('*')
lcdcnt11 db 9d
lcdcnt22 db 16d
lcdcnt33 db 16d
lcdcnt44 db 16d
;Humi~
flagcount11 dw 0
vals11 db 12 dup(0)
ctr11 dw 0
lcdln111 db 'Pres(Ba):'
lcdln222 db 16 dup('-')
lcdln333 db 16 dup('.')
lcdln444 db 16 dup('*')
lcdcnt111 db 9d
lcdcnt222 db 16d
lcdcnt333 db 16d
lcdcnt444 db 16d
;Pres
flagcount111 dw 0
vals111 db 12 dup(0)
ctr111 dw 0
numstr db 16 dup(0)
q db 0
r db 0
divby dw 12d
updatenow db 00h
;------------------------start-inits-----------------------;
start: cli
a8253 equ 02000h
a8259 equ 02010h
a8255 equ 02020h
b8255 equ 02030h
8259_init:
;icw1
mov al, 00010011b ;ICW4 Needed (single 8259)
mov dx, a8259+00h ; dx has 1st address of 8259
out dx, al
;icw2
mov al, 10000000b ; dx has 2nd address of 8259
mov dx, a8259+02h ; 80h is generatedfor IR0 ie But-INT
out dx,al
;icw4
mov al, 00000011b ; rest follow 80h - 87h
out dx,al
;ocw1
mov al, 11111110b ; non buffered mode with AEOI enabled
out dx, al
; Initialising 8255A ...
8255_init:
mov al, 10000010b ;Cmnd Word - port a(o/p), !(prt B: i/p)
mov dx, a8255+06h
out dx, al
; !(Same as prev 8255) B - i/p C - for controlling ADC
mov al, 10000010b
mov dx, b8255+06h
out dx, al
8253_init: ; counter0 - sq. wave - binary i/p(2MHz-i/p)
;100Hz
mov al, 00110100b ; counter0 - sq. wave - binary i/p(2.5MHz-i/p)
mov dx, a8253+06h
out dx, al
mov al, 0A8h ; to divide by 25000d = 61A8h
mov dx, a8253+00h
out dx, al
mov al, 61h
mov dx, a8253+00h
out dx, al
;5min
mov al, 01110100b ; counter1 - Using mode 2 - every 5 min(low)
mov dx, a8253+06h ; must be inverted and given as interrupt
out dx, al
mov al, 30h
mov dx, a8253+02h ; divide by 30000 = 7530h
out dx, al
mov al, 75h
mov dx, a8253+02h
out dx, al
;1hr
mov al, 10010100b ; counter2 - Using mode 2 - every 1 hr(low)
mov dx, a8253+06h ; must be inverted and given as interrupt
out dx, al
mov al, 0ch
mov dx, a8253+04h ; to divide by 12d = 0ch
out dx, al
LCD_init:
lcden equ 80h
lcdrw equ 40h
lcdrs equ 20h
aclrb lcdrw
lcd_out 38h
lcd_out 0Eh
lcd_out 06h
lcd_clear
LCD_init1:
lcden1 equ 10h
lcdrw equ 40h
lcdrs equ 20h
aclrb lcdrw
lcd_out1 38h
lcd_out1 0Eh
lcd_out1 06h
lcd_clear
LCD_init11:
lcden11 equ 08h
lcdrw equ 40h
lcdrs equ 20h
aclrb lcdrw
lcd_out11 38h
lcd_out11 0Eh
lcd_out11 06h
lcd_clear
;------------------------start-code-------------------------;
; Perform Initial display ...
;turn on adc - temperature
mov thp,00h
int 81h
;wait for eoc
eocint08:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint08
eocint18:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint18
;Store Values - Temperature
mov thp,00h
int 83h
;Repeat process for Humi~ty
mov thp,01h
int 81h ; do same for humi~
;wait for eoc
eocint010:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint010
eocint101:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint101
mov thp,01h
int 83h
; FOR pressure
mov thp,11h
int 81h ; do same for humi
;wait for eoc
eocint0109:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint0109
eocint1018:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint1018
mov thp,11h
int 83h
mov thp,00h
int 82h
mov thp,01h
int 82h
mov thp,11h
int 82h
; --------END of initial display ---------------
;poll portb of a8255 forever
xinf:
;check if button is pressed using a flag stored in memory
mov al, updatenow
cmp al, 01h
jnz cont
mov updatenow, 00h
mov thp,00h ;FOR TEMPERATURE
int 81h ;turn on adc
;wait for eoc
eocint0:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint0
eocint1:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint1
mov thp,00h
int 83h
mov thp,01h
int 81h ; do same for humi
;wait for eoc
eocint00:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint00
eocint11:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint11
mov thp,01h
int 83h
mov thp,11h ; FOR PRESSURE
int 81h
;wait for eoc
eocint000:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint000
eocint111:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint111
mov thp,11h
int 83h
mov thp,00h
int 82h
mov thp,01h
int 82h
mov thp,11h
int 82h
;regular polling
cont:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 01h
jz butint
mov bl, al
and bl, 02h
jz fivemin
mov bl, al
and bl, 04h
jz onehr
mov bl, al
and bl, 08h
jz eocint
jmp xinf
;low logic detected. Wait for whole pulse
butint:
in al, dx
and al, 01h
jz butint
int 80h
jmp xinf
fivemin:
in al, dx
and al, 02h
jz fivemin
mov thp,00h
int 81h
eocint09:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint09
eocint19:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint19
mov thp,00h
int 83h
mov thp,01h
int 81h
;wait for eoc
eocint009:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint009
eocint119:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint119
mov thp,01h
int 83h
mov thp,11h
int 81h
;wait for eoc
eocint00999:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jnz eocint00999
eocint11999:
mov dx, a8255+02h
in al, dx
mov bl, al
and bl, 08h
jz eocint11999
mov thp,11h
int 83h
;Change value of no. of 5 min intervals taken during simulation
inc readyForHour
cmp readyForHour,02h
jnz donotcallonehour
mov thp,00h
int 82h ; Call the 1 hour interrupt
mov thp,01h
int 82h
mov thp,11h
int 82h
mov readyForHour,00h ; Reset the 12, 5-min interval count
donotcallonehour: jmp xinf
; Obsolete. Is not use as intrpt is called directly
onehr:
in al, dx
and al, 04h
jz onehr
int 82h
jmp xinf
eocint:
in al, dx
and al, 08h
jz eocint
mov thp,00h
int 83h
mov thp,01h
int 83h
mov thp,11h
int 83h
jmp xinf
jmp quit
;------------------------start-macros-----------------------;
pushall macro
push ax
push bx
push cx
push dx
push si
push di
endm
popall macro
pop di
pop si
pop dx
pop cx
pop bx
pop ax
endm
;set/clear pins since BSR was being strange
asetb macro mbit
pushall
mov al, mbit
mov bl, cstatea
or al, bl
mov dx, a8255+04h
out dx, al
mov bl, al
mov cstatea, bl
popall
endm
aclrb macro mbit
pushall
mov al, mbit
xor al, 0FFh
mov bl, cstatea
and al, bl
mov dx, a8255+04h
out dx, al
mov bl, al
mov cstatea, bl
popall
endm
adcst equ 01h
adcoe equ 02h
adcA equ 04h
adcB equ 08h
adcC equ 10h
adcALE equ 20h
bsetb macro mbit
pushall
mov al, mbit
mov bl, cstateb
or al, bl
mov dx, b8255+04h
out dx, al
mov bl, al
mov cstateb, bl
popall
endm
bclrb macro mbit
pushall
mov al, mbit
xor al, 0FFh
mov bl, cstateb
and al, bl
mov dx, b8255+04h
out dx, al
mov bl, al
mov cstateb, bl
popall
endm
lcd_out macro dat
aclrb lcdrs
pushall
mov al, dat
mov dx, a8255+00h
out dx, al
asetb lcden
aclrb lcden
call delay_20ms
popall
endm
lcd_out1 macro dat
aclrb lcdrs
pushall
mov al, dat
mov dx, a8255+00h
out dx, al
asetb lcden1
aclrb lcden1
call delay_20ms
popall
endm
lcd_out11 macro dat
aclrb lcdrs
pushall
mov al, dat
mov dx, a8255+00h
out dx, al
asetb lcden11
aclrb lcden11
call delay_20ms
popall
endm
lcd_write_char macro dat
asetb lcdrs
pushall
mov al, dat
mov dx, a8255+00h
out dx, al
asetb lcden
aclrb lcden
;call delay_20ms
popall
endm
lcd_write_char1 macro dat
asetb lcdrs
pushall
mov al, dat
mov dx, a8255+00h
out dx, al
asetb lcden1
aclrb lcden1
;call delay_20ms
popall
endm
lcd_write_char11 macro dat
asetb lcdrs
pushall
mov al, dat
mov dx, a8255+00h
out dx, al
asetb lcden11
aclrb lcden11
;call delay_20ms
popall
endm
lcd_clear macro
lcd_out 01h
endm
;division routine since div was acting strange
wow_divide macro divi
pushall
mov cx, 00
mov bx, divi
loopy:
sub ax, bx
inc cx
cmp ax, 0
jge loopy
dec cx
add ax, bx
mov r, al
mov q, cl
popall
endm
wow_divide1 macro divi
pushall
mov cx, 00
mov bx, divi
loopy1:
sub ax, bx
inc cx
cmp ax, 0
jge loopy1
dec cx
add ax, bx
mov r, al
mov q, cl
popall
endm
wow_divide2 macro divi
pushall
mov cx, 00
mov bx, divi
loopy2:
sub ax, bx
inc cx
cmp ax, 0
jge loopy2
dec cx
add ax, bx
mov r, al
mov q, cl
popall
endm
;------------------------Start-Procedure Defs-----------------------;
;delay proc: just a huge loop
delay_20ms proc near
mov dx, 10
r1: mov cx, 2353
r2: loop r2
dec dx
jne r1
ret
delay_20ms endp
;write a string in memory to LCD
write_string proc near
lea si, lcdln1
mov cl, lcdcnt1
l1: lcd_write_char [si]
inc si
loop l1
ret
write_string endp
;write a string in memory to LCD
write_string1 proc near
lea si, lcdln11
mov cl, lcdcnt11
l11: lcd_write_char1 [si]
inc si
loop l11
ret
write_string1 endp
;write a string in memory to LCD
write_string11 proc near
lea si, lcdln111
mov cl, lcdcnt111
l111: lcd_write_char11 [si]
inc si
loop l111
ret
write_string11 endp
;-----------------------------------------------
;Scale Humidity
convert_humi proc near
;get it to scale (0-99%)
mov ah, 00h
mov al, q
mov bl, 99d
mul bl
mov bl, 0FFh ;FFh is the max o/p from ADC
div bl
;split the numbers
mov ah, 00h
mov bl, 10d
div bl
lea si, numstr ;Load appropriate ascii value(quo)
add ax, 3030h
mov [si], al
mov [si+1], ah
mov al, r
mov ah, 00h
mov bx, 100d
mul bx
mov bl, 12d
div bl
mov ah, 00h
mov bl, 10d
div bl
add ax, 3030h
mov [si+2], al ;Load appropriate ascii value(rem)
mov [si+3], ah
ret
convert_humi endp
; Scaling fns ----------------------------------------------
;Scale temperature
convert_temp proc near
;get it to scale (5-50 C)
mov ah, 00h
mov al, q
mov bl, 45d
mul bl
mov bl, 0FFh
div bl
add ax, 05h
;split the numbers
mov ah, 00h
mov bl, 10d
div bl
lea si, numstr
add ax, 3030h
mov [si], al
mov [si+1], ah
mov al, r
mov ah, 00h
mov bx, 100d
mul bx
mov bl, 12d
div bl
mov ah, 00h
mov bl, 10d
div bl
add ax, 3030h
mov [si+2], al
mov [si+3], ah
ret
convert_temp endp
;--------------------------------------------------------------------------
;Scale Pressure
convert_pres proc near
;get it to scale (0-2 Bar)
mov ah, 00h
mov al, q
mov bl, 02d
mul bl
mov bl, 0FFh ;FFh is the max o/p from ADC
div bl
;split the numbers
mov ah, 00h
mov bl, 10d
div bl
lea si, numstr ;Load appropriate ascii value(quo)
add ax, 3030h
mov [si], al
mov [si+1], ah
mov al, r
mov ah, 00h
mov bx, 100d
mul bx
mov bl, 12d
div bl
mov ah, 00h
mov bl, 10d
div bl
add ax, 3030h
mov [si+2], al ;Load appropriate ascii value(rem)
mov [si+3], ah
ret
convert_pres endp
;output ascii equiv values on LCD from mem location
num_out proc near
lcd_out 01h
call write_string
mov al, numstr
mov ah, numstr+1
lcd_write_char al
lcd_write_char ah
lcd_write_char '.'
mov al, numstr+2
mov ah, numstr+3
lcd_write_char al
lcd_write_char ah
ret
num_out endp
;output ascii equiv values on LCD from mem location
num_out1 proc near