help pl

Thread Starter

parul

Joined Feb 28, 2007
1
I am working on project in which sensor senses the temp and sends to PC
In my interface part I am working on 89c2051 microcontroller.I want to check this coding. so please check it for me.


org 00h

dlycnt equ 92h
rsreg equ 14h
chcount equ 30h
ch1meas equ 31h
ch2meas equ 32h
ch3meas equ 33h
ch4meas equ 34h
checksumh equ 35h
checksuml equ 36h

timedlyreg equ 38h
databyte1 equ 40h

rsdt equ 00h
timeout equ 01h

ajmp init

org 0023h
clr ie.4
clr ri
ljmp rs232rec
reti

init:
clr p3.4
acall fixdly
clr p3.3
mov ip,#04h
mov sp,#66h
setb ie.7
mov tmod,#00100001b
mov scon,#50h
mov th1,#0f3h
setb tr1
acall fixdly
see_con:
mov a,#41h
acall tserial
acall starttimer
clr timeout
setb rsdt
clr ri
wait_rs:
jb timeout,see_con
jb rsdt,wait_rs
clr tr0
mov a,r7
cjne a,#43h,see_con
mov chcount,#00h
adcscan:
clr tr0
mov r1,#ch1meas
mov chcount,#00h
nextch:
mov a,chcount
jnz secondch
clr p3.7
clr p3.2
sjmp getdata
secondch:
cjne a,#01h,thirdch
clr p3.7
setb p3.2
sjmp getdata
thirdch:
cjne a,#02h,forthch
setb p3.7
clr p3.2

sjmp getdata
forthch:
cjne a,#02h,forthch
setb p3.7
clr p3.2
sjmp getdata
getdata:
acall dly5
setb p3.3
nop
setb p3.4
nop
nop
clr p3.4
clr p3.3
acall starttimer
acall dly5
adhere:
jb timeout,adc_error
jnb p3.5,adhere
clr tr0
nop
nop
nop
nop
mov a,p1
mov @r1,a
inc r1
inc chcount
sjmp nextch
scanover:
mov checksumh,#00h
mov checksuml,#00h
mov r1,ch1meas
mov r3,#04h
checkloop:
mov a,@r1
add a,checksuml
mov checksuml,a
jnc no_carry
inc checksumh
no_carry:
inc r1
djnz r3,checkloop
trnsmission:
mov a,#53h
acall tserial
mov r3,#06h
mov r1,#ch1meas
transloop:
mov a,@r1
acall hexasc
mov a,r6
acall tserial
mov a,r7
acall tserial
;acall tserial
inc r1
djnz r3,transloop
mov a,#54h
acall tserial
adc_error:
mov a,#51h
acall tserial
mov a,32h
acall tserial
ajmp adcscan
tserial:
mov sbuf,a
tx:
jnb ti,tx
clr ti
ret
rs232rec:
mov a,sbuf
mov r7,a
clr rsdt
reti
smdly:
mov a,#01h
push 00h
sjmp dlysm1
fixdly:
mov a,#01h
msdly:
push 00h
dly3:
mov b,#0ffh

dlysm1:
mov r0,#dlycnt
dly2:
djnz r0,dly2
nop
djnz b,dlysm1
djnz a,dly3
pop 00h
ret
starttimer:
mov timedlyreg,#50h
clr timeout
setb ie.1
setb tr0
ret
timeoser:
djnz timedlyreg,not_complete
setb timeout
clr tr0
clr ie.1
not_complete:
reti
dly5:
mov b,#08h
dly55:
djnz b,dly55
ret
hexasc:
mov r6,a
anl a,#0fh
acall direct
mov r7,a
mov a,r6
anl a,#f0h
swap a
acall direct
xch a,r6
ret
direct:
add a,#30h
da a
jnb acc.6,hex1
inc a
hex1:
ret
end


thanx
 

beck

Joined Nov 27, 2006
26
Hi Parul,
Use comments , without comments it gets very difficult to understand what you are trying to do.
you can use 8051 simulators (some are freewares) to see if your code is working or not. thats the best way.
 

Arm_n_Legs

Joined Mar 7, 2007
186
Without reference to a circuit, the code is meaning? For example, what is the purpose of those port control instructions like SETB P3.4 in your program does? We know it set the port to "1", but for what purpose?

~cheers~
 

Dave

Joined Nov 17, 2003
6,969
Without reference to a circuit, the code is meaning? For example, what is the purpose of those port control instructions like SETB P3.4 in your program does? We know it set the port to "1", but for what purpose?

~cheers~
I think that is why beck suggested use comments -code is barely readable otherwise.

Btw, Welcome to All About Circuits!

Dave
 
Top