16F690 read/write


Closed Thread
Results 1 to 14 of 14
  1. #1

    Default 16F690 read/write

    Hello,
    I need a little help with read and write to internal EEPROM in PIC16F690.

    I try to write to adress 10, value 1

    like:
    Code:
    led1 var portc.4
    buton1 var porta.4
    led1flag var bit
    
    init:
    low led1
    let led1flag = 0
    
    zac:
    read 10, led1flag
    if buton1 = 0 and led1flag = 0 then goto onled
    if buton1 = 0 and led1flag = 1 then goto offled
    goto zac
    
    onled:
    high led1
    let led1flag = 1
    write 10, led1flag
    debounce:
    if buton1 = 0 then 
    pause 10
    goto debounce
    endif
    goto zac
    
    offled:
    low led1
    let led1flag = 0
    write 10, led1flag
    debb:
    if buton1 = 0 then 
    pause 10
    goto debb
    endif
    goto zac
    But the program stuck on read and the write instruction.
    On 16F628 I use these commands and it works, on 16F690 I am doing something wrong. Please can someone to explain how use READ and WRITE instruction on this chip. Thanks.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    your pgm is an incomplete undebugable snippet , start here
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Warning I'm not a teacher

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    Hello Richard,

    here is a complete code with config:

    Code:
    '*  Notes   : PIC16F690                                         *
    '*          :                                                   *
    '****************************************************************
     _INTRC_OSC_NOCLKOUT ; Using Internal Oscillator
     _WDT_OFF; Edisable Watch Dog Timer
    _MCLRE_OFF; disable MCLR
     _CP_OFF ;Disable Code Protection
     _CPD_OFF ; Disable Data Code Protection
     _FCMEN_OFF ; Disable Fail Safe Clock Monitor
     _IESO_OFF ; Disable Internal/External switchover
     _BOR_ON ;Enable Brown out detect
     _PWRTE_ON ; Enable Power up Timer
     
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON  
    @MyConfig = _MCLRE_OFF & _BOR_OFF 
    
    DEFINE OSC 8 ; tells PBP we use a 8 MHZ clock 
    OSCCON = %01110000 
    
    ANSEL = 0  ;set all digital
    TRISA = %110100    ; Set RA5,RA4 and RA2 input, rest output
    TRISB = %0000     ; PORT B all output
    TRISC = %00000000  ; PORT C all output
    CM1CON0 = 0 ' Disable comparator 1
    CM2CON0 = 0 ' Disable comparator 2
    
    led1 var portc.4
    buton1 var porta.4
    led1flag var bit
    
    low led1
    let led1flag = 0
    
    init:
    read 10,led1flag
    pause 2
               
    main:
    if led1flag = 1 then
    high led1
    else 
    low led1
    endif
    if buton1 = 0 then  
    let led1flag = 1
    goto writetoeeprom
    endif
    goto main
    
    writetoeeprom:
    write 10, led1flag
    pause 2
    debounce:
    if buton1 = 0 then goto debounce
    goto init
    end
    The WRITE and READ instructions works on 16F628, 16F688 as is in the code, but on 16F690 still not.
    I think on 16F690 must to be defined something to proper work with internal eeprom, but I don't know what.

    If I try simple:

    Code:
    led var bit
    let led = 1
    
    write 10, led 
    
    main:
    read 10, led
    SEROUT porta.2,T9600,[led]
    end
    Nothing writen in to the eeprom.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    main:
    read 10, led
    SEROUT porta.2,T9600,[led]
    end

    you realise the chr's 0,1,255 {all the likely eprom values you expect} are unprintable , there is nothing special or different about 16f690 eprom

    SEROUT porta.2,T9600,[#led] or
    SEROUT porta.2,T9600,[dec led]
    is whats required
    Warning I'm not a teacher

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    and I doubt your config setting is correct

    it could go like this , but why would you
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
    @MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF
    @ __config MyConfig
    this is the prescribed way

    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_ON
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
    __CONFIG cfg

    #ENDCONFIG
    or this

    #CONFIG
    __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOD_ON & _IESO_ON & _FCMEN_ON
    #ENDCONFIG
    Warning I'm not a teacher

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    You code for sending the value out is sending unprintable characters to whatever is receiving the serial.

    if your bit is a 0 then that is a null character, if it is a 1 then it is a SOH see here

    http://www.asciitable.com/

    If you want to see the character as a printable digit then add 48 to it
    SEROUT porta.2,T9600,[led+48]

    You could also run your simple program then put the pic back in the programmer, read and view the eeprom data.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    Quote Originally Posted by richard View Post
    and I doubt your config setting is correct

    it could go like this , but why would you


    this is the prescribed way



    or this
    Sorry, that is my copy paste error.

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    Yes this is true, my serout command is not correct, but if I try simple write in to the eeprom the program stuck and not run next.

    Like:

    Code:
    led var bit
    let led = 1
    led var portc.4
    
    write 10, led 
    
    main:
    high led
    pause 500
    low led
    pause 500
    goto main
    end

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    led var bit
    let led = 1
    led var portc.4

    write 10, led

    main:
    high led
    pause 500
    low led
    pause 500
    goto main
    end
    once again an uncompilable piece of code,there is nothing special or different about 16f690 eprom . snippets are pointless
    try and post a complete and correct pgm that demonstrates the issue
    Warning I'm not a teacher

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    works just fine for me
    Attached Images Attached Images  
    Warning I'm not a teacher

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    OK, I try to make a memory pushbutton. If I switch on the power supply and push the button then lit up the led and i want to store to the eeprom value 1 which represent the led is on flag. When I switch off the power supply and then switch on again I want to read value from eeprom and if it is 1 then the led is lit up immediately after power is applied without pushing the button.

    I can program the pic, for me not work the write and the read to internal eeprom instruction.

    On different chip like 16F688 I normally use the Write and Read command to store and read variable value to internal eeprom like:

    WRITE Adress, Value
    (write 10,1)
    and

    READ Adress, Var
    (read 10,led)

    On 16F690 chip It doesn't work for me. The program stops on the line where is the WRITE command or if the read commadn is first then stops on this line.
    Last edited by louislouis; - 21st November 2016 at 13:06.

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    this is what I tried , it works fine


    Code:
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_ON
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
      __CONFIG cfg
    
    #ENDCONFIG
    DEFINE OSC 8 ; tells PBP we use a 8 MHZ clock 
    OSCCON = %01110000 
    
    ANSEL = 0  ;set all digital
    TRISA = %110100    ; Set RA5,RA4 and RA2 input, rest output
    TRISB = %0000     ; PORT B all output
    TRISC = %00000000  ; PORT C all output
    CM1CON0 = 0 ' Disable comparator 1
    CM2CON0 = 0 ' Disable comparator 2
    
    led1 var portc.4
    buton1 var porta.4
    led1flag var bit
    
    low led1
    let led1flag = 0
    
    init:
    read 10,led1flag
    pause 2
               
    main:
    if led1flag = 1 then
    high led1
    else 
    low led1
    endif
    if buton1 = 0 then  
    let led1flag = 1
    goto writetoeeprom
    endif
    goto main
    
    writetoeeprom:
    write 10, led1flag
    pause 2
    debounce:
    if buton1 = 0 then goto debounce
    goto init
    end
    Warning I'm not a teacher

  13. #13


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    Hello Richard,

    basically this is my code without changes, but after try It isn't work. Then I try to replace the chip (the previous is an brand new out of the box) to another brand new and ...
    ... man all works, the trevious chip was faulty, two days of labour and time wasting. Thank You for all support .

  14. #14
    Bums12's Avatar
    Bums12 Guest


    Did you find this post helpful? Yes | No

    Default Re: 16F690 read/write

    I can not delete my message.
    Last edited by Bums12; - 17th December 2016 at 09:28.

Similar Threads

  1. SD Card Write/Read
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th April 2014, 08:26
  2. PLEASE HELP...read write issues
    By nomad77 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th March 2011, 14:39
  3. Can't read an sms Using TC35i & 16F690
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 4th October 2009, 22:41
  4. I2C Read and Write
    By DerekMacom in forum mel PIC BASIC
    Replies: 14
    Last Post: - 21st April 2008, 15:44
  5. cannot read/write to 16F690 data memory after CPD_ON
    By awdsas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd November 2006, 11:46

Members who have read this thread : 2

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