PDA

View Full Version : 16F690 read/write



louislouis
- 20th November 2016, 21:35
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:


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.

richard
- 21st November 2016, 03:00
your pgm is an incomplete undebugable snippet , start here
http://www.picbasic.co.uk/forum/showthread.php?t=561

louislouis
- 21st November 2016, 10:40
Hello Richard,

here is a complete code with config:



'* 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:



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.

richard
- 21st November 2016, 11:27
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

richard
- 21st November 2016, 11:39
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

aerostar
- 21st November 2016, 11:42
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.

louislouis
- 21st November 2016, 11:54
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.

louislouis
- 21st November 2016, 12:00
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:



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

richard
- 21st November 2016, 12:16
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

richard
- 21st November 2016, 12:25
works just fine for me

louislouis
- 21st November 2016, 12:41
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.

richard
- 21st November 2016, 13:02
this is what I tried , it works fine



#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

louislouis
- 21st November 2016, 13:47
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 .

Bums12
- 17th December 2016, 09:21
I can not delete my message.