Soft i2c doesn't work

General discussion on mikroPascal.
Post Reply
Author
Message
titan66
Posts: 18
Joined: 11 Mar 2009 11:00

Soft i2c doesn't work

#1 Post by titan66 » 10 Jul 2009 13:35

hi friends
i have a project about digital watch
i did some works but it doesnt work
i use ds1307
what can be my problem?



it is my program;(gun:day,sn:sec,dk:min,ay:mon,yil:year)




program i2c;
uses turkcetimes1414,xglcd_lib,flash_f_e;
var
ee_adr, ee_data : byte;
jj : word;
data:array[0..159] of byte;
dataf:array[0..63] of byte;
datas:array[0..63] of byte;
bb,er,tt,rrr,aa,rr,zz,zzz,ii,v,vv,ks1,kss1,kss2,ks2:byte;
yer,ee,ks,kss,dd,cc,bir,iki,uc,text:word;

txt:string[20] ;

sn, dk, saat, day, gun, ay, yil : byte;
MSG2:string[14];



Procedure Saat_yaz( sn, dk, saat, gun, ay, yil : byte);
begin
Soft_I2C_Config(Porte,2,1);
Soft_I2C_Start();
Soft_I2C_Write($D0);
Soft_I2C_Write($00);
Soft_I2C_Write(dec2bcd(sn));
Soft_I2C_Write(dec2bcd(dk));
Soft_I2C_Write(dec2bcd(saat));
Soft_I2C_Write(dec2bcd(gun));
Soft_I2C_Write(dec2bcd(ay));
Soft_I2C_Write(dec2bcd(yil));
Soft_I2C_Stop();
end;

Procedure Saat_oku;
var
a:byte;
txt:array[0..2] of char;
begin

for a:=1 to 3 do
begin
Soft_I2C_Config(Porte,2,1);
Soft_I2C_Start();
Soft_I2C_Write($D0);
Soft_I2C_Write($00);
Soft_I2C_Start();
Soft_I2C_Write($D1);
sn:=Soft_I2C_Read(1);sn:=bcd2dec(sn);
dk:=Soft_I2C_Read(1);dk:=bcd2dec(dk);
saat:=Soft_I2C_Read(1);saat:=bcd2dec(saat);
day:=Soft_I2C_Read(0);
gun:=Soft_I2C_Read(1);gun:=bcd2dec(gun);
ay:=Soft_I2C_Read(1);ay:=bcd2dec(ay);
yil:=Soft_I2C_Read(0);yil:=bcd2dec(yil);
Soft_I2C_Stop();
if saat>24 then saat:=0;
if dk>60 then dk:=0;
if sn>60 then sn:=0;
if gun>31 then gun:=0;
if ay>12 then ay:=0;
if yil>99 then yil:=0;
MSG2[3]:=chr(48);
MSG2[4]:=chr(57);
MSG2[0]:=chr(49);
MSG2[1]:=chr(53);
MSG2[2]:=chr(47);
end;
end;
Procedure giris;

begin
saat_oku;

MSG2[3]:=48+dk DIv 10;
MSG2[4]:=48+dk MOD 10;
MSG2[0]:=48+saat DIv 10;
MSG2[1]:=48+saat MOD 10;
MSG2[2]:=chr(58);
xGlcd_Write_Text(msg2, 50, 28, 1);
end;
label ana,off,onn,ana1,ana2,atla,bas;
begin
PORTA:=0; // portlar temizlendi
PORTB:=0;
PORTD:=0;
PORTC:=0;
TRISA:=%00000100; //Giriş çıkışlar ayarlandı
trisb:=%00000000;
trisd:=%00000000;
TRISC:=%11001000;
TRISE:=%00000110;
ADCON1:=%00000110; //PortAnın tüm bacakları digital seçildi
ADCON0:=0;
Glcd_Init(PORTd,2,3,6,5,0,7,PORTb); // lcd init
xGlcd_Set_Font(@Times_New_Roman14x14, 14,14,32); // glcd generator init
glcd_Fill(0);
xGlcd_Write_text(' RFID', 0,20, 1);
Glcd_Write_text(' Kart Okuyucu', 18,5, 1);
delay_ms(700); // olmazsa usart_init çaçışmıyo
usart_init(19200);
//Soft_Uart_Init(PORTc, 5, 4,9600, 0); // döngu içine aabiliriz
delay_ms(700); // olmazsa usart_init çalışmıyo// olmazsa usart_init çalışmıyo // Turn off cursor
saat_oku;
if ((ay=10) and (gun>25) and (day=2)and (saat=2)) or ((ay=11) and (gun=1) and (day=2)and (saat=2))
then
begin
saat_yaz( sn, dk, saat, gun, ay, yil );
end;
if ((ay=3) and (gun>25) and (day=2)and (saat=1)) or ((ay=4) and (gun=1) and (day=2)and (saat=1))
then
begin
saat:=2;
saat_yaz( sn, dk, saat, gun, ay, yil );
end;
sn:=0; dk:=50; saat:=16; gun:=9; ay:=6; yil:=09;
saat_yaz( sn, dk, saat,gun, ay, yil);
ana:
giris;
goto ana;
end.

ta1dr
Posts: 40
Joined: 19 Apr 2005 06:47

#2 Post by ta1dr » 10 Jul 2009 13:45

SDA ve SCL pinlerine pull up dirençc takdınızmı?
eger kodlarınızda sorun yoksa çalışacakdır

titan66
Posts: 18
Joined: 11 Mar 2009 11:00

#3 Post by titan66 » 10 Jul 2009 14:11

evt taktım simulasyondada çalışmıyor saat_oku kısmında sorun olabilirmi?

ta1dr
Posts: 40
Joined: 19 Apr 2005 06:47

#4 Post by ta1dr » 10 Jul 2009 14:34

pascal dan anlamıyorum sonuçda birbirine benziyor ama şu noktalama işaretleri beni cok yanıltıyor sim de pinlerde değişiklik oldugunu görebiliyomusun veya donanım da lojik probe yada skopda pinlerdeki durum nedir?
dirençler 10k dan büyük olmasın genelde 4k7 yeterli geliyor

birde her fonksiyonda config yapmana gerek yok sadece main de config yapman yeterli en azından basicde ben öyle kullanıyorum

titan66
Posts: 18
Joined: 11 Mar 2009 11:00

#5 Post by titan66 » 13 Jul 2009 09:00

hallettim sorunu ilgin için teşekkür ederim saol.

Post Reply

Return to “mikroPascal General”