Counter programing in 8051 using asm language

Status
Not open for further replies.
yup now i tried it on compiler then at setb 08h 21h memory address was set.
but here when i executed
Code:
setb 01h
setb 02h
then, the 20h location took 06h value in it....
 

Right... Binary 110 is decimal/hex 6.
 

do you know anything about solar panels???
I have been searching about them why is the effeciency of solar panels so low... What is the reason but,most of the websites just say that research is being conducted and the effeciency is attempted to make around 45-47% i have my own reasons to say why solar is not that effecient but i want someone to evaluate my points

- - - Updated - - -

Right... Binary 110 is decimal/hex 6.
here 20h has its 8bits say form 0 to 7.
when i write setb 01h and setb 03h that means 0th bit is set and 1st bit is set right??? then binary will be 011=3 in hex right??
 


Code ASM - [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
$MOD51
ORG 0000H
mov r0,#00H
mov r1,#00H
 
MOV P1,A
SETB P2.3
SETB P2.4
clr p2.6
LCALL WAITING;
LOP:
LOOP1:
 
MOV A,P2
RLC A
RLC A
RLC A
RLC A
JC CHECK;
cjne r0,#09,CLOSE
 
mov r0,#00H
 CLOSE:inc r0;
 
LCALL RECHARGE;
CHECK:
ACALL DELAY1
MOV A,P2
RLC A
RLC A
RLC A
RLC A
RLC A
Jc OVER1;
DEC r0;
cjne r0,#00,Open
clr p2.6
Open:ACALL OVER; 
OVER1:
JC LOP;
 
RECHARGE:
MOV A,#38H
ACALL COMNWRT
ACALL DELAYY
MOV A,#0EH
ACALL COMNWRT
ACALL DELAYY
MOV A,#01H
ACALL COMNWRT
ACALL DELAYY
MOV A,#06H
ACALL COMNWRT
ACALL DELAYY
MOV A,#81H
ACALL COMNWRT
ACALL DELAYY
MOV A,#'U'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'P'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'U'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'N'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'T'
ACALL DATAWRT
ACALL DELAYY
MOV A,#':'
ACALL DATAWRT
ACALL DELAYY
MOV A,#20H
ACALL DATAWRT
ACALL DELAYY
MOV A,r0
orl a,#30h
ACALL DATAWRT
ACALL DELAYY
SETB P2.6
ACALL LOOP1
RET
 
OVER:
MOV A,#38H
ACALL COMNWRT
ACALL DELAYY
MOV A,#0EH
ACALL COMNWRT
ACALL DELAYY
MOV A,#01H
ACALL COMNWRT
ACALL DELAYY
MOV A,#06H
ACALL COMNWRT
ACALL DELAYY
MOV A,#81H
ACALL COMNWRT
ACALL DELAYY
MOV A,#0c2H
ACALL COMNWRT
ACALL DELAYY
MOV A,#'D'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'W'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'N'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'C'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'O'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'U'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'N'
ACALL DATAWRT
ACALL DELAYY
MOV A,#'T'
ACALL DATAWRT
ACALL DELAYY
MOV A,#':'
ACALL DATAWRT
ACALL DELAYY
MOV A,#20H
ACALL DATAWRT
ACALL DELAYY
MOV A,r0
orl a,#30h
ACALL DATAWRT
ACALL DELAYY
ACALL LOOP1;
ret
 
WAITING:
MOV A,#38H
ACALL COMNWRT
ACALL DELAYY
MOV A,#0FH
ACALL COMNWRT
ACALL DELAYY
MOV A,#01H
ACALL COMNWRT
ACALL DELAYY
MOV A,#80H
ACALL COMNWRT
ACALL DELAYY
MOV A,#"I"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"N"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"T"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"E"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"L"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"L"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"I"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"G"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"E"
ACALL DATAWRT
MOV A,#"N"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"T"
ACALL DATAWRT
ACALL DELAYY
MOV A,#0c2H
ACALL COMNWRT
ACALL DELAYY
MOV A,#"V"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"I"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"S"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"I"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"T"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"O"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"R"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"C"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"O"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"U"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"N"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"T"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"E"
ACALL DATAWRT
ACALL DELAYY
MOV A,#"R"
ACALL DATAWRT
ACALL DELAYY
ret
 
COMNWRT: MOV P1,A
CLR P3.5
SETB P3.4
CLR P3.4
RET
 
DATAWRT: MOV P1,A
SETB P3.5
SETB P3.4
CLR P3.4
RET
 
DELAY1: MOV R3,#50
HERE22: MOV R4,#225
HEREe: DJNZ R4,HEREe
DJNZ R3,HERE22
RET
DELAYy: MOV TMOD,#10H
MOV R3,#01
Z33:MOV TL1,#08H;
MOV TH1,#01H;
SETB TR1
BACK33: JNB TF1,BACK33
CLR TR1
CLR TF1
DJNZ R3,Z33
RET
 
 
DELAY: MOV TMOD,#10H
MOV R3,#25D
Z334:MOV TL1,#08H;
MOV TH1,#01H;
SETB TR1
BACK334: JNB TF1,BACK334
CLR TR1
CLR TF1
DJNZ R3,Z334
RET
 
 
END

 
Last edited by a moderator:

hey did you see this engg classes videos on you tube:https://www.youtube.com/watch?v=IT3kqte0PXo
in this at 3:10mintue he is giving second example that is bcd addition of 34 and 37 ok let me do it here:
in decimal: binary equivalent:
34__________________________________00110100
+37_________________________________ 00110111
=71(this answer is in decimal)__________= 01101011 =6b
so 71-6b=06(difference) and hence AUXILLARY CARRY FLAG IS AFFECTED.
BUT..6b is in hex and 71 is in decimal then how did he find differnce like that? Is his explaination is wrong or is it that my interpretation is wrong??:-(
 
Last edited:

Here, 34 and 37 are hex values 34H & 37H. Their decimal are 52 & 55. Use windows calculator to convert between hex, dec, oct & bin...
 

no but in the video he himself said that 34 & 37 are two decimal numbers.
and now if i add 52+55=107(in decimal) and 6bh=107d so there is no difference of ""6"" generated..Where is the confusion?
 

BCD is really confusing... :thinker: What they are doing is considering every decimal digits independently and converting them to binary. After adding 34 & 37, AC is not set. The result 6B is not a decimal number because dec is 0,1,...,9. 'B' is undefined.
I don't know about BCD so much. I guess since a processor can take a single digit number at a time as an input and also in its binary form, so they all are evaluated nibble wise. BCD theory says dec numbers are mostly converted to 4 bit binary (0 to 9). After an arithmetic operation, they are being verified if every nibbles comes under the following table:
0000________0
0001________1
0010________2
0011________3
0100________4
0101________5
0110________6
0111________7
1000________8
1001________9

If after binary addition any nibble or number comes with different value, say 1100, then ofcourse its not a single digit no. In dec its 12. But we cannot replace a single digit with 12. So in hex, its C. Maybe that's why it was written in that way. 'C' can be a single letter which can be used to replace 12. Its just a matter of representation.
Adding 34 & 37 yields 71, or simply 6 and 11. Its obviously not 611. The second digit '1' from last is added to 6 as a carry and the answer becomes (6+1) and 1 i.e., 71...
 

ya you are right any digit 0-9 well known number system to us can be represented in nibbles and as in BCD ex:56 for this number in binary we write binary equivalent of 5 seperately and binary equivalent of 6 seperately this reduces a lot of hardware complexity so BCD IS USEFUL
Code:
org 0000h
main:
mov a,#94
mov r0,#39
add a,r0
da a
sjmp main
end
i have tried this code & the resultant of the accumulator register inspite of using DA INSTRUCTIION OR WITHOUT USING remains same.
 

DA instruction is not needed for addition. It is needed for MUL, DIV and possibly for SUB.... You do a divide and check the result.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…