PDA

View Full Version : On Board EEPROM Write Read



Peter1960
- 22nd June 2005, 23:58
Hello,
Aim -
To Read Status of Pins, A2 - A5 (4 bits)
Display on Other Pins, B4 - B7
Store Data in EEPROM Location 24 (Onboard)

Program 16F628a 4 mhz
*Usual Setups etc
ID var Byte
ID = 0
' Get Chip ID from PortA 2 - 5
If PortA.2 = 1 Then
ID = ID + 1
High PortB.4
EndIf
If PortA.3 = 1 Then
ID = ID + 2
High PortB.5
EndIf
If PortA.4 = 1 Then
ID = ID + 4
High PortB.6
EndIf
If PortA.5 = 1 Then
ID = ID + 8
High PortB.7
EndIf
Write 24,ID

If all ID were high I was expecting 0F in the location, however
the data pins showed correct, ie all high, but eeprom showed 0C.

Why?

Peter

Peter1960
- 23rd June 2005, 00:01
Oh Dear!!!! Got caught again !!!
Trick for anyone reading this....
If you use a PIC chip with on board Analogue Inputs, ie
A0, A1, A2, A3 on PIC 16F628a,
Make SURE you add the line
CMCON = 7 ( Disable A-D, PortA = Digital)

Adding this line resolved the problem.

Actually I realised as I was typing the question before,
added the line in the program, and yep! all working.

Trust this will help.
thnks
Peter

mister_e
- 23rd June 2005, 00:18
S.h.i.t. happen ;)

BTW PORTA is always a problem source... nothing new if i say
read datasheet
you print this page (http://www.melabs.com/support/mcu_hints.htm)

Peter1960
- 23rd June 2005, 00:52
Thnks Steve.

Yep, the old saying R.T.F.M is always true.

Peter

mister_e
- 23rd June 2005, 03:12
Hehe i try to stay as polite as i can ;)

Peter1960
- 23rd June 2005, 03:34
Sorry Steve, I did not mean to offend.

mister_e
- 23rd June 2005, 03:46
I think it's the time to share that picture and laugh together... hehe i like it!!!