EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
You are here: Home / Topics / Help with PIC16F628A can’t write/read to internal EEPROM

Help with PIC16F628A can’t write/read to internal EEPROM

|

Microcontroller › PIC › Help with PIC16F628A can’t write/read to internal EEPROM

  • This topic has 0 replies, 1 voice, and was last updated 1 year, 8 months ago by jerico fulo.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • May 15, 2019 at 1:10 am #5015
    jerico fulo
    Participant

    Hi Guys,

    My first post here so please go easy on me :)

    I have spent a great deal of time trying to write to the internal eeprom in a 16F628A without success. My project is very simple. A single push button advances one of three LEDs eventually lighting all three. When powered down and then back on, I want the LEDs to come back on in the state they were at, at power down. IE: if two LEDs were lit, then the same two should come on at power up.

    My software advances the LEDs no problem but it either doesn't write to the EEPROM or doesn't read the EEPROM at power up. I have tried pretty much all I can think of, I suspect I have a paging problem but a point in the right direction would be appreciated.

    I'm using MPLAB IDE V8.92, writing in assembly language and programming with a PICKIT3

    Code follows and any pointers gratefully received. Cheers, Mark

    INIT
        MOVLW        0X07        ;MAKE PORT PINS DIGITAL
        MOVWF        CMCON
        BSF            RP0
        MOVLW        B'10000000'
        MOVWF        TRISA
        MOVLW        B'00000000'    
        MOVWF        TRISB
        CLRWDT
        MOVLW        B'01010111'    ;ENABLE PORT B PULLUPS
        MOVWF        OPTREG
        
        BCF            RP0
        BCF            RP1
        CLRF        PORTB        ;SET ALL PINS ON PORT B TO LOW (ALL OUTPUTS OFF)
        CLRF        PORTA        ;ALL PORT A PINS ARE OUTPUTS EXCEPT FOR THE SW INPUT – HIGH INPUT = OFF OR NOT ACTIVE – SW INPUT GOES LOW WHEN ACTIVE

        CLRF        LAMPS_REG
        CLRF        ON_TIMER
        CLRW

    ;**************** MAIN PROGRAM STARTS HERE ******************

    TESTING
        BSF            OUT1            ; FLASH A LED TO SHOW POWER UP
        CALL        HALF_SEC
        BCF            OUT1
        CALL        HALF_SEC
        CALL        HALF_SEC
        CALL        HALF_SEC

    START                            ; LOAD FROM EEPROM HERE

        CLRW
        BCF            RP0
        MOVLW        0XF1            ; ADDRESS OF FILES IN EEPROM MEMORY – 0X00 IS THE FIRST ADDRESS IN EEPROM
        BSF            RP0
        MOVWF        EEADR
        BSF            EECON1,0            ; SET BIT FOR READ
        BCF            RP0
        MOVF        EEDATA,W
        MOVWF        LAMPS_REG            ; PUT THE MEMORY INTO THE REG

        CALL        LAMPS_CHECK

    MAIN
        BTFSS        BUTTON
        GOTO        MOVE        ; SWITCH GOES LOW WHEN PUSHED
        GOTO        MAIN        ; SW NOT PRESSED SO KEEP LOOKING

    MOVE                        ; INC ILLUMINATED STACK HERE
        CALL        SHORT_SEC
        BTFSC        BUTTON        ; DOUBLE CHECK NOT A FALSE SW PUSH
        GOTO        MAIN        ; FALSE PRESS SO RETURN TO LOOP LOOKING

    ; TEST TO SEE WHICH LAMPS ARE ON

        BTFSS        LAMPS_REG,0        ; CHECK LAMPS IN ORDER FOR BEING ON
        GOTO        MAKE_1_ON
        BTFSS        LAMPS_REG,1
        GOTO        MAKE_2_ON
        BTFSS        LAMPS_REG,2
        GOTO        MAKE_3_ON

    ; ADD THE REST HERE FOR MORE LAMPS INCLUDING TURN ALL OFF IF THEY ARE ALL NOW ON

    MAKE_1_ON
        BSF            LAMPS_REG,0        ; SET THE BIT IN THE REG    
        BSF            OUT1            ; TURN ON LAMP
        CALL        WRITE_NEW_LAMPS
        GOTO        MAIN
    MAKE_2_ON
        BSF            LAMPS_REG,1
        BSF            OUT2
        CALL        WRITE_NEW_LAMPS
        GOTO        MAIN
    MAKE_3_ON
        BSF            LAMPS_REG,2
        BSF            OUT3
        CALL        WRITE_NEW_LAMPS
        GOTO        MAIN

    CLEAR_ALL                        ; WE GET HERE IF ALL LAMPS ARE ON AND WE WANT TO CLEAR THEM
        CLRF        LAMPS_REG
        CLRF        PORTB
        CLRF        PORTA
        GOTO        MAIN

    WAITING_RELEASE
        BTFSS        BUTTON        ; WAIT FOR BUTTON TO BE RELEASED TO AVOID DOUBLE ADVANCE OF LEDS
        GOTO        WAITING_RELEASE
        GOTO        MAIN

    ;************************** CALLS BELOW HERE ****************************

    WRITE_NEW_LAMPS                ; WRITE TO EEPROM
        MOVLW        0XF1
        BSF            RP0
        MOVWF        EEADR
        BSF            WREN

        BCF            RP0
        MOVF        LAMPS_REG,W
        BSF            RP0

        MOVWF        EEDATA
        MOVLW        H'55'
        MOVWF        EECON2
        MOVLW        H'AA'
        MOVWF        EECON2
        BSF            EECON1,1
        BTFSC        EECON1,1
        GOTO        $-1                ; WAIT FOR WRITE TO COMPLETE
        BCF            WREN
        BCF            RP0

        BTFSS        BUTTON
        GOTO        $-1

        RETURN

    LAMPS_CHECK

        BTFSC        LAMPS_REG,0            ; CHECK EACH POSITION AND SET THE LAMP AS REQUIRED
        BSF            OUT1
        BTFSC        LAMPS_REG,1
        BSF            OUT2
        BTFSC        LAMPS_REG,2
        BSF            OUT3

        RETURN

    ; DELAY ROUTINES BELOW HERE

    ******************************************** END *********************************************

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Honey amp - diy guitar amp kit January 22, 2021
  • Re:paralleled PWM ESCs January 22, 2021
  • Simple class A amplifier how it works January 22, 2021
  • Touch circuit sound, led. 555 timer January 21, 2021
  • new to Ardunio but trying to compile January 21, 2021

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2021 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools