PDA

View Full Version : pic basic i2c bus does not work



tamertokgoz
- 11th June 2008, 21:22
Originally Posted by tamertokgoz
'I try to use sda scl fmc24c512 and pcf8583 on the sda scl line
'but could not read anythıng from eeprom when I push the
'button also the second problem is the lcd shows abnormal
'hour minute day v.s sometimes and shows what it has to
'be sometimes could you help me
'fm24c512 has a2 on chasis a1 and a0 on 5 volt connecttion with 4.7k thanks for help


DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE ADC_BITS 100
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50




SDA var PORTC.4
SCL var PORTC.3
BTN1 VAR PORTD.0 ' BUTON 1

symbol So = PORTE.0 ' Serial output pin
symbol capture = PIR1.2 ' CCP1 capture flag
symbol overflow = PIR1.0 ' Timer1 overflow flag

TRISA = %11111111
TRISB = %00000001
ADCON1 = %10000010

ADD VAR WORD
ADDO VAR WORD
FX VAR WORD

f2 var word
VOLT VAR WORD
AMPER VAR WORD
y var word
F1 VAR WORD
per var word

fre var word
MS VAR WORD
period VAR WORD ' Word variable that stores the value

sec var byte
mnt var byte
hour var byte
day var byte
month var byte
year var byte

CCP1CON = %00000100 ' Enable the CCP1 capture, falling edge
T1CON = %00000001 ' TMR1 prescale=1, and turn it on (1uS per count)

BOOT:
LCDOut $fe, 1

LCDOut " "

LCDOut $fe,$c0," "
pause 6
ADD =10

loop:
IF (capture = 0) Then loop ' Wait here until captured

period.lowbyte = CCPR1L ' Store the captured value in
period.highbyte = CCPR1H ' period variable

IF overflow = 0 Then ' Skip the output if the timer overflowed
' So=period
goto adcloop
EndIF

capture = 0 ' Clear the capture flag
reset:

IF (capture = 0) Then reset ' Wait for beginning of next period

TMR1L = 0 ' Clear Timer1 low register
TMR1H = 0 ' Clear Timer1 high register
capture = 0 ' Clear capture flag
overflow = 0 ' Clear overflow flag



goto loop



ADCLOOP:
ADCIN 0, VOLT
PAUSE 40
ADCIN 1, AMPER
amper = (amper */ 15)>>2



i2cread SDA,scl,%10100000,2,[sec,mnt,hour,day,month]
CKP =1
year.3 = 1
year.2 = 0
year.1 = day.6
year.0 = day.7

month.5 =0
month.6 =0
month.7 =0
'day.5 =0
day.6 =0
day.7 =0

pause 25
f1 = period / 100
f1 = 10000 / f1
y = 10000/ f1
y = y*100
if y > period then
f2 =">"
else
f2 ="<"
endif



LCDOut $fe, 1
Lcdout hex2(hour),hex2(mnt),hex2(Sec), "-", hex2(day),".", hex2(month),"." , hex2(year)

LCDOut $fe,$c0,"V="
Lcdout dec VOLT

lcdout " I="
Lcdout dec AMPER
LCDOut " F"
Lcdout F2,"=",dec F1
ADD = ADD +1
I2CWRITE SDA,SCL,$A6,ADD,[ADD],BOGUS
PAUSE 50
IF BTN1 THEN OKU
GoTo loop ' Do it forever
OKU :
FOR ADDO =10 TO ADD
I2CREAD SDA,SCL,$A7,ADDO,[FX],BOGUS
PAUSE 25
SEROUT2 So,84,[DEC ADDO ,"--", DEC(FX), 13,10]
PAUSE 50

NEXT
GOTO LOOP
bogus:
LCDOut $fe,1, "timed out" ' I2C command timed out
Pause 1000
RETURN


End

mister_e
- 11th June 2008, 21:23
This is absolutely imperative you told us which PIC you're using and at which frequency you run it.

I don't see any Config fuses setting either.

Schematic is more than welcome.

tamertokgoz
- 11th June 2008, 21:25
This is absolutely imperative you told us which PIC you're using and at which frequency you run it.

I don't see any Config fuses setting either.

Schematic is more than welcome.

pic 16f687

mister_e
- 11th June 2008, 22:09
Check your datasheet for ANSEL and ANSELH register settings.

As you have it now, you have some digital vouched use... but... on analog configured pins.

WOW ISIS... http://www.mister-e.org/Pics/puke

tamertokgoz
- 12th June 2008, 22:57
Check your datasheet for ANSEL and ANSELH register settings.

As you have it now, you have some digital vouched use... but... on analog configured pins.

WOW ISIS... http://www.mister-e.org/Pics/puke

it also does not any help