• 0

Question

Right, I don't know if I'm being stupid or what but I'm reading the time from an RTC chip via I2C and storing it in an array, and then processing it as below... For some reason, Data[8] shows the seconds fine but Data[0] always shows 0, but I can't really see why? Am I doing something wrong or is this a bug?

while (i < 7)
{
IdleI2C();
Data[i] = ReadI2C();
++i;
}

Data[8] = Data[0] & 0b01111111;
Data[0] = Data[0] & 0b01111111; //Seconds
Data[1] = Data[1] & 0b01111111; //Minutes
Data[2] = Data[2] & 0b01111111; //Hours
Data[3] = Data[3] & 0b00000111; //Days
Data[4] = Data[4] & 0b00111111; //Date
Data[5] = Data[5] & 0b00011111; //Month
Data[6] = Data[6] & 0b00011111; //Year
Data[7] = Data[7] & 0b00011111; //Control

Data[0] = ((Data[0] & 0b01110000)>>4)*10 + (Data[0] & 0b00001111);
Data[1] = ((Data[1] & 0b01110000)>>4)*10 + (Data[1] & 0b00001111);
if ((Data[2] & 0b01000000) == 0b01000000)
{
    //24 hour
    Data[2] = ((Data[2] & 0b00110000)>>4)*10 + (Data[2] & 0b00001111);
}
else
{
    //12 hour
    Data[2] = ((Data[2] & 0b00010000)>>4)*10 + (Data[2] & 0b00001111);
}
Data[4] = ((Data[4] & 0b00010000)>>4)*10 + (Data[4] & 0b00001111);
Data[5] = ((Data[5] & 0b00010000)>>4)*10 + (Data[5] & 0b00001111);
Data[6] = ((Data[6] & 0b11110000)>>4)*10 + (Data[6] & 0b00001111);
Data[8] = ((Data[8] & 0b01110000)>>4)*10 + (Data[8] & 0b00001111);

sprintf(Bob, "%d%c", Data[2], 128);
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[1], 128);
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[0], 128); //Always shows 0
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[8], 128); //Shows seconds correctly
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[0], 128); //Again, always shows 0
LCDWriteString(&Bob);
LCDPosition(2); //Goes to 2nd line
sprintf(Bob, " %d%c", Data[3], 128);
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[4], 128);
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[5], 128);
LCDWriteString(&Bob);
sprintf(Bob, ":%d%c", Data[6], 128);
LCDWriteString(&Bob);
sprintf(Bob, ",%d%c", Data[8], 128);
LCDWriteString(&Bob);
LCDPosition(1); //Goes back to first line

Link to comment
https://www.neowin.net/forum/topic/1140794-mplabx-xc16-bug/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Yet another bug, this program seems like complete and utter shitware. It's noted for being a C compile, right, I'd call it a BASIC interpretor that ****s up as soon as you throw anything mediocre at it.

DayNumToDay(Data[3], &Bob);
sprintf(Bob, "%s%c", Bob, 128);
LCDWriteString(&Bob);

Works, outputs 'Sun'. The LCDWriteString() routine outputs each character until it finds 128, I was trying with sizeof but it appears that MPLAB doesn't like it for some stupid pathetic reason or other.

DayNumToDay(Data[3], &Bob);
sprintf(Bob, " %s%c", Bob, 128);
LCDWriteString(&Bob);

Doesn't, it messes up the LCD completely and I have to put an 'if (i < 8)...' inside the LCDWriteString otherwise (I presume) it endlessly prints out spaces and never gets to the 128 character. Now, I have absolutely NO IDEA WHAT the addition of a SINGLE SPACE character would do this.

Bob is defined as unsigned char Bob[10];

The only thing I can think is that after the 4th byte it skips to a completely different memory location, which is a complete and utter ****ing joke.

So please someone, enlighten me as to how I'm going wrong or if it's just better to dump this (so far) pathetic 4gb waste of complete tosh into the trashcan and be rid of it forever?

  • 0

I'm unsure of why the code in your first post does not work. It looks like you do the same things to Data[8] that you do to Data[0]. Try simulating the code on your computer using a known-good compiler (like GCC or Clang) by creating a ReadI2C() that gives you some output you would expect from your RTC chip. It will probably also be fairly easy to replace LCDWriteString() with puts() for the purpose of your simulation too. If it still doesn't do what you expect, you can at least run it through GDB to figure out why. If the simulation works right then it might be a compiler bug; you can submit a bug report to Microchip using their ticket system at http://support.microchip.com. Submitting the code to reproduce the bug (and the probably the simulation too) will probably get you a faster response.

As for your second problem, I have also encountered many bugs with sprintf() and family in Microchip's compilers (HI-TECH C for the PIC18F and XC16 for the PIC24F). One I remember in particular caused my program to freeze indefinitely (crash?) every time I tried to printf() a float using "%f". However every time I tried to output the same variable using "%x" it worked. The other floating point format specifiers are not supported by Microchip's printf() (I.E. "%F", "%e", "%E", "%g", "%G"). Although XC16 is based on GCC, its standard library is not based on glibc - its Microchip proprietary - and therefore has many bugs. I recommend that you report the bug to Microchip, including code necessary to reproduce it.

This topic is now closed to further replies.
  • Posts

    • Windows 11 KB5094126 BSODing, freezing, forcing BitLocker lockout, breaks OneDrive, and more by Sayan Sen Microsoft released Windows 11 KB5094126 and KB5093998 last week as the latest Patch Tuesday updates. Following that the company also published the accompanying dynamic updates under KB5094149, KB5095971, and KB5094156. While Microsoft has so far not acknowledged any major problems with the release, some users online are running into problems. These range from OneDrive and Dropbox access issues, BitLocker recovery lockouts, to blue screens and BSODs. The most common one seems to be happening with HP systems wherein affected users say they hit 0xc0430001 BSOD (blue screen of death) error code after the KB5094126 update. We wonder if this could be related to the recent bug we covered on HP devices wherein the ongoing Secure Boot certificate updates are leading to similar issues. While we are not certain, users affected by this issue likely need to ensure that the boot.stl file is included on the installation media (such as a USB installer or ISO), if the above-mentioned dynamic updates are deployed. If this file is missing, computers may fail to boot from the installation media and could display the error 0xc0430001. This STL file is used by Secure Boot to verify that the boot files are trusted, so it must match the same Windows version and system architecture. To ensure the file is included, Microsoft recommends using the Update WinPE script, which automatically updates the image and handles the required files. Alternatively, you can manually copy the boot.stl file from the Windows\Boot\EFI folder on a Windows device and place it in the matching folder on your installation media before deploying the updated image. Aside from blue screening some users also note their systems have been freezing following the update. In the case of the OneDrive and Dropbox access issues, a user figured out that there could be a conflict with UAC. He explained: "Okay, so I did some digging, and in our environment KB5094126 breaks OneDrive and Dropbox in Explorer. I went through all our GPOs and found out that the combination of disabling UAC and having my user being a local admin breaks OneDrive in Explorer. ... If I enable UAC again, then it works, even with KB5094126 still installed." Hopefully, Microsoft will look into these issues. Source: Microsoft forum (link1, link2, link3, link4), Reddit (link1, link2, link3)
    • It is when it's a desktop in my house though for a PC that's lightly used and not really important when it is. If it was a laptop, it would be a different story. The real solution is varied and begins starting at post #22 in that thread.
    • Win11Debloat 2026.06.14 by Razvan Serea Win11Debloat is a lightweight, easy to use PowerShell script that allows you to quickly declutter and customize your Windows experience. It can remove pre-installed bloatware apps, disable telemetry, remove intrusive interface elements and much more. The script also includes many features that system administrators and power users will enjoy. Such as a powerful command-line interface, support for Windows Audit mode and the option to make changes to other Windows users. All changes made by Win11Debloat can be easily reversed, and most removed apps can be restored via the Microsoft Store. A full guide on how to undo the changes is available here. Win11Debloat features: Below is an overview of the key features and functionality offered by Win11Debloat. Please refer to the wiki for more information about the default settings preset. Remove a wide variety of preinstalled apps. Click here for more info. Disable telemetry, diagnostic data, activity history, app-launch tracking & targeted ads. Disable tips, tricks, suggestions & ads across Windows. Disable Windows location services & app location access. Disable Find My Device location tracking. Disable 'Windows Spotlight' and tips & tricks on the lock screen. Disable 'Windows Spotlight' desktop background option. Disable ads, suggestions and the MSN news feed in Microsoft Edge. Hide Microsoft 365 ads on the Settings 'Home' page, or hide the 'Home' page entirely. Disable & remove Microsoft Copilot. Disable Windows Recall. Disable Click to Do, AI text & image analysis tool. Prevent AI service (WSAIFabricSvc) from starting automatically. Disable AI Features in Edge. Disable AI Features in Paint. Disable AI Features in Notepad. Disable the Drag Tray for sharing & moving files. Restore the old Windows 10 style context menu. Turn off Enhance Pointer Precision, also known as mouse acceleration. Disable the Sticky Keys keyboard shortcut. Disable Storage Sense automatic disk cleanup. Disable fast start-up to ensure a full shutdown. ...and more. Once you’ve downloaded the Win11Debloat file (Get.ps1), just follow these quick steps: Locate the Get.ps1 script file. Right-click the file and select Run with PowerShell from the context menu. If prompted by User Account Control (UAC), select Yes to grant the script the necessary administrative permissions. Win11Debloat 2026.06.14 changes: This is a minor release that hopefully addresses the false positives in Windows Defender and Bitdefender that prevented users from downloading and/or running Win11Debloat. Refactor Get-RegFileOperations.ps1 to address false positives by @Raphire in #626 Add logging around WinGet app retrieval and increase timeout to 20s by @Raphire Download: Win11Debloat 2026.06.14 | Open Source View: Win11Debloat Home Page | Screenshots 1| 2 Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Still using Microsoft Money 2005 in 2026 here!
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      139
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      82
  • Tell a friend

    Love Neowin? Tell a friend!