-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.asm
168 lines (148 loc) · 4.11 KB
/
a.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
ORG 00H //Start the program
;angles
MOV R1,#18H ;DECLINATION ANGLE WHEN THE DAY OF YEAR IS 103
MOV R6,#24H ;zenith angle of 36 degree with the perpendicular as the reference at 10am
MOV R7,#46H ;Azimuthal angle of 70 degree from north as point of reference
;hour angle calc
MOV R3,#0CH
MOV A,R3
SUBB A,#0CH
MOV B,#0CH
DIV AB
MOV R0,A ;hour angle
;zenith angle calculation
MOV R3,#0DH ;LATITUDE 13 degree for vellore
MOV A,R3
MOV B,R1
MUL AB
MOV R2,A
MOV A,#0DH
MOV B,R1
MUL AB
MOV B,R0
MUL AB
MOV R3,A
MOV A,R2
ADD A,R3
MOV R2,A
JMP ZEN
;azimuthal angle calculation
MOV R3,#0DH
MOV A,R3
MOV B,R1
MUL AB
MOV B,R0
MUL AB
MOV R4,A
MOV A,#0DH
MOV B,R1
MUL AB
ADD A,R4
MOV R4,A
JMP AZI
;Code to move motor for zenith angle
;The motor moves from 0 degree (start of day)
;to the calculated angle at 10am
;to 180 degree at the end of the day
;and this is repeated in a loop
ZEN:
MOV TMOD, #01H ;using Timer 0 in Mode 1
LCALL zero_degrees ;Function to move to position = 0 deg
LCALL delay ;Function to create a delay of 1 sec
LCALL req ;Function to move to the zenith angle position of sun
LCALL delay
LCALL one_eighty_degrees ;Function to move to position = 180 deg
LCALL delay ;Function to create a delay of 1 sec
RET
zero_degrees: //To create a pulse of 1ms
MOV TH0, #0FCH //(FFFF - 03E7 + 1)H = (FC19)H
MOV TL0, #19H //equal TO (1000)D = 1ms
SETB P2.0 ;Make P2.0 HIGH
SETB TR0 ;Start the timer 0
WAIT1:JNB TF0, WAIT1 ;Wait till the TF0 flag is set
CLR P2.0 ;Make P2.0 LOW
CLR TF0 ;Clear the flag manually
CLR TR0 ;Stop the timer 0
RET
;a pulse of 1.2ms is required to move the servo motor to the zenith angle
req: //To create a pulse of 1.2ms
MOV TH0, #0FBH //(FFFF - 04B0 + 1)H = (FB51)H
MOV TL0, #51H //equal TO (1200)D = 1.2ms
SETB P2.0 ;Make P2.0 HIGH
SETB TR0 ;Start the timer 0
WAIT2:JNB TF0, WAIT2 ;Wait till the TF0 flag is set
CLR P2.0 ;Make P2.0 LOW
CLR TF0 ;Clear the flag manually
CLR TR0 ;Stop the timer 0
RET
one_eighty_degrees: //To create a pulse of 2ms
MOV TH0, #0F8H //(FFFF - 07CF + 1)H = (F831)H
MOV TL0, #31H //equal to (2000)D = 2ms
SETB P2.0 ;Make P2.0 HIGH
SETB TR0 ;Start the timer 0
WAIT4:JNB TF0, WAIT4 ;Wait till the TF0 flag is set
CLR P2.0 ;Make P2.0 LOW
CLR TF0 ;Clear the flag manually
CLR TR0 ;Stop the timer 0
RET
delay: //To create a delay of 1sec
MOV R4,#64H ;100us * 100us * 100us = 1s
LOOP1:MOV R3,#64H
LOOP2:MOV R2,#64H
LOOP3:DJNZ R2,LOOP3
DJNZ R3,LOOP2
DJNZ R4,LOOP1
;Code to move motor for azimuth angle
;The motor moves from 0 degree (start of day)
;to the calculated angle for day 103
;to 180 degree at the end of the day
;and this is repeated in a loop
AZI:
MOV TMOD, #01H ;using Timer 0 in Mode 1
LCALL zero_degrees1 ;Function to move to position = 0 deg
LCALL delay1 ;Function to create a delay of 1 sec
LCALL req1 ;Function to move to the azimuth angle of sun
LCALL delay1
LCALL one_eighty_degrees1 ;Function to move to position = 180 deg
LCALL delay1 ;Function to create a delay of 1 sec
RET
zero_degrees1: //To create a pulse of 1ms
MOV TH0, #0FCH //(FFFF - 03E7 + 1)H = (FC19)H
MOV TL0, #19H //equal TO (1000)D = 1ms
SETB P2.1 ;Make P2.0 HIGH
SETB TR0 ;Start the timer 0
WAIT11:JNB TF0, WAIT11 ;Wait till the TF0 flag is set
CLR P2.1 ;Make P2.0 LOW
CLR TF0 ;Clear the flag manually
CLR TR0 ;Stop the timer 0
RET
;a pulse of 1.39ms is required to move the servo motor to the azimuth angle
req1: //To create a pulse of 1.39ms
MOV TH0, #0FAH //(FFFF - 056E + 1)H = (FA93)H
MOV TL0, #93H //equal TO (1390)D = 1.39ms
SETB P2.1 ;Make P2.0 HIGH
SETB TR0 ;Start the timer 0
WAIT22:JNB TF0, WAIT22 ;Wait till the TF0 flag is set
CLR P2.1 ;Make P2.0 LOW
CLR TF0 ;Clear the flag manually
CLR TR0 ;Stop the timer 0
RET
one_eighty_degrees1: //To create a pulse of 2ms
MOV TH0, #0F8H //(FFFF - 07CF + 1)H = (F831)H
MOV TL0, #31H //equal to (2000)D = 2ms
SETB P2.1 ;Make P2.0 HIGH
SETB TR0 ;Start the timer 0
WAIT44:JNB TF0, WAIT44 ;Wait till the TF0 flag is set
CLR P2.1 ;Make P2.0 LOW
CLR TF0 ;Clear the flag manually
CLR TR0 ;Stop the timer 0
RET
delay1: //To create a delay of 1sec
MOV R4,#64H ;100us * 100us * 100us = 1s
LOOP11:MOV R3,#64H
LOOP22:MOV R2,#64H
LOOP33:DJNZ R2,LOOP33
DJNZ R3,LOOP22
DJNZ R4,LOOP11
RET
END