Counting led blinks..


Closed Thread
Results 1 to 40 of 93

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, I've been playing some time with READ and Write command on the internal eeprom, I'm having trouble updating DATA @6,5,"54321". Probably I'm doing it the hard way. Can you help me out what I'm doing wrong?
    Code:
    'My Tested Prototype with Pic18F4550 and EEPROMInclude "modedefs.bas"
    INCLUDE "C:\PBP\USB18\EE_Vars.pbp"           ; Include the EE_var routines
    asm
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    DEFINE    OSC 48
    ADCON1 = 15               ' Set all I/Os to Digital      
    CMCON = 7                 ' Disable Comparators
    INTCON2.7 = 0
    'EEprom data
    'U1    VAR WORD  :  @  EE_var  _U1, WORD, 9999 ' for later use
     
    DATA @0,5,"12345"
    DATA @6,5,"54321"
    DATA @13,5,"14332"
    DATA @19,5,"24432"
    DATA @25,5,"85921"
    
    
    TRISA = %00000000
    TRISD = %00000000
    PORTD = %00000000
    TRISB = %11110000    ' Set Keypad I/O 
    PORTB = 0             ' Set columns LOW  
    PortA = 0
    
    
    myvarkey    var byte
    ByteA        var Byte[6]  
    B0          var byte[5]
    cnt         var byte
    x           var byte
    cnt = 0
    asciichar var byte
    address var byte
        '    ---------------------------------[Program Start]----------------------------------------------
    serout2 PortD.5,T9600,[$1B,$63,$30]  
    pause 200
    serout2 PortD.5,84,[$1B,$45,"EEPROM"]
    serout2 PortD.5,84,[$D,"Studies"]
    serout2 PortD.5,84,[$1B,$63,$30]
    pause 2000
    Serout2 PortD.5,84, [$1B,$45]
    main:
    
    
    @ READKEYPAD _myvarkey
    lookup myvarkey,[0,"123A456B789C*0#D"],Key 
    Serout2 PortD.5,84, [$1B,$45,"Key = ",Key]
     
    if Key = "#"  and cnt < 6 then
         if ByteA[0]="1" and ByteA[1]="9" then   ' wait 19 is pressed before updating 
            Serout2 PortD.5,84, [$D, "Special Key"]        
            pause 20
            serout2 PortD.5,84,[$D,str ByteA\cnt]
            READ 6,x
             for address=6 to x+6
                Write address+1, ByteA[address]
             next address
            cnt=0   
         endif  
         
    else                         
         ByteA[cnt]=Key
         Serout2 PortD.5,84, [$D, ">" , ByteA[cnt]]
         cnt=cnt+1
    
    
    Endif
    
    
    if cnt > 5 then
    Serout2 PortD.5,84, [$D, "5Digits only"]
    cnt = 0
    ENdif
    
    
    
    
    if Key = "A" then
    READ 0,x
    serout2 PortD.5,84,[$D,Dec x," "]
    pause 1000
    for address=0 to x
        READ address,asciichar
        serout2 PortD.5,84,[$D,asciichar]
    next address
    pause 1000
    cnt = 0
    endif
    
    
    if Key = "B" then
    READ 6,x
    serout2 PortD.5,84,[$D,Dec x," "]
    pause 1000
    for address=0+6 to x+6
        READ address,asciichar
        serout2 PortD.5,84,[$D,asciichar]
    next address
    pause 1000
    cnt = 0
    endif
    
    
    if Key = "C" then
    READ 13,x
    serout2 PortD.5,84,[$D,Dec x," "]
    pause 1000
    for address=0+13 to x+13
        READ address,asciichar
        serout2 PortD.5,84,[$D,asciichar]
    next address
    pause 1000
    cnt = 0
    endif
    
    
    if Key = "D" then
    READ 19,x
    serout2 PortD.5,84,[$D,Dec x," "]
    pause 1000
    for address=0+19 to x +19
        READ address,asciichar
        serout2 PortD.5,84,[$D,asciichar]
    next address
    pause 1000
    cnt = 0
    endif
    
    
    if Key = "*" then
    READ 25,x
    serout2 PortD.5,84,[$D,Dec x," "]
    pause 1000
    for address=0+25 to x +25
        READ address,asciichar
        serout2 PortD.5,84,[$D,asciichar]
    next address
    pause 1000
    cnt = 0
    endif
    pause 500
    goto main
    But updating Data @0 ,"12345" was not a problem, I'm stuck passed @0 location.

    regards,
    tacbanon

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    This:
    Code:
    DATA @0,"12345"
    DATA @6,"54321"
    produces this when the EEPROM is read back
    31 32 33 34 35 00 35 34 33 32 31 00 FF FF

    Is that what you want?

    Did you find out what went bad with the SD card module? You can always use the SD card socket without all the other stuff on the module, it is easy if the MCU is running ~3 volts.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Code:
    DATA @0,"12345"
    DATA @6,"54321"
    Sorry If I was not being clear... how can I rewrite them and read back as in the format of "56988" or "65431".
    Before overwriting DATA @6,"54321" I can read back as "54321". But after updating it gives me like Hex numbers.

    I don't know exactly what happened to sdcard it just dont work as before. But I will try to test it again later.

    thanks,
    tacbanon

  4. #4
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi mackrackit, sorry if was not making clear. I want to read back from eeprom in the format of example "12345" or "65432" and I can do this uisng the following code.
    Code:
    if Key = "A" then
    READ 0,x
    serout2 PortD.5,84,[$D,Dec x," "]
    pause 1000
    for address=0 to x
        READ address,asciichar
        serout2 PortD.5,84,[$D,asciichar]
    next address
    pause 1000
    cnt = 0
    endif
    And I noticed that if I rewrite the value of DATA @6,5,"54321" by entering "19325" and read it back I get "QZu" not "19325"..how do I resolve this?
    I will try to test the sdcard tonight, hope something comes up....

    thanks,
    tacbanon
    Last edited by tacbanon; - 2nd November 2011 at 11:59.

  5. #5
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi I finally got my eeporm problem solved..I figured that it needs 2 location space in between.
    Code:
    DATA @0,5,"12345"
    DATA @7,5,"54321"
    DATA @14,5,"14332"
    DATA @21,5,"24432"
    DATA @28,5,"85921"
    works great...
    BTW just want to ask if there is a possible to press a key that consist of several characters, for example if I pressed key 1 in successive I can get a character 'a','b','c'. similar to a cellphone keypad.

    regards,
    tacbanon
    Last edited by tacbanon; - 2nd November 2011 at 14:01.

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    I found one link http://www.picbasic.co.uk/forum/showthread.php?t=11209 but not sure how to to do it...but I will try..

    regards,
    tacbanon

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Melanie's example is good, but the methods talked about at the start of this thread might be better.
    Timer/Counter from TIMER0.
    It should work well with all of the other stuff going on.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, I'm sorry about that(I'm misleading the thread), anyway I borrowed an sdcard from a friend...but he never tested it yet and doesn't have datasheet..hopefully I don't blow it up
    Here are the List I done & planning to do on my project in this thread.
    1. Use Timer/Counter from TIMER0 for multi coin-acceptor(pic16F877 and 18F4550) -Done
    2. Test RTC and Sdcard separate program- Done
    3. Incorporating Multi coin acceptor-RTC and Keypad on 4550 - Done (I need the keypad for access and view settings.)
    4. Incorporate SDcard for saving RTC data and number of coins dropped - not yet
    5. Use USB CDC to dump data(rtc and number of coins) from SDcard to terminal communicator - not yet


    I appreciated the help and the knowledge I got on this forum...not easy task(for me) but you encourage me to try it out...


    thanks again,
    tacbanon
    Last edited by tacbanon; - 3rd November 2011 at 10:18.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts