I know that if we want to display the pc time, we will use the below coding:
System.Windows.Forms.Timer tmr = null;
private void StartTimer()
{
tmr = new System.Windows.Forms.Timer();
tmr.Interval = 1000;
tmr.Tick += new EventHandler(tmr_Tick);
tmr.Enabled = true;
}
void tmr_Tick(object sender, EventArgs e)
{
textBox6.Text = DateTime.Now.ToString("dd/MM/yy HH:mm:ss");
}
private void Form1_Load(object sender, EventArgs e)
{
StartTimer();
}
But I do not want to display the pc time. I want to display another time (the rtc time from microcontroller for my case).
If I get the rtc time from serial port and displayed into the text box as “09:00:00”. It is just static there right? How do I get it to run/increment on the text box?
I’ve tried the below which I modified from above coding:
System.Windows.Forms.Timer rtc = null;
private void StartRTC()
{
rtc = new System.Windows.Forms.Timer();
rtc.Interval = 1000;
rtc.Tick += new EventHandler(rtc_Tick);
rtc.Enabled = true;
}
int i = 1;
DateTime dt = new DateTime();
void rtc_Tick(object sender, EventArgs e)
{
textBox17.Text = dt.AddSeconds(i).ToString("HH:mm:ss");
i++;
}
But the time showed on my text box always start increment on 00:00:00.
How do I let it to start increment on the time I get from my microcontroller rtc?
That’s because you’re starting with
new DateTime()and so you’re getting and default value of a newDateTimeclass. You should initialize the value of theDateTimewith the API call to the microprocessor.Example
Please note because I know nothing about the API for your microprocessor I can only write psuedo-code. In your second example, replace the following line…
with…
Edited based off of last comment