سلام
من با استفاده از یه kbd وglcd یه دفترچه یادداشت خیلی ساده ساختم اما یه جائی به مشکل برخوردبرنامه سه قسمت داره : پاک کردن کل حافظه eeprom (دفترچه)/ یادداشت پیام / جستجوی پیام
مشکل من تو قسمت جستجو هستش
مثلا 4 تا پیام رو از خونه 0 حافظه ذخیره کردم(آدرس ها پشت سر هم هست و برای هر پیام 64 تا خونه حافظه رو اختصاص دادم)
اما زمانیکه سرچ میکنم برنامه کار نمیکنه و یه سری کد اشتباه به جای پیام ذخیره شده برام نمایش میده و ضمنا سرچ به این صورت هستش که شماره پیام ذخیره شده باید وارد بشه مثلا اگر 1 را وارد کنم باید پیام شماره 1 نمایش داده بشه
میشه لطفا راهنمائی بفرمائید
مرسی
$regfile = "m32def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$include "font8x8.font"
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
'some routines to control the display are in the glcdKS108.lib file
$lib "glcdKS108.lib"
'First we define that we use a graphic LCD
Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Portd , Ce = 4 , Ce2 = 3 , Cd = 2 , Rd = 1 , Reset = 5 , Enable = 0
'Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Porta , Ce = 4 , Ce2 = 3 , Cd = 0 , Rd = 1 , Reset = 5 , Enable = 2
'Mishod Payeh Shomareh 5 Ra Braye Reser Entekhab ****m - Man Shomareh 6 Ra Gharar Dadam Va Reset Lcd Ra Mostaghim Be Vcc Vasl Kardam.
'The dataport is the portname that is connected to the data lines of the LCD
'The controlport is the portname which pins are used to control the lcd
'CE =CS1 Chip select
'CE2=CS2 Chip select second chip
'CD=Data/instruction
'RD=Read
'RESET = reset
'ENABLE= Chip Enable
'specify the font we want to use
Setfont Font8x8
Config Kbd = Portc , Debounce = 20 [ , Delay = 100]
Config Timer1 = Timer , Prescale = 8
Stop Timer1
Enable Interrupts
Enable Ovf1
On Ovf1 Ovf1routin
Dim X As Byte
Dim Y As Byte
Dim A As Word
Dim B As Word
Dim Data_show As Word
Dim Key As Byte
Dim Column As Byte , Row As Byte
Dim Eepra As Integer
Dim Eeprd As Byte
Dim Counter_1 As Byte
Dim Lookds As Byte
Dim Nme As String * 64
Dim Nme_s As String * 64
Dim Data_1 As Byte
Dim Char_c As Byte
Dim D_save As Byte
Dim Last_a As Eram Integer At 1
Last_a = 0
Main:
Cls Graph
Lcdat 1 , 1 , " Tel_NoteBook "
Lcdat 3 , 1 , "New message=1"
Lcdat 5 , 1 , "Clear all=2"
Lcdat 7 , 1 , "Search=3"
Loop_main:
Do
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key = 0 Then : Goto Sub_newname : End If
If Key = 1 Then : Goto Sub_clear : End If
If Key = 2 Then : Goto Sub_search : End If
Waitms 100
Goto Loop_main
Loop
'-------------------------------------------
' Memory Clear
'-------------------------------------------
Sub_clear:
Cls Graph
Lcdat 1 , 1 , "Are you sure"
Lcdat 3 , 1 , "clear all data ?"
Lcdat 7 , 1 , "OK=F1 Cancel=F2"
Wait 2
Clear_w1:
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key = 15 Then : Goto Main : End If 'Press Menue Button
If Key = 7 Then : Goto Main : End If 'Press Cancel button
If Key = 3 Then 'Press OK Button
Cls Graph
Lcdat 1 , 1 , "Please wait..."
Lcdat 3 , 1 , "Deleting memory"
Eeprd = 0
For Eepra = 0 To 1023
Writeeeprom Eeprd , Eepra
Next Eepra
'Last_a = 10
'Total_n = 0
Cls Graph
'LCDAT Y , COL, value
Lcdat 1 , 1 , "Memory Empty"
Wait 3
Goto Main
End If
Goto Clear_w1
'-------------------------------------------
' Save New Number
'-------------------------------------------
Sub_newname:
Cls Graph
Lcdat 1 , 1 , "type message :"
Wait 1
Cls
D_save = 0
Column = 1
Nme = " "
Wait 1
Noname:
Stop Timer1
Timer1 = 0
Counter_1 = 0
Lookds = 0
If D_save = 1 Then : Goto Data_save : End If
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key > 15 Then : Goto Noname : End If
New_char:
Start Timer1
If Key = 15 Then : Stop Timer1 : Goto Main : End If 'Press Menue Button
If Key = 7 Then : Stop Timer1 : Goto Main : End If 'Press Cancel Button
If Key = 3 Then : D_save = 1 : Goto Noname : End If 'Press Ok Button
If Key = 12 Then : Goto Noname : End If 'Press * key
If Key = 14 Then : Goto Noname : End If 'Press # key
If Key = 11 Then
Stop Timer1
Timer1 = 0
Counter_1 = 0
Decr Column
Data_1 = " "
Mid(nme , Column , 1) = Data_1
Lcdat 3 , 1 , Nme
If Column = 0 Then
Nme = " "
Column = 1
End If
Waitms 300
Goto Noname
End If
If Lookds = 0 Then : Data_1 = Lookupstr(key , Sdata_0) : End If
If Lookds = 1 Then : Data_1 = Lookupstr(key , Sdata_1) : End If
If Lookds = 2 Then : Data_1 = Lookupstr(key , Sdata_2) : End If
If Lookds = 3 Then : Data_1 = Lookupstr(key , Sdata_3) : End If
If Lookds = 4 Then : Data_1 = Lookupstr(key , Sdata_4) : End If
Mid(nme , Column , 1) = Data_1
Lcdat 3 , 1 , Nme
Incr Lookds
If Lookds = 5 Then : Lookds = 0 : End If
Waitms 200
Save_w1:
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Counter_1 >= 10 Then
Incr Column
Goto Noname
End If
If Key < 16 Then
Stop Timer1
Timer1 = 0
Counter_1 = 0
Goto New_char
End If
Goto Save_w1
'--------------------------------------------------
Data_save:
Eepra = Last_a
Writeeeprom Nme , Eepra
Eepra = Eepra + 64
Last_a = Eepra
Cls Graph
Lcdat 1 , 1 , "message Saved"
Wait 2
Goto Main
'--------------------------------------------------
' Search
'--------------------------------------------------
Sub_search:
Cls Graph
Lcdat 1 , 1 , "Enter Number:"
Wait 1
Cls
Noname_s:
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key > 15 Then : Goto Noname_s : End If
New_char_s:
Start Timer1
If Key = 15 Then : Stop Timer1 : Goto Main : End If 'Press Menue Button
If Key = 7 Then : Stop Timer1 : Goto Main : End If 'Press Cancel Button
If Key = 3 Then : D_save = 1 : Goto S_search : End If 'Press Ok Button
If Key = 12 Then : Goto Noname_s : End If 'Press * key
If Key = 14 Then : Goto Noname_s : End If 'Press # key
S_search:
Cls
Select Case Key
Case 0:
For B = 0 To 64
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 1:
For B = 65 To 129
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 2:
For B = 130 To 194
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 3:
For B = 195 To 259
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 4:
For B = 260 To 324
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 5:
For B = 325 To 389
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case Else:
Cls
Lcdat 1 , 1 , " I'm Sorry"
Lcdat 2 , 3 , " Message "
Lcdat 3 , 3 , " Not Found"
End Select
Wait 5
Goto Main
End 'end program
Ovf1routin:
Incr Counter_1
Return
Data_key:
Data 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15
Sdata_0:
Data "1" , "2" , "3" , "A" , "4" , "5" , "6" , "B" , "7" , "8" , "9" , "C"_
, "*" , "0" , "#" , "D"
Sdata_1:
Data "." , "a" , "d" , "A" , "g" , "j" , "m" , "B" , "p" , "t" , "w" , "C"_
, "+" , " " , "(" , "D"
Sdata_2:
Data "," , "b" , "e" , "A" , "h" , "k" , "n" , "B" , "q" , "u" , "x" , "C"_
, "-" , "@" , "
" , "D"
Sdata_3:
Data "?" , "c" , "f" , "A" , "i" , "l" , "o" , "B" , "r" , "v" , "y" , "C"_
, "/" , "$" , "%" , "D"
Sdata_4:
Data "!" , "2" , "3" , "A" , "4" , "5" , "6" , "B" , "s" , "8" , "z" , "C"_
, "\" , "^" , "~" , "&" , "D"
من با استفاده از یه kbd وglcd یه دفترچه یادداشت خیلی ساده ساختم اما یه جائی به مشکل برخوردبرنامه سه قسمت داره : پاک کردن کل حافظه eeprom (دفترچه)/ یادداشت پیام / جستجوی پیام
مشکل من تو قسمت جستجو هستش
مثلا 4 تا پیام رو از خونه 0 حافظه ذخیره کردم(آدرس ها پشت سر هم هست و برای هر پیام 64 تا خونه حافظه رو اختصاص دادم)
اما زمانیکه سرچ میکنم برنامه کار نمیکنه و یه سری کد اشتباه به جای پیام ذخیره شده برام نمایش میده و ضمنا سرچ به این صورت هستش که شماره پیام ذخیره شده باید وارد بشه مثلا اگر 1 را وارد کنم باید پیام شماره 1 نمایش داده بشه
میشه لطفا راهنمائی بفرمائید
مرسی
$regfile = "m32def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$include "font8x8.font"
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
'some routines to control the display are in the glcdKS108.lib file
$lib "glcdKS108.lib"
'First we define that we use a graphic LCD
Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Portd , Ce = 4 , Ce2 = 3 , Cd = 2 , Rd = 1 , Reset = 5 , Enable = 0
'Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Porta , Ce = 4 , Ce2 = 3 , Cd = 0 , Rd = 1 , Reset = 5 , Enable = 2
'Mishod Payeh Shomareh 5 Ra Braye Reser Entekhab ****m - Man Shomareh 6 Ra Gharar Dadam Va Reset Lcd Ra Mostaghim Be Vcc Vasl Kardam.
'The dataport is the portname that is connected to the data lines of the LCD
'The controlport is the portname which pins are used to control the lcd
'CE =CS1 Chip select
'CE2=CS2 Chip select second chip
'CD=Data/instruction
'RD=Read
'RESET = reset
'ENABLE= Chip Enable
'specify the font we want to use
Setfont Font8x8
Config Kbd = Portc , Debounce = 20 [ , Delay = 100]
Config Timer1 = Timer , Prescale = 8
Stop Timer1
Enable Interrupts
Enable Ovf1
On Ovf1 Ovf1routin
Dim X As Byte
Dim Y As Byte
Dim A As Word
Dim B As Word
Dim Data_show As Word
Dim Key As Byte
Dim Column As Byte , Row As Byte
Dim Eepra As Integer
Dim Eeprd As Byte
Dim Counter_1 As Byte
Dim Lookds As Byte
Dim Nme As String * 64
Dim Nme_s As String * 64
Dim Data_1 As Byte
Dim Char_c As Byte
Dim D_save As Byte
Dim Last_a As Eram Integer At 1
Last_a = 0
Main:
Cls Graph
Lcdat 1 , 1 , " Tel_NoteBook "
Lcdat 3 , 1 , "New message=1"
Lcdat 5 , 1 , "Clear all=2"
Lcdat 7 , 1 , "Search=3"
Loop_main:
Do
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key = 0 Then : Goto Sub_newname : End If
If Key = 1 Then : Goto Sub_clear : End If
If Key = 2 Then : Goto Sub_search : End If
Waitms 100
Goto Loop_main
Loop
'-------------------------------------------
' Memory Clear
'-------------------------------------------
Sub_clear:
Cls Graph
Lcdat 1 , 1 , "Are you sure"
Lcdat 3 , 1 , "clear all data ?"
Lcdat 7 , 1 , "OK=F1 Cancel=F2"
Wait 2
Clear_w1:
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key = 15 Then : Goto Main : End If 'Press Menue Button
If Key = 7 Then : Goto Main : End If 'Press Cancel button
If Key = 3 Then 'Press OK Button
Cls Graph
Lcdat 1 , 1 , "Please wait..."
Lcdat 3 , 1 , "Deleting memory"
Eeprd = 0
For Eepra = 0 To 1023
Writeeeprom Eeprd , Eepra
Next Eepra
'Last_a = 10
'Total_n = 0
Cls Graph
'LCDAT Y , COL, value
Lcdat 1 , 1 , "Memory Empty"
Wait 3
Goto Main
End If
Goto Clear_w1
'-------------------------------------------
' Save New Number
'-------------------------------------------
Sub_newname:
Cls Graph
Lcdat 1 , 1 , "type message :"
Wait 1
Cls
D_save = 0
Column = 1
Nme = " "
Wait 1
Noname:
Stop Timer1
Timer1 = 0
Counter_1 = 0
Lookds = 0
If D_save = 1 Then : Goto Data_save : End If
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key > 15 Then : Goto Noname : End If
New_char:
Start Timer1
If Key = 15 Then : Stop Timer1 : Goto Main : End If 'Press Menue Button
If Key = 7 Then : Stop Timer1 : Goto Main : End If 'Press Cancel Button
If Key = 3 Then : D_save = 1 : Goto Noname : End If 'Press Ok Button
If Key = 12 Then : Goto Noname : End If 'Press * key
If Key = 14 Then : Goto Noname : End If 'Press # key
If Key = 11 Then
Stop Timer1
Timer1 = 0
Counter_1 = 0
Decr Column
Data_1 = " "
Mid(nme , Column , 1) = Data_1
Lcdat 3 , 1 , Nme
If Column = 0 Then
Nme = " "
Column = 1
End If
Waitms 300
Goto Noname
End If
If Lookds = 0 Then : Data_1 = Lookupstr(key , Sdata_0) : End If
If Lookds = 1 Then : Data_1 = Lookupstr(key , Sdata_1) : End If
If Lookds = 2 Then : Data_1 = Lookupstr(key , Sdata_2) : End If
If Lookds = 3 Then : Data_1 = Lookupstr(key , Sdata_3) : End If
If Lookds = 4 Then : Data_1 = Lookupstr(key , Sdata_4) : End If
Mid(nme , Column , 1) = Data_1
Lcdat 3 , 1 , Nme
Incr Lookds
If Lookds = 5 Then : Lookds = 0 : End If
Waitms 200
Save_w1:
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Counter_1 >= 10 Then
Incr Column
Goto Noname
End If
If Key < 16 Then
Stop Timer1
Timer1 = 0
Counter_1 = 0
Goto New_char
End If
Goto Save_w1
'--------------------------------------------------
Data_save:
Eepra = Last_a
Writeeeprom Nme , Eepra
Eepra = Eepra + 64
Last_a = Eepra
Cls Graph
Lcdat 1 , 1 , "message Saved"
Wait 2
Goto Main
'--------------------------------------------------
' Search
'--------------------------------------------------
Sub_search:
Cls Graph
Lcdat 1 , 1 , "Enter Number:"
Wait 1
Cls
Noname_s:
Key = Getkbd()
If Key < 16 Then Key = Lookup(key , Data_key)
If Key > 15 Then : Goto Noname_s : End If
New_char_s:
Start Timer1
If Key = 15 Then : Stop Timer1 : Goto Main : End If 'Press Menue Button
If Key = 7 Then : Stop Timer1 : Goto Main : End If 'Press Cancel Button
If Key = 3 Then : D_save = 1 : Goto S_search : End If 'Press Ok Button
If Key = 12 Then : Goto Noname_s : End If 'Press * key
If Key = 14 Then : Goto Noname_s : End If 'Press # key
S_search:
Cls
Select Case Key
Case 0:
For B = 0 To 64
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 1:
For B = 65 To 129
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 2:
For B = 130 To 194
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 3:
For B = 195 To 259
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 4:
For B = 260 To 324
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case 5:
For B = 325 To 389
If X >= 128 Then
X = 0
Y = Y + 8
End If
Readeeprom Data_show , B
Lcdat Y , X , Data_show
X = X + 8
Next
Case Else:
Cls
Lcdat 1 , 1 , " I'm Sorry"
Lcdat 2 , 3 , " Message "
Lcdat 3 , 3 , " Not Found"
End Select
Wait 5
Goto Main
End 'end program
Ovf1routin:
Incr Counter_1
Return
Data_key:
Data 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15
Sdata_0:
Data "1" , "2" , "3" , "A" , "4" , "5" , "6" , "B" , "7" , "8" , "9" , "C"_
, "*" , "0" , "#" , "D"
Sdata_1:
Data "." , "a" , "d" , "A" , "g" , "j" , "m" , "B" , "p" , "t" , "w" , "C"_
, "+" , " " , "(" , "D"
Sdata_2:
Data "," , "b" , "e" , "A" , "h" , "k" , "n" , "B" , "q" , "u" , "x" , "C"_
, "-" , "@" , "

Sdata_3:
Data "?" , "c" , "f" , "A" , "i" , "l" , "o" , "B" , "r" , "v" , "y" , "C"_
, "/" , "$" , "%" , "D"
Sdata_4:
Data "!" , "2" , "3" , "A" , "4" , "5" , "6" , "B" , "s" , "8" , "z" , "C"_
, "\" , "^" , "~" , "&" , "D
دیدگاه