i need to convert this code , help needed..
here what i converted:
i am not sure ReadRTCByte code is true..
but i could not convert this code:
help needed..
B4X:
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop(){
WriteRTCByte(0,0); //STOP RTC
WriteRTCByte(1,0x18); //MINUTE=18
WriteRTCByte(2,0x11); //HOUR=11
WriteRTCByte(3,0x09); //DAY=1(MONDAY) AND VBAT=1
WriteRTCByte(4,0x28); //DATE=28
WriteRTCByte(5,0x02); //MONTH=2
WriteRTCByte(6,0x11); //YEAR=11
WriteRTCByte(0,0x80); //START RTC, SECOND=00
delay(100);
while(1){
Serial.print("20"); //year beginning with 20xx
DisplayRTCData(6,8);
Serial.print(".");
DisplayRTCData(5,5);
Serial.print(".");
DisplayRTCData(4,6);
Serial.print(" ");
DisplayRTCData(2,6);
Serial.print(":");
DisplayRTCData(1,7);
Serial.print(":");
DisplayRTCData(0,7);
Serial.println();
delay(1000);
}
}
unsigned char ReadRTCByte(const unsigned char adr){
unsigned char data;
Wire.beginTransmission(0x6f);
Wire.write(adr);
Wire.endTransmission();
Wire.requestFrom(0x6f,1);
while (Wire.available()) data=Wire.read();
return data;
}
void WriteRTCByte(const unsigned char adr, const unsigned char data){
Wire.beginTransmission(0x6f);
Wire.write(adr);
Wire.write(data);
Wire.endTransmission();
}
void DisplayRTCData(const unsigned char adr, const unsigned char validbits){
unsigned char data;
data=ReadRTCByte(adr);
data=data & 0xff>>(8-validbits);
if (data<10) Serial.print("0"); //leading zero
Serial.print(data,HEX);
}
here what i converted:
B4X:
Sub Process_Globals
Public Serial1 As Serial
Public pin1 As Pin
Public wm As WireMaster
Public rtcAdress As Int = 0x6f
EndSub
Private Sub AppStart
'mcp79410
Serial1.Initialize(9600)
pin1.Initialize(8,pin1.MODE_OUTPUT)
pin1.Initialize(9,pin1.MODE_OUTPUT)
pin1.Initialize(10,pin1.MODE_OUTPUT)
pin1.Initialize(11,pin1.MODE_OUTPUT)
pin1.Initialize(14,pin1.MODE_OUTPUT)
pin1.Initialize(15,pin1.MODE_OUTPUT)
pin1.Initialize(16,pin1.MODE_OUTPUT)
pin1.Initialize(17,pin1.MODE_OUTPUT)
wm.Initialize
WriteRTCByte(0,0) 'STOP RTC
WriteRTCByte(1,0x18) 'MINUTE=18
WriteRTCByte(2,0x11) 'HOUR=11
WriteRTCByte(3,0x9) 'DAY=1(MONDAY) And VBAT=1
WriteRTCByte(4,0x28) 'DATE=28
WriteRTCByte(5,0x11) 'MONTH=11
WriteRTCByte(6,0x16) 'YEAR=16
WriteRTCByte(0,0x80) 'START RTC, SECOND=00
Delay(100)
Log("AppStart")
AddLooper("Looper")
EndSub
Sub Looper()
dim seconds as byte =ReadRTCByte(0)
'how to convert it ??
End sub
Private Sub WriteRTCByte(adres As Byte,data As Byte)
wm.WriteTo(rtcAdress,Array As Byte(adres,data))
EndSub
Private Sub ReadRTCByte(adres As Byte) As Byte
wm.WriteTo(rtcAdress,Array As Byte(adres))
Dim b() As Byte=wm.RequestFrom(rtcAdress,1)
raf.Initialize(b,True)
Return raf.ReadByte(raf.CurrentPosition)
EndSub
i am not sure ReadRTCByte code is true..
but i could not convert this code:
B4X:
void DisplayRTCData(const unsigned char adr, const unsigned char validbits){
unsigned char data;
data=ReadRTCByte(adr);
data=data & 0xff>>(8-validbits);
if (data<10) Serial.print("0"); //leading zero
Serial.print(data,HEX);
}
help needed..