mike20200
- 31st August 2007, 00:00
Im using PIC16f877A with 20Mhz crystal
and my code is below
================================================== =================
DEFINE OSC 20
Name var BYTE[8]
'To start the progam hit a CR
cmd var byte
CR con 13
CLear
PAUSE 200
main:
Serout2 PORTC.6, $BC,["Option"]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
Serout2 PORTC.6, $BC,["1:START",10,13]
pause 200
Serout2 PORTC.6, $BC,["2: Enter Name",10,13]
pause 200
Serout2 PORTC.6, $BC,["3: Display Name",10,13]
pause 200
Serout2 PORTC.6, $BC,["4: Shut Down",10,13]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
goto getinput
getInput:
Serout2 PORTC.6, $BC,["Choose your Option",10,13]
pause 200
serin2 PORTC.7, $BC,[dec1 cmd]
if cmd = "0" Then
GOSUB bad
endif
if cmd = "1" Then
GOSUB dosleep
endif
if cmd = "2" Then
GOSUB doend
endif
if cmd = "3" Then
GOSUB getname
endif
if cmd = "4" Then
GOSUB dispname
endif
bad: Serout2 PORTC.6, $BC,[10,13,"Invalid Command",10,13]
pause 200
return
dosleep: Serout2 PORTC.6, $BC,[10,13,"Night Night..",10,13]
pause 200
return
doend: Serout2 PORTC.6, $BC,[10,13,"BYE BYE",10,13]
pause 200
Return
'---------------------------------------------------------------------
'Get the users name
'---------------------------------------------------------------------
getname: Serout2 PORTC.6, $BC,["What is your name? "]
pause 200
'Read in users name here. Maximum of 30 characters or CR
serin2 PORTC.7, $BC,[str name\30\13]
pause 200
'Display name until 30 characteres or end of data
Serout2 PORTC.6, $BC,["Hello ",str name \30]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
return
'-----------------------------------------------------------------
'Display the users name
'-----------------------------------------------------------------
dispname: Serout2 PORTC.6, $BC,["Hello ",str name \30]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
return
end
================================================== ================
I run it with Hyperterminal to test my code. what i get is this infinity non stop loop:
================================================== ================
Choose your Option
Option
1:START
2: Enter Name
3: Display Name
4: Shut Down
Choose your Option
Option
1:START
2: Enter Name
3: Display Name
4: Shut Down
Choose your Option
Option
================================================== ================
How to make the loop stop n to key in what i wan... Pls help me
and my code is below
================================================== =================
DEFINE OSC 20
Name var BYTE[8]
'To start the progam hit a CR
cmd var byte
CR con 13
CLear
PAUSE 200
main:
Serout2 PORTC.6, $BC,["Option"]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
Serout2 PORTC.6, $BC,["1:START",10,13]
pause 200
Serout2 PORTC.6, $BC,["2: Enter Name",10,13]
pause 200
Serout2 PORTC.6, $BC,["3: Display Name",10,13]
pause 200
Serout2 PORTC.6, $BC,["4: Shut Down",10,13]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
goto getinput
getInput:
Serout2 PORTC.6, $BC,["Choose your Option",10,13]
pause 200
serin2 PORTC.7, $BC,[dec1 cmd]
if cmd = "0" Then
GOSUB bad
endif
if cmd = "1" Then
GOSUB dosleep
endif
if cmd = "2" Then
GOSUB doend
endif
if cmd = "3" Then
GOSUB getname
endif
if cmd = "4" Then
GOSUB dispname
endif
bad: Serout2 PORTC.6, $BC,[10,13,"Invalid Command",10,13]
pause 200
return
dosleep: Serout2 PORTC.6, $BC,[10,13,"Night Night..",10,13]
pause 200
return
doend: Serout2 PORTC.6, $BC,[10,13,"BYE BYE",10,13]
pause 200
Return
'---------------------------------------------------------------------
'Get the users name
'---------------------------------------------------------------------
getname: Serout2 PORTC.6, $BC,["What is your name? "]
pause 200
'Read in users name here. Maximum of 30 characters or CR
serin2 PORTC.7, $BC,[str name\30\13]
pause 200
'Display name until 30 characteres or end of data
Serout2 PORTC.6, $BC,["Hello ",str name \30]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
return
'-----------------------------------------------------------------
'Display the users name
'-----------------------------------------------------------------
dispname: Serout2 PORTC.6, $BC,["Hello ",str name \30]
pause 200
Serout2 PORTC.6, $BC,[10,13]
pause 200
return
end
================================================== ================
I run it with Hyperterminal to test my code. what i get is this infinity non stop loop:
================================================== ================
Choose your Option
Option
1:START
2: Enter Name
3: Display Name
4: Shut Down
Choose your Option
Option
1:START
2: Enter Name
3: Display Name
4: Shut Down
Choose your Option
Option
================================================== ================
How to make the loop stop n to key in what i wan... Pls help me