samhk
Joined: 27 Nov 2005 Posts: 14
|
Posted: Sun Jun 11, 2006 9:27 am Post subject: why the result from simulator different from the acutal |
|
|
can any one tell me why the following program work ok when load into the controller, however the simulator in bascome can not generate the correct result
'
' BASCOM-8051 template
'
$map
$noramclear
$crystal = 11059200
$regfile = "reg51.dat"
Const Cr = 13
On Serial Serial_srv Nosave
Dim Ser_buf(16) As Byte
Dim Txd_flag As Bit
Dim Rxd_flag As Bit
Main:
' sp=&h30
Gosub Serial_init
enable interrupts
Restore Msg1
Gosub Send_to_ser_buf
Reset Txd_flag
Sbuf = Ser_buf(1)
Bitwait Txd_flag , Set
End
Serial_init:
' initial timer 1 for serial port
' mode 9600-8-N-1
Config Timer1 = Timer , Gate = Internal , Mode = 2
counter1=&hFDFD
scon=&b01010000
' smod =0
reset pcon.7
' tmp=pcon or &b10000000
' pcon=tmp
'clr et1
reset ie.3
'setb tr1
set tcon.6
'clr ri
reset scon.0
'clr ti
reset scon.1
'setb es
set ie.4
' erase tmp
Return
Serial_srv:
$asm
' check if TI is set for interrupe
jnb scon.1,serial_srv_1
' *** TXD ***
clr scon.1
push psw
push acc
mov a,r0
push acc
' copy the address of buffer in to r0
mov r0,#{ser_buf-1}
mov a,@r0
add a,#{ser_buf-1}
mov r0,a
mov a,@r0
mov sbuf,a
inc {ser_buf-1}
cjne a,#{cr},serial_srv_2
setb {txd_flag}
mov {ser_buf},#2
Serial_srv_2:
pop acc
mov r0,a
pop acc
pop psw
ajmp serial_srv_3
Serial_srv_1:
' *** RXD ***
clr scon.0
serial_srv_3:
$end Asm
return
Send_to_ser_buf:
Dim Tmp1 As Byte
Dim Tmp2 As Byte
Tmp2 = 1
Ser_buf(0) = 2
Read Tmp1
Do
Ser_buf(tmp2) = Tmp1
Incr Tmp2
Read Tmp1
Loop Until Tmp1 = 0
Ser_buf(tmp2) = Cr
Erase Tmp2
Erase Tmp1
return
Msg1:
Data "!Hello World" |
|