|

楼主 |
发表于 2014-4-19 12:24:32
|
显示全部楼层
'(
Function : Main Function
Date : 2013 / 6 / 01
Rev.31
')
_main:
'/* date time vars */
Dim Strdate As String * 10
Dim Strtime As String * 8
Dim Strmin As String * 2
Dim Strhour As String * 2
Dim Intyear As Integer
Dim Intmonth As Integer
Dim Intday As Integer
'/* temp vars */
Dim Oldhour As String * 2
Dim Strtemp As String * 2
Dim Intfix As Integer
'/* system state vars */
Dim Intcsq As Integer
Dim Bitri As Bit 'ring symbol
Dim Strtelephonenumber As String * 16 , Strinnumber As String * 16 , Strkeynumber As String * 16
Do
'/* Get data from module */
Getline Str_uart
'/////////////////////////////////////////////////////////////
' State Machine
'
' +STATE Module
'/////////////////////////////////////////////////////////////
If Str_uart = "+ZIND:8" Then
_lamp = 0
Cls : Locate 2 , 1 : Lcd "Module is full."
Call Setupmodule
Module_state = 1
End If
If Str_uart = "+ZIND:0" Or Str_uart = "+ZIND:1" Then
Call Setupmodule
If Str_uart = "+ZIND:1" Then Installed_uim = 1 : Waitms 1000
Cls : Locate 1 , 1 : Lcd "Load data..."
If Installed_uim = 1 Then
Locate 2 , 13 : Lcd "UIM"
End If
Module_state = 2 : Old_state = 2
_lamp = 1
Readeeprom Setting_show_temp , 0
If Setting_show_temp <> "T" And Setting_show_temp <> "F" And Setting_show_temp <> "A" Then Setting_show_temp = "T"
Enable Int0 'Infra-red input
End If
If Left(str_uart , 8) = "+ZCCNT:0" Then
Locate 2 , 1 : Lcd "### "
End If
If Left(str_uart , 6) = "+ZCEND" Then
Cls : Locate 1 , 1 : Lcd "# Disconnected #" : Waitms 1000
Strinnumber = ""
Module_state = Old_state
End If
If _ri = 0 And Module_state <> 0 And Module_state <> 1 Then
Bitri = 1
Else
Bitri = 0
End If
If Left(str_uart , 5) = "RING:" Then
Intlen = Len(str_uart) - 5
Strinnumber = Right(str_uart , Intlen)
Bitri = 1
End If
If Bitri = 1 Then
Locate 1 , 1 : Lcd "### RING : "
Locate 2 , 1 : Lcd Strinnumber ; " "
Module_state = 6
End If
If Left(str_uart , 10) = "NO CARRIER" Then
Cls : Locate 1 , 1 : Lcd "NO CARRIER" : Waitms 1000
End If
If Left(str_uart , 9) = "NO ANSWER" Then
Cls : Locate 1 , 1 : Lcd "NO ANSWER" : Waitms 1000
End If
'///////////////////////////////////////////////////////////////
' State Machine
'
' +STATE Clock
'///////////////////////////////////////////////////////////////
If Module_state = -1 Then Goto _closemodule
'/* Draw Callin number */
If Module_state = 5 Then
Locate 1 , 1 : Lcd Strkeynumber ; " "
Locate 2 , 5 : Lcd Strtelephonenumber
End If
'/* Draw Dial */
If Module_state = 4 Then
Locate 1 , 1 : Lcd "Key number: "
Locate 2 , 1 : Lcd Strtelephonenumber ; " "
End If
'/* Draw Mark */
Select Case Draw_state
Case 1
Locate 2 , 1 : Lcd ">>> "
Draw_state = 0
End Select
If Module_state = 5 Or Module_state = 6 Then Goto Exit0
If Module_state = 2 Then Print "AT+CCLK?"
If Module_state = 3 Then Print "AT+CSQ?"
If Left(str_uart , 5) = "+CCLK" Then
'/* cut string */
Intlen = Len(str_uart) - 8 : Str_uart = Right(str_uart , Intlen)
Intlen = Intlen - 5 : Str_uart = Left(str_uart , Intlen )
'/* get date time */
Strdate = "20" + Left(str_uart , 8)
Strtime = Right(str_uart , 8)
Strhour = Left(strtime , 2)
Strmin = Mid(strtime , 4 , 2)
'/* check data */
If Mid(strdate , 5 , 1) <> "/" Then Goto Exit0
If Mid(strdate , 8 , 1) <> "/" Then Goto Exit0
If Mid(strtime , 3 , 1) <> ":" Then Goto Exit0
If Mid(strtime , 6 , 1) <> ":" Then Goto Exit0
'/* the whole point timekeeping */
If Oldhour <> Strhour Then Print "AT+ZDTMF=1," ; Chr(34) ; "*" ; Chr(34) ; ",4,5" : Oldhour = Strhour 'Beep
Select Case Setting_show_temp
'/* full mode */
Case "T"
Strtemp = Mid(strdate , 3 , 2) : Intyear = Val(strtemp)
Strtemp = Mid(strdate , 6 , 2) : Intmonth = Val(strtemp)
Strtemp = Mid(strdate , 9 , 2) : Intday = Val(strtemp)
Locate 1 , 1 : Lcd Strdate ; " "
Locate 2 , 1 : Lcd Strtime ; " "
Call Getweek(intyear , Intmonth , Intday)
Call Gettemperature()
'/* simple mode */
Case "F"
Locate 1 , 1 : Lcd Strdate ; " "
Locate 2 , 9 : Lcd Strtime ; " "
Locate 2 , 1 : Lcd " "
'/* large print mode */
Case "A"
Intfix = Val(strhour)
If Intfix > 12 Then
Intfix = Intfix - 12
Strhour = Str(intfix)
End If
If Len(strhour) = 1 Then Strhour = "0" + Strhour
Call Clarline(2)
'/* Draw hour number */
If Strhour <> "11" Then
Strtemp = Mid(strhour , 1 , 1) : Intlen = Val(strtemp)
If Intlen = 0 Then
Call Clarline(1) : Call Clarline(2)
Else
Call Shownumber(1 , Intlen)
End If
Strtemp = Mid(strhour , 2 , 1) : Intlen = Val(strtemp) : Call Shownumber(3 , Intlen)
If Intlen = 1 Then Call Clarline(5)
Else
Strtemp = Mid(strhour , 1 , 1) : Intlen = Val(strtemp) : Call Shownumber(3 , Intlen)
Strtemp = Mid(strhour , 2 , 1) : Intlen = Val(strtemp) : Call Shownumber(5 , Intlen)
Call Clarline(1)
Call Clarline(2)
If Strhour = "11" Then Call Clarline(12)
End If
Call Clarline(6)
Call Clarline(8)
Call Clarline(16)
'/* Draw point */
Locate 1 , 7 : Lcd Chr(0)
Locate 2 , 7 : Lcd Chr(0)
'/* Draw Min number */
Strtemp = Mid(strmin , 1 , 1) : Intlen0 = Val(strtemp) : Call Shownumber(9 , Intlen0)
Strtemp = Mid(strmin , 2 , 1) : Intlen = Val(strtemp)
If Intlen0 = 1 Then
Call Shownumber(11 , Intlen)
If Intlen = 1 Then
Call Clarline(12)
Call Clarline(13)
End If
Call Clarline(14)
Call Clarline(15)
Else
Call Shownumber(13 , Intlen)
Call Clarline(12)
End If
If Intlen = 1 Then Call Clarline(15) : Call Clarline(16)
End Select
'/* auto backlight */
#if Autolamp = 1
Intlen = Val(strhour)
If Intlen > 18 Or Intlen < 8 Then 'Evening
_lamp = 1
Else 'Morning/afternoon
_lamp = 0
End If
#endif
End If
If Left(str_uart , 4) = "+CSQ" Then
Intlen = Len(str_uart) - 5
Str_uart = Right(str_uart , Intlen)
Intcsq = Val(str_uart)
If Intcsq < 32 Then
'/* normal */
Locate 2 , 1 : Lcd "CSQ: " + Str(intcsq) ; " "
Intcsq = Intcsq / 2
For Intlen = 0 To Intcsq
Locate 1 , Intlen : Lcd Chr(255)
Next Intlen
Intcsq = Intcsq + 1
For Intlen = Intcsq To 16
Locate 1 , Intlen : Lcd Chr(2)
Next Intlen
Else
'/* searching network */
For Intlen = 0 To 4
Locate 1 , Intlen : Lcd Chr(255)
Next Intlen
For Intlen = 5 To 16
Locate 1 , Intlen : Lcd Chr(2)
Next Intlen
Locate 2 , 1 : Lcd "Search network.."
End If
End If
Exit0:
Loop
End
'(
Function : Close Module And Power Off
Date : 2013 / 6 / 01
Rev.3
')
_closemodule:
Cls : Locate 1 , 1 : Lcd "Reset module..."
Print "ATH" : Waitms 100
Print "AT+ZPWROFF"
Waitms 1000
Cls : Locate 1 , 1 : Lcd "Module is full."
Waitms 2000
Cls : Locate 1 , 1 : Lcd "Close the clock!"
_lamp = 0
Module_state = -2
Powerdown
_resetmodule:
Waitms 30
_monoff = 0
Waitms 2000
_monoff = 1
Waitms 100 '200ms impulse
_monoff = 0
_monoff = 1
Waitms 100
_monoff = 0
_monoff = 1
Return
(字数超长,下接) |
|