B4R Question MCP79410 RTC code

serkanpolat

Member
Licensed User
Longtime User
i need to 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..
 

serkanpolat

Member
Licensed User
Longtime User
ok here is the result :)

thank you very much erel :)



nixie.jpeg
 
Upvote 0

serkanpolat

Member
Licensed User
Longtime User
this is a nixe tube watch prototype :)
nixie tubes are very rare items from 1960's.. in those times , there were no display and lcd etc so they used neon tubes to display numbers.
some of crazy people like me, found those tubes and started to build watch, clock etc.. (i have 10 x 4 different types of these tubes, found from ukrain and russian street bazaars)
they are in different sizes, this is the smallest one, its 1.5 cm height. but it can be 8 cm as well..

we installed ardunio system to a pic processor, then i tried to use b4r instead of using c :)
it have an 3-axis accelerometer , 3v to 170v transformator, and rtc :)
when you move your hand to your face, it will show the clock and seconds :)

here is a sample finished item made by cathode corner :)
maxresdefault.jpg
 
Upvote 0

serkanpolat

Member
Licensed User
Longtime User
one more stupid question:
i couldn't find a way to set PORTB and PORTC
so i used native methods

B4X:
Private Sub setLED(a As Int,b As Int)
    RunNative("secondsleft",a)
    RunNative("secondsright",b)
End Sub
#if C
void secondsleft(B4R::Object* o){
PORTC=o->toULong();
}
void secondsright(B4R::Object* o){
PORTB=o->toULong();
}
#End if

is there any easier way , or is this ok?
 
Upvote 0
Top