1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

write string in eeprom?

Discussion in 'Oshonsoft' started by ese2709, Aug 8, 2012.

  1. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,187
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Look at this option, I have checked it with your keypad settings and it works ok.

    Dont forget to make Dim keyoff as Byte

    Code (text):

    lp1:
    PORTD = 0x0f
    keyoff = PORTD And 0xf0
    If keyoff <> 0 Then
    Goto lp1
    Endif
     
     
    Last edited: Aug 13, 2012
  2. ese2709

    ese2709 New Member

    Joined:
    Aug 20, 2011
    Messages:
    30
    Likes:
    0
    it works.... tq very much...

    now its going to next step;)
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,187
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    Thats good.;)

    I would not use a code character value above 9.
    Have you considered 0 thru 9 A,B,C,D,E,F [ as ASCII characters]

    EDIT:
    You dont need the '#' sign in front of the value when you use this method.
    Also the EEPROM write is included with the LCD write routine
    The value saved in EEPROM is in ASCII

    Code (text):

    Define SIMULATION_WAITMS_VALUE = 1

    Define CONF_WORD = 0x3f72
    Define CLOCK_FREQUENCY = 12
    AllDigital

    Define LCD_BITS = 4
    Define LCD_DREG = PORTB
    Define LCD_DBIT = 0
    Define LCD_RSREG = PORTE
    Define LCD_RSBIT = 0
    Define LCD_RWREG = PORTE
    Define LCD_RWBIT = 1
    Define LCD_EREG = PORTE
    Define LCD_EBIT = 2
    Define LCD_READ_BUSY_FLAG = 1

    'For Keypad
    Symbol raw1 = RD7
    Symbol raw2 = RD6
    Symbol raw3 = RD5
    Symbol raw4 = RD4
    Symbol col1 = RD0
    Symbol col2 = RD1
    Symbol col3 = RD2
    Symbol col4 = RD3
    TRISD = 0xf0
    TRISB = 0
    Lcdinit

    Dim button As Byte
    Dim digit As Byte
    Dim pass As Byte
    Dim error As Bit
    Dim mem As Byte
    Dim keyoff As Byte

    start:

    Lcdcmdout LcdClear

    Lcdout "ALARM SYSTEM"
    Lcdcmdout LcdClear
    Lcdout "New Password:"
    Lcdcmdout LcdLine2Home
    Lcdout "****"

    mem = 0
    For digit = 1 To 4  '4 digit password
    Gosub get_button
    pass(digit) = button
    Lcdcmdout LcdLine2Pos(digit)  'replace '-' with key type
    Lcdout button  ''''#button

    Write mem, pass(digit)
    mem = mem + 1

    button = 0
    Next digit

    '''''''go to write input data
    '''''''Gosub write_data

    Lcdcmdout LcdClear
    Lcdout "Password Saved"

    WaitUs 2000

    'Test Password
    Gosub check_password

    Goto start
    End                                              

    check_password:

    Lcdcmdout LcdClear
    Lcdcmdout LcdLine1Home
    Lcdout "Type Password"

    For digit = 1 To 4  '4 digit password
    Gosub get_button
    pass(digit) = button
    Lcdcmdout LcdLine2Pos(digit)
    Lcdout button  '''#button

    button = 0
    Next digit

    '???? Here how to check the input password is same with saved password, error = 1 if wrong password.... some code for me?

    If error = 1 Then
    Lcdout "Access Denied"
    WaitUs 2000
    Goto check_password
    Else
    Lcdout "Access verified"
    Endif
    Return                                            

    get_button:

    While button = 0
    button = 0
    col1 = 1
    If raw1 = 1 Then button = "0"
    If raw2 = 1 Then button = "4"
    If raw3 = 1 Then button = "8"
    If raw4 = 1 Then button = "C"
    col1 = 0
    col2 = 1
    If raw1 = 1 Then button = "1"
    If raw2 = 1 Then button = "5"
    If raw3 = 1 Then button = "9"
    If raw4 = 1 Then button = "D"
    col2 = 0
    col3 = 1
    If raw1 = 1 Then button = "2"
    If raw2 = 1 Then button = "6"
    If raw3 = 1 Then button = "A"
    If raw4 = 1 Then button = "E"
    col3 = 0
    col4 = 1
    If raw1 = 1 Then button = "3"
    If raw2 = 1 Then button = "7"
    If raw3 = 1 Then button = "B"
    If raw4 = 1 Then button = "F"
    col4 = 0
    Wend

    lp1:
    PORTD = 0x0f
    keyoff = PORTD And 0xf0
    If keyoff <> 0 Then
    Goto lp1
    Endif



    '?????here the code wait for button release before return.... some code for me??? :)
    Return
     
    Last edited: Aug 13, 2012
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ese2709

    ese2709 New Member

    Joined:
    Aug 20, 2011
    Messages:
    30
    Likes:
    0

    Code (text):

    Define CONF_WORD = 0x3f72
    Define CLOCK_FREQUENCY = 12
    AllDigital

    Define LCD_BITS = 4
    Define LCD_DREG = PORTB
    Define LCD_DBIT = 0
    Define LCD_RSREG = PORTE
    Define LCD_RSBIT = 0
    Define LCD_RWREG = PORTE
    Define LCD_RWBIT = 1
    Define LCD_EREG = PORTE
    Define LCD_EBIT = 2
    Define LCD_READ_BUSY_FLAG = 1

    'For Keypad
    Symbol raw1 = RD7
    Symbol raw2 = RD6
    Symbol raw3 = RD5
    Symbol raw4 = RD4
    Symbol col1 = RD0
    Symbol col2 = RD1
    Symbol col3 = RD2
    Symbol col4 = RD3
    TRISD = 0xf0
    TRISB = 0
    Lcdinit

    Dim button As Byte
    Dim digit As Byte
    Dim pass(4) As Byte
    Dim error As Bit
    Dim mem As Byte
    Dim b As Byte
    Dim keyoff As Byte
    Dim readtemp(4) As Byte

    start:
    Lcdcmdout LcdClear
    Lcdout "ALARM SYSTEM"
    Lcdcmdout LcdLine2Home
    Lcdout "Press Any Key"
    Gosub get_button
    If button = 0 Then
    Goto start
    Else
    button = 0
    Endif

    Gosub set_password

    Gosub check_password
    End                                              

    set_password:
    Lcdcmdout LcdClear
    Lcdout "New Password:"
    Lcdcmdout LcdLine2Home
    Lcdout "----"

    For digit = 1 To 4  '4 digit password
    Gosub get_button
    pass(digit) = button
    Lcdcmdout LcdLine2Pos(digit)  'replace '-' with key type
    Lcdout button
    button = 0
    Next digit

    'go to write input data
    Gosub write_data

    Lcdcmdout LcdClear
    Lcdout "Password Saved"

    WaitUs 2000

    Return                                            

    check_password:
    Lcdcmdout LcdClear
    Lcdcmdout LcdLine1Home
    Lcdout "Type Password:"

    For digit = 1 To 4  '4 digit password
    Gosub get_button
    pass(digit) = button
    Lcdcmdout LcdLine2Pos(digit)
    Lcdout button
    button = 0
    Next digit

    Gosub read_passmem

    If pass(1) <> readtemp(1) Then
    error = 1
    Endif
    If pass(2) <> readtemp(2) Then
    error = 1
    Endif
    If pass(3) <> readtemp(3) Then
    error = 1
    Endif
    If pass(4) <> readtemp(4) Then
    error = 1
    Endif

    If error = 1 Then
    Lcdcmdout LcdLine2Home
    Lcdout "Access Denied"
    WaitUs 2000
    Goto check_password
    Else
    Lcdcmdout LcdLine2Home
    Lcdout "Access verified"
    Endif
    Return                                            

    write_data:
    mem = 0x30  'memory address start
    For digit = 1 To 4
    Write mem, pass(digit)
    mem = mem + 1
    Next digit
    Return                                            

    read_passmem:
    Lcdcmdout LcdLine2Home
    Lcdout "----"
    mem = 0x30
    For digit = 1 To 4
    Read mem, readtemp(digit)
    Lcdcmdout LcdLine2Pos(digit)
    Lcdout readtemp(digit)
    mem = mem + 1
    Next digit
    Return                                            


    get_button:
    While button = 0
    button = 0
    col1 = 1
    If raw1 = 1 Then button = "0"
    If raw2 = 1 Then button = "4"
    If raw3 = 1 Then button = "8"
    If raw4 = 1 Then button = "C"
    col1 = 0
    col2 = 1
    If raw1 = 1 Then button = "1"
    If raw2 = 1 Then button = "5"
    If raw3 = 1 Then button = "9"
    If raw4 = 1 Then button = "D"
    col2 = 0
    col3 = 1
    If raw1 = 1 Then button = "2"
    If raw2 = 1 Then button = "6"
    If raw3 = 1 Then button = "A"
    If raw4 = 1 Then button = "E"
    col3 = 0
    col4 = 1
    If raw1 = 1 Then button = "3"
    If raw2 = 1 Then button = "7"
    If raw3 = 1 Then button = "B"
    If raw4 = 1 Then button = "F"
    col4 = 0
    Wend
    Gosub lp1
    Return                                            

    lp1:
    PORTD = 0x0f
    keyoff = PORTD And 0xf0
    If keyoff <> 0 Then
    Goto lp1
    Endif
    Return                                            

     
    here the code... its working... if u have some suggestion for optimize my code i will appreciate...

    Now i`m going to the next step making a menu

    tq very much....;)
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,187
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    If I enter a new pwd and then use the correct pwd again, it says Accepted.

    If I enter the incorrect pwd I get Denied, but after that even when I enter the correct pwd I get denied.

    Also you do not want to offer the user the option to enter a new pwd every time you power up..

    The program has to recognise the correct previous pwd on power up
     
  7. ese2709

    ese2709 New Member

    Joined:
    Aug 20, 2011
    Messages:
    30
    Likes:
    0
    i will check it.... now i`m making the menu...

    later i will post the code...

    tq;)
     
  8. ese2709

    ese2709 New Member

    Joined:
    Aug 20, 2011
    Messages:
    30
    Likes:
    0
    the code is ready, now i`m going to test with circuit... need to assemble circuit.... may take a few dayssssssss... :D
     

Share This Page