• 0

Question

So I've been using GPUtils for a few weeks now, used to use MPASM back in the day on windows but I have to say I really like GPUtils.

So I've been playing around with this PIC 18F4520 IC I have and have been writing a pretty large program (in terms of pages). I've been frustrated for a whole day now on why a function won't work and has undesirable behaviour - returns 0 or crashes or resets the PIC... Then I realised something - the code was too long for one page and I've been coding in the next page without knowing it.

So (this is all reloctable code - NOT absolute) I read up on using BANKSEL and PAGESEL in GPUtils... Unfortunately, it appears to do buggar all, I'm not sure if I'm using it wrong or if features is bugged and just isn't working. This is the code I'm using (from the lst to see the addresses):

000288   0b0f	 andlw   0xf			  ANDLW b'00001111'
										   PAGESEL 400h
										   PAGESEL FUNC
00028a   ec00	 call    0x400, 0		 CALL FUNC
00028c   f002
										   PAGESEL $
00028e   0100	 movlb   0			    BANKSEL d2
.....
										   org 0x400

000400   010f	 movlb   0xf			  FUNC BANKSEL PCL
										   PAGESEL $
000402   6e02	 movwf   0x2, 0		   movwf d1
000404   0e04	 movlw   0x4			  movlw b'00000100'

And as can be seen - PAGESEL is doing nothing if I provide it with the function name or an address, I have to alter the PCLATH register manually as if I'm using absolute assembly which is a bit dumb and will always vary depending on what's added or what it's linked with or if anything is changed so I'm unsure if I'm doing something wrong or if I need to report a bug.

(Compiling using: gpasm -c 18f4520LCD.asm, linking using: gplink -m -c -s /usr/share/gputils/lkr/18f4520.lkr -o 18f4520LCD 18f4520LCD.o)

Anyone else got GPUtils, a programmer and can see if this is happening when they try this?

Thanks!

Link to comment
https://www.neowin.net/forum/topic/1133852-gputils-pic-bug/
Share on other sites

Recommended Posts

  • 0

I'm much more familiar with the PIC 18F242 than the 18F4520, but I assume their instruction set is similar. It looks like you are completely disregarding the BSR (Bank Select Register) in your code. You are setting it with instructions such as movlb 0xf, then disregarding that value with movwf 0x2, 0. According to the PICmicro Quick Reference Chart:

RAM access bit

a = 0: RAM location in Access RAM (BSR register is ignored)

a = 1: RAM bank is specified by BSR register (default)

Hex: 6Ff*

Mnemonic: MOVWF f,a

Description: Move WREG to f

Function: WREG ? f

Just out of curiosity, why did you choose to program this project in assembly instead of C? SDCC is a good FOSS C compiler for the PIC18 that is undergoing rapid development. (Check out the SDCC SVN repo if you're interested.) If you would rather have a commercial compiler, the HI-TECH C compiler for the PIC18 is also excellent.

  • 0

Actually, that is the assembler, there is no movlb in the actual code file

PAGESEL 800h
CALL FUNC
PAGESEL $
BANKSEL d2
movwf d2
....
org 0x400
FUNC BANKSEL PCL
PAGESEL $
movwf d1
movlw b'00000100'

So quite what is going on... *shrug* I've not a clue.

Never been a fan of C on PICs, I like to know what they're actually doing... Or attempt, found some I2C 24c16 that reads/programs fine with a JDM programmer but using my own I2C implementations and loads off the 'net using custom methods and using the actual in-built I2C commands - None worked! There's a lot of I2C C examples for PIC chips on the net that consist of something like

I2CStart();

I2CRead('1010000');

I2CWrite();

...Fair enough you can write fast code but what the hell is actually going on? Same as on a PICAXE, well, I find PICAXE worse for it's got a bootloader running, all the time, so anything that's timing critical or to be very optimised will never be optimised.

EDIT: Just seen that SDCC project supports HC08, got an HC11 which appears to be backward compatible that I was slowly going to move on to, might give it a blast on that to see if/how it works :D

Edited by n_K
  • 0

C is very advantageous because it allows you to program the controller faster. I agree that its certainly possible to program the PIC18 in C and not understand what its doing underneath, but just because you program it in C doesn't necessarily mean that you don't! Knowing the instruction set means you understand that 16-bit and signed variables have higher overhead, float is not supported in hardware so it should be used sparingly (if at all), and there are only three pointer registers. That's why its probably best to learn assembly first, but I wouldn't rely on it for anything super complicated.

On a side note, I have working I2C code that I wrote to communicate between the PIC18 and a serial EEPROM. (In C, of course! I'm just insane, not a masochist.) It uses the PIC18's built-in I2C functions and relies on no third-party code. I will send it to you if you're interested.

Actually, that is the assembler, there is no movlb in the actual code file

Maybe you should consider invoking movlb and movwf directly then. Even if you are not writing those commands at the moment, it is happening according to the code you posted.

Also, doesn't using directives that expand into multiple assembly instructions somewhat defeat the reason why you're using assembly instead of C?

  • 0

This is the problem though, because it's relocatable code, if I mix another library with it or even if I don't, it's a mis-match of things and so unless I specifically put the address in - I don't know where it'll be nor what bits to set when using one function from another. I only spotted why this was going wrong by accident in gpsim, seeing it be fine at address 400 then come to an increment of PCL and suddenly jump to instruction 6 out of the blue - then saw the PCLATH and PCLATU registers - set them manually and it works fine but I shouldn't have to set them manually - gpasm and gplink should be doing that with the pagesel/banksel instructions as far as I'm aware, so I'm not sure if I'm doing it wrong or if the program is bugged and I'd feel a complete tool to sign up to sourceforge to report this problem if it isn't a bug :(. [There was also no RTL/RRL instruction present, for some reason it's 'rrcf' and 'rlcf' :s again not sure if it's a bug]

I've tried using the internal I2C functions too but this EEPROM (there's no spec sheet either for this exact model, 24c16 (Not 16A! And not atmel!) by and the 18f4520 just don't like each other for some reason. I've got a 16f88 I might try with it sometime but I also found a 93c46n that works brilliantly and prefer having seperate SDO and SDI lines :D

  • 0

I've tried using the internal I2C functions too but this EEPROM (there's no spec sheet either for this exact model, 24c16 (Not 16A! And not atmel!) by and the 18f4520 just don't like each other for some reason. I've got a 16f88 I might try with it sometime but I also found a 93c46n that works brilliantly and prefer having seperate SDO and SDI lines :D

I have the 24LC515. There are a couple important considerations, but do you have 10K pull-up resistors on your SCL and SDA lines? Also, are you sure you have the address right? On my EEPROM, the A0, A1, and A2 pins determine the user-defined part of the address, which must be included with the static device address. If you don't have the datasheet and don't know the device address, you could always try brute-forcing it by trying every address until one is accepted. (Since its only 8 bits that shouldn't take very long.) You would need to be sure everything else was correct for that to actually work, though.

  • 0

10k!? No! I've tried 3.8K and 2.2K.

The address is the problem, well, might be... The atmel 16a spec sheet says it has no address pins and it's forced to 000 but I grounded them anyway.

The first time I tried just doing my own 'brute force' attempty at the whole I2C thing and copied atmel's waveforms (not using the in-built I2C lines) and it did kind of work, and by kind-of I mean sporatically (it was not running at 100KHz, it was running using LEDs so I could see it, so very slow). If I powered the device on 20 times, say, 5 times the EEPROM would respond with the data, some of those times it would be delayed by a few clocks, but the other 15 or so times it wouldn't do anything, but the JDM programmer for the PC reads the chip fine each time!

EDIT: Or would it? Might be getting confused between the 93c46n and the 24c16 here actually as to if it even replied properly. Don't think it did actually.

  • 0

The datasheet for my EEPROM says the I2C speed should be between 100 - 400 KHz, so I set mine to 350 KHz. Like I already mentioned, I put a 10K pull-up resistor on the SCL and SDA lines. I used 0xA0 as my address because my static device ID is 1010, my user-configurable ID pins are all grounded (000), and I want to write by default (0). Since the PIC18 is big-endian, my 8-bit address is 10100000 (0xA0) when I want to write and 10100001 (0xA1) when I want to read. Obviously it will be a little different depending on the EEPROM chip you're using, but maybe my configuration will help.

  • 0

Here's one attempt I tried which literally just hammered the data out at a slow speed (so I could see the LEDs):

;RB0 = CLK
;RB1 = OUT/IN
;START
movlw   b'00000011'
movwf   LATB
call Delay
movlw   b'00000001'
movwf   LATB
call Delay
movlw   b'00000000'
movwf   LATB
call Delay
;/START
;DATA
;101000010
movlw   b'00000011'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000011'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000011'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
;/DATA
bsf LATD, 0
call Delay
call Delay

;CHECK
movlw   b'00000010' ;RB1 now an input
movwf   TRISB
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
;/CHECK
bcf LATD, 0

;STOP
movlw   b'00000001'
movwf   LATB
call Delay
movlw   b'00000011'
movwf   LATB
call Delay
movlw   b'00000000'
movwf   LATB
call Delay
;/STOP

goto Start

Another one I quickly attempted using the actual PIC I2C functions:

movlw b'00000000'
movwf INTCON
movwf INTCON2
movwf INTCON3
movwf ADCON0
movlw b'00001111'
movwf ADCON1
movwf CMCON
movlw b'00000000'
movwf RCON
movwf PIR1
movwf PIR2
movwf PIE1
movwf PIE2
movwf IPR1
movwf IPR2
movwf CMCON
movwf CVRCON
movlw b'00000000'
movwf SSPADD
movlw b'10000000'
movwf SSPSTAT
movlw b'00001000'

movwf SSPCON1
movlw b'00000000'
movwf SSPCON2
call Delay
BSF SSPCON1, 5
call Delay
BSF PIR1, 3
call Delay
BSF SSPCON2, 0
BSF PIR1, 3
call Delay
;movlw b'11010000'
movlw b'110100000'
movwf SSPBUF
BCF SSPCON2, 6
call Delay
call Delay
movf SSPBUF, w
movwf LATA
BSF SSPCON2, 6
call DelayL
movlw b'110100000'
movwf SSPBUF
BCF SSPCON2, 6
call Delay
call Delay
swapf SSPBUF, w
movwf LATA
sleep

Now I look I've not a clue about the 1101... movlw, it's got 9 bits :s. And the other one I tried was just basically nicked from http://nnp.ucsd.edu/phy120B/0_pic_asm_files/i2c_CFD.asm though I changed it to remove the 2nd lot of addressing as the 24c256 has 16-bit addresses that the 24c16 and below don't.

But yes unfortunately none worked. I might have another go at them in the future.... As I'm currently having problems with pagesel in gputils, do you know if there's an official MPASM for linux anywhere?

  • 0

I don't think MPASM was ever released for Linux. However, there is GPL source code available for the MPLAB Assembler and MPLAB C compiler for the PIC24, dsPIC, and PIC32. The existing PIC16 and PIC18 toolchains are completely incompatible with the PIC24 and PIC32 toolchains, so it might not do you any good.

In case you are interested, the C30 source code is buried on a page deep in Microchip's website that looks like something straight out of 1990. There is also some discussion of building an older version of the compiler for Debian on the Microchip user forums. The Debianized source is quite old and not in the modern Debian packaging format, but the debian/control and debian/patches/* should get you started if you want to build the current version of C30 for Debian or some other Linux distribution. Good luck!

Edit: I just discovered something. If you install the free (but not FOSS) MPLABX in Linux, it will install MPASM. MPLABX 1.60 installed MPASM 5.48 as /opt/microchip/mplabx/mpasmx/mpasmx on my machine. Potentially unlike Microchip's ASM30, the version of MPASM installed with MPLABX will work with the PIC18.

  • 0

That, is, insane.

Warning[205]: Found directive in column 1. (PAGESEL)

Message[312]: Page or Bank selection not needed for this device. No code generated.

So... What the hell? Because I've got an 18f4520 I need to manage the PCLATH and PCLATU registers myself? What a heap of ****. I can't believe how pathetic that is! What's the point in having the functions at all then if you can't use them.

  • 0

So I got a DSPIC30F4013 in the mail today... Thought it'd be fun to play around with it in gputils but there appears to be a slight minor drawback; it's not supported in gputils :(.

So I just had a quick look around and saw the HI TECH C compiler that supports it for $850 and some 'csd 24 bit' that supports it for $350... Both are $850 and $350 too expensive for me for playing around with!

Got any suggestions for C compilers ? :p Or heck, even assembly at this point!

  • 0

I just checked the XC16 v1.1 User Manual to make sure that my assumption that the compiler supports your device as well is correct. According to section 1.2:

1.2 DEVICE DESCRIPTION

The MPLAB XC16 C compiler fully supports all Microchip 16-bit devices:

? The dsPIC? family of digital signal controllers combines the high performance required in digital signal processor (DSP) applications with standard microcontroller (MCU) features needed for embedded applications.

? The PIC24 family of MCUs are identical to the dsPIC DSCs with the exception that they do not have the digital signal controller module or that subset of instructions. They are a subset, and are high-performance MCUs intended for applications that do not require the power of the DSC capabilities.

The latest version of the MPLAB XC 16 compiler and user manual can be downloaded here, and the source code can be downloaded here (since the compiler is GCC based). The XC16 C compiler runs perfectly on my Debian 7 (AMD64) installation, so I assume it will work equally as well for you on Arch.

  • 0

Humm, bit of a problem;

/usr//bin/sdcc -mpic16 -V -p18f4520 -DDEBUG --denable-peeps --opt-code-size --optimize-cmp --optimize-df -I. -c i2c_master.c

+ /usr//bin/sdcpp -nostdinc -Wall -DDEBUG -I. -Dpic18f4520 -D__18f4520 -D__SDCC_PIC18F4520 -DSTACK_MODEL_SMALL -D__STACK_MODEL_SMALL -obj-ext=.o -D__SDCC=3_2_1 -DSDCC=321 -D__SDCC_REVISION=8413 -DSDCC_REVISION=8413 -D__SDCC_pic16 -DSDCC_pic16 -D__pic16 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem /usr//bin/../share/sdcc/include/pic16 -isystem /usr/share/sdcc/include/pic16 -isystem /usr//bin/../share/sdcc/include -isystem /usr/share/sdcc/include i2c_master.c

In file included from i2c_master.h:4,

from i2c_master.c:1:

/usr//bin/../share/sdcc/include/pic16/pic18fregs.h:580:26: error: pic18f4520.h: No such file or directory

And the files in that directory;

adc.h delay.h float.h i2c.h malloc.h p18fxxx.inc pic18fregs.h signal.h stddef.h stdio.h string.h

ctype.h errno.h gstack.h limits.h math.h pic16devices.txt sdcc-lib.h stdarg.h stdint.h stdlib.h usart.h

I edited the PKGBUILD and compiled my own SVN version of sdcc but I'm not sure what I'm doing wrong that the files aren't there!

EDIT: Scratch that, downloaded the file off the net and it works, not sure why it isn't included by default though.

New problem! config.h:9: syntax error: token -> 'char' ; column 9

make: *** [main.o] Error 1

#define VERSION 0.1

// Set the __CONFIG words:

code char at __CONFIG1H _conf1 = _OSC_INTIO67_1H

code char at __CONFIG2L _conf2 = _VREGEN_ON_2L & _PUT_ON_2L & _BODEN_OFF_2L;

^ It doesn't seem to like that... And I haven't got a clue what it SHOULD look like :p

Edited by n_K
  • 0

You should set the device configuration using the pragmas documented in the XC16 C compiler manual.

2.5.14 Specifying Configuration Bits

The #pragma config directive may be used to program the configuration bits for a device. The pragma has the form:

#pragma config setting = state|value

#pragma config register = value

where setting is a configuration setting descriptor (e.g., WDT), state is a descriptive value (e.g., ON) and value is a numerical value. The register token may represent a whole configuration word register, e.g., CONFIG1L. Use the native keywords discussed in the Differences section to look up information on the semantics of this directive.

2.5.14.1 EXAMPLE

The following shows configuration bits being specified using this pragma.

#pragma config WDT=ON, WDTPS = 0x1A

If you need to use special function registers - which I'm guessing your probably do - read chapter 4 of the manual. In particular, the following is an excerpt from section 4.6 "using SFRs":

The convention in the processor header files is that each SFR is named, using the same name that appears in the data sheet for the part ? for example, CORCON for the Core Control register. If the register has individual bits that might be of interest, then there will also be a structure defined for that SFR, and the name of the structure will be the same as the SFR name, with ?bits? appended. For example, CORCONbits for the Core Control register. The individual bits (or bit fields) are named in the structure using the names in the data sheet ? for example PSV for the PSV bit of the CORCON register.

I recommend that you have both the datasheet and compiler manual handy until you know your microcontroller and compiler's special features fairly well. My approach is usually to read the datasheet first to learn the neat features specific to my microcontroller, then read the compiler manual so I understand the caveats and best practices recommended by its authors (who presumably know more about the architecture than me). However, if you have to pick just one section of the datasheet or compiler manual to read, "Chapter 2. Common C Interface" should absolutely be it. That chapter will explain enough to get you started, at least.

  • 0

This is sdcc not the official MC compiler.

I can't understand why it won't work, this is using an example from the sdcc forums that another user said works fine on the PIC I'm trying to compile for.

main.c:11: warning 115: unknown or unsupported #pragma directive '__CONFIG1H = _OSC_HS_PLL_1H & _OSCS_ON_1H;' (when it was #pragma __CONFIG1H = _OSC_HS_PLL_1H & _OSCS_ON_1H;)

main.c:11: warning 191: #pragma config: bad argument(s); pragma ignored (when it was #pragma config __CONFIG1H = _OSC_HS_PLL_1H & _OSCS_ON_1H;)

I got the config line I changed to #pragma from another post on their forums :s

  • 0

Does SDCC support the dsPIC? I though it only supported the PIC18.

I have only used the XC16 C compiler with my PIC24, but I have used both the HI-TECH C compiler and SDCC with my PIC18. I can try to find my makefile and some basic source code if you are interested. All I could find off-hand, though, is the configuration I have often used for the PIC18 with HI-TECH C.


#ifndef CONFIG_H
#define CONFIG_H

#include <htc.h>

/* PIC18F242 configuration details */
#pragma config OSC=HSPLL
#pragma config BOR=OFF
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF
#pragma config LVP=OFF

/* Bit manipulation macros suggested by the HI-TECH C manual */
#define bitset(var,bitno) ((var) |= (1 << (bitno)))
#define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
#define bittst(var,bitno) (var & (1 << (bitno)))

#endif // CONFIG_H
[/CODE]

[b]Edit:[/b] OK. I found it. I can't vouch for the completeness of this code and I make no claims that it represents good style or practice, but it [i]does[/i] compile on SDCC 3.2 and run on the PIC18F242. The zip archive with the code is attached to this post.

SDCC_PIC18_SERIALCALC_EX.zip

  • 0

I was compiling and testing for the 18F4520 :p Also got an 18F4550 too now.

I'd like to try out the dspic but unfortunately either the hardware and/or the software fails half way through reading/programming them so I'm actually unable to do anything with them.

  • 0

Right I've got the XC8 free edition and MPLABX installed on this PC, tried compiling the 18F4520 example for an LCD I got and it does compile... Only problem is that it's not starting instructions at 0x0000 and is instead starting at 0x1067... I can't really understand why?

http://www.wvshare.c...-Touch-LCD-A.7z is the code and I converted it from an MPLAB 8.x project, any ideas?

"invalid address 0xf0010f, possibly not hex file for correct pic type?"

"picprog --device=pic18f4520 --erase --burn -i "/tmp/TOUCH.X.production.hex" --jdm --pic /dev/ttyS0

Picprog version 1.9.1, Copyright ? 2010 Jaakko Hyv?tti <[email protected]>

Picprog comes with ABSOLUTELY NO WARRANTY; for details

type `picprog --warranty'. This is free software,

and you are welcome to redistribute it under certain conditions;

type `picprog --copying' for details.

Trying realtime priority 1

Bound to CPU 0

Bound to CPU 1

Bound to CPU 2

Using >1 ?s delays. --rdtsc may work for faster timings.

/tmp/TOUCH.X.production.hex:397:invalid input line."

Line 397 is in bold (lines 395-end):

":107FE80000000000000000000000000057617665F6

:087FF80053686172650000008E

:020000040020DA

:08000000FFFFFFFFFFFFFFFF00

:020000040030CA

:0E000000FF071F1FFF8385FF0FC00FE00F409B

:00000001FF"

Edited by n_K
  • 0

Microcontroller code compiled with an ANSI C compiler never starts at address 0. It uses the reserved space before main() for global and static variables.

Unfortunately I can't look at your code because it doesn't extract properly for me. However, this adafruit LCD tutorial is a good place to start. I also attached my code for a basic calculator using a 4 line 20 character LCD and 4x4 keypad. It compiles using the HI-TECH C compiler (and most likely the XC8 compiler as well, although I haven't tested that). I uploaded it to my PIC18F242 from MPLABX using the PICkit 2.

LCDCalc.zip

  • 0

Right I've found the problem, apparently it's because MPLAB is (crap) writing 'odd byte counts' to save space or something, and someone wrote a program (fixhex3) to fix the problems but appears it's a private release or something.

So I have absolutley no idea how to make MPLABX create proper files or how to change invalid files into proper ones either :s

  • 0

Right I got it programmed, having to use picpgm as picprog doesn't support the 'odd byte count' programming type by picpgm does, the downside to using picpgm is that it takes absolutely ages to write, and verifying... WOW... I've got it not verifying as it took over 30 second to verify :(.

But I've got an incredibly strange action from this code, I've tried a 3.4Mhz oscillator, 8Mhz oscillator and 20Mhz oscillator - they all seem to run the code at the same speed, even tried reducing the values in the loop functions - and the program doesn't speed up AT ALL, it is absolutely crazy :s.

  • 0

Wow, I can't actually believe it :o.

Got an 18LF4520 reading data from an RTC using C, and, it works!

Unbelievable! (Well, I've got it setting LEDs depending on what the seconds are) but heck it's astonishing to be able to write that in 20 lines of code instead of 300 or so, though it does seem to be compiling it to inefficient code;

Program space used 348h ( 840) of 8000h bytes ( 2.6%)

Data space used 15h ( 21) of 600h bytes ( 1.4%)

Ah well, that's nifty!

  • 0

Right actually it's not working... And I've no idea why! It's getting back straight 1s.

Here's the code I kinda 'converted' it from;

  RTC_t rtc;
  I2C_start();    // START
  I2C_out_byte(0xD0);   // DS1307 hardware address + write command
  I2C_sack();	 // slave ACK
  I2C_out_byte(0x00);   // we will read from this address
  I2C_sack();	 // slave ACK
  I2C_start();	 // repeated START
  I2C_out_byte(0xD1);   // DS1307 hardware address + read command
  I2C_sack();	 // slave ACK
  rtc.sec = I2C_in_byte();   // read sec
  I2C_ack();	 // master ACK
  rtc.min = I2C_in_byte();   // read min
  I2C_ack();	 // master ACK
  rtc.hour = I2C_in_byte();  // read hour
  I2C_ack();	 // master ACK
  rtc.dweek = I2C_in_byte();  // read dweek
  I2C_ack();	 // master ACK
  rtc.day = I2C_in_byte();  // read day
  I2C_ack();	 // master ACK
  rtc.month = I2C_in_byte();  // read month
  I2C_ack();	 // master ACK
  rtc.year = I2C_in_byte();  // read year
  I2C_nack();	 // master NACK

And here's my code;

#define I2C_V2 true
#include &lt;plib/i2c.h&gt;
    int Data[6];
    OSCCON = 0b10100011;
    TRISC = 0x00; // turn on tri-state register and
				 // make all output pins
    PORTC = 0x00; // make all output pins LOW
    TRISA = 0x00;
    PORTA = 0xFF;
    OpenI2C( MASTER, SLEW_OFF);
    __delay_ms(90);
    __delay_ms(90);
    __delay_ms(90);
    PORTA = 0x00;
    SSPADD = 0x3F;
    StartI2C();
    IdleI2C();
    WriteI2C( 0xD0 );  // sends address to the
    IdleI2C();
    WriteI2C( 0x00 );
    IdleI2C();
    StopI2C();

    StartI2C();
    IdleI2C();
    WriteI2C( 0xD1 );  // sends address to the
    IdleI2C();
    WriteI2C( 0x00 );  // sends address to the
    IdleI2C();
//    RestartI2C();
    Data[0] = ReadI2C();
    IdleI2C();
    AckI2C();
    IdleI2C();
    Data[1] = ReadI2C();
    IdleI2C();
    AckI2C();
    IdleI2C();
    Data[2] = ReadI2C();
    IdleI2C();
    AckI2C();
    IdleI2C();
    Data[3] = ReadI2C();
    IdleI2C();
    AckI2C();
    IdleI2C();
    Data[4] = ReadI2C();
    IdleI2C();
    AckI2C();
    IdleI2C();
    Data[5] = ReadI2C();
    IdleI2C();
    AckI2C();
    IdleI2C();
    Data[6] = ReadI2C();
    IdleI2C();
    NotAckI2C();
    IdleI2C();
    StopI2C();
    PORTA = Data[0];
    __delay_ms(90);
    __delay_ms(90);
    __delay_ms(90);
    __delay_ms(90);
    PORTA = 0;
    __delay_ms(90);
    __delay_ms(90);
    __delay_ms(90);
    __delay_ms(90);
    PORTA = Data[1];
    Sleep();

Any ideas?

This topic is now closed to further replies.
  • Posts

    • So how did you solve the problem? Disabling Secure Boot isn’t a solution.
    • Another devilish issue surrounding these certificates is what can happen with old, unsuspecting PCs that nevertheless have Secure Boot enabled. In my case, it was a Dell with a 3rd-gen Core chip (so about 13 years old). As of the last few weeks, it was suddenly BSOD'g within about 5 minutes of booting. Turns out it was because of MS's "Secure-Boot-Update" scheduled task, which is scheduled to run 5 minutes after login. It's explained in gory detail here (this is not my post, but it was where I found the answer), but the short version is that this legacy system would need fairly elaborate, manual certificate intervention since MS's automatic cert update method cannot work. How to do that is linked late in the thread. https://www.bleepingcomputer.c...od-caused-by-scheduled-task Secure Boot wasn't at all important for this particular PC, so I disabled it to be done with the problem.
    • Winhance 26.06.12 by Razvan Serea Winhance is an open-source Windows enhancement utility designed to help users debloat, optimize, and customize Windows 10 and 11. It provides a user-friendly interface for removing unwanted apps, legacy components, and optional features safely, giving you more control over your system. With Winhance, you can improve performance, reduce clutter, and enhance privacy without the need for a clean install. Beyond basic debloating, Winhance offers extensive optimization tools. Users can tweak power plans, adjust gaming and performance settings, control notifications, and manage Windows Update behavior. Privacy-focused settings allow you to limit telemetry and data collection, while system customization options let you personalize the taskbar, Start menu, Explorer, and Windows themes. Winhance also supports installing or removing software efficiently, including external apps via WinGet integration, streamlining both new setups and daily maintenance. New AI privacy groups have been added for Windows AI, Microsoft Edge AI, and Microsoft Office AI, giving users clearer control over AI-related telemetry and feature usage. In addition, new settings in Gaming & Performance introduce AI taskbar pin toggles, options to remove AI apps, and controls for AI services and scheduled tasks, allowing users to better manage how AI components run in the background and appear in the system. For advanced users and IT professionals, Winhance integrates WIMUtil, a tool for creating custom Windows installation ISOs with automated configuration. You can generate autounattend.xml files, inject drivers, and apply your chosen Winhance settings automatically during installation. Most changes are non-destructive and reversible, with clear explanations in the GUI. Whether you’re optimizing a single PC or managing multiple systems, Winhance delivers a faster, cleaner, and highly personalized Windows experience. The Winhance.Installer.exe includes both Installable and Portable versions during setup. Winhance supports both Windows 10 and Windows 11 64-bit versions. It's regularly updated to ensure compatibility with the latest Windows updates and features. Winhance key features: Debloat Windows – Safely remove unwanted apps, features, and legacy components. Optimize Performance – Tune system settings for speed, responsiveness, and gaming. Privacy Enhancements – Control telemetry, data collection, and notifications. Power Management – Configure power plans and advanced energy settings. Windows Update Control – Adjust update behavior for stability and convenience. Theme Customization – Switch between light/dark mode and adjust system colors. Taskbar & Start Menu Tweaks – Modify layout, icons, and behavior. Explorer Customization – Adjust file explorer appearance and functionality. Software Management – Install/remove Windows apps and optional features. External Apps Installation – Deploy essential apps via WinGet integration. Configuration Management – Save, export, and import Winhance settings easily. Automation with WIMUtil – Create custom Windows ISOs with integrated settings. Autounattend.xml Generator – Automate Windows installations with preconfigured options. Driver Integration – Include current system drivers in custom ISOs. Non-Destructive Changes – Reversible settings with clear explanations in the GUI. Winhance 26.06.12 changelog: Features Builder Mode — build a Winhance config file or autounattend.xml without changing anything on the PC you're sitting at. Flip the new mode switcher to Builder, set everything the way you want it, and save the result as a Winhance config or an autounattend file ready for deployment on other machines. Sponsors & Supporters page — the exit donation dialog is gone. In its place, an in-app page (heart icon or the More menu) recognizes the businesses and individual supporters who keep Winhance free. It works offline and is fully localized. Change History — Winhance now keeps a receipt of everything it does. ChangeHistory.txt records every setting change (before and after values) and every app install or removal, with clear headers for config imports and bulk actions. Open it from the More menu. Hebrew language support — Winhance is now available in 29 languages. New Explorer customizations: desktop icon visibility toggles, This PC folder visibility, an icon cache size setting, and automatic thumbnail cache cleanup. New "All apps view" setting for the redesigned Windows 11 Start menu, and the Windows 11 system tray icons setting is now a dropdown with more control. App-local UI zoom — press Ctrl +/-/0 or use Ctrl+MouseWheel to scale the whole app, just like a browser. New External Apps: EA app, Ubisoft Connect, Battle.net, Rockstar Games Launcher, PowerShell, and Helium Browser. Bug Fixes Layouts no longer clip when the Windows text size slider is set above 100%. Accessibility: Narrator now announces setting names on toggles and dropdowns, previously unlabeled buttons are labeled, and progress updates are announced. Silent updates now respect your custom install location instead of reverting to the default. Cancel in Review Mode no longer clears your app selections. OneNote is now detected correctly for Win32 Click-to-Run installs. Clean Start Menu applies more reliably by also writing the group policy path. WinGet errors are no longer silent — error details now show in the terminal output. Fixed a startup crash on older Windows builds caused by a .NET runtime regression. Config import now converts power setting values correctly and no longer re-applies an already-active power plan. Improvements App icons load noticeably faster and cover almost everything now, including legacy capabilities and optional features — they come from a dedicated, checksum-validated icon repository and are fetched in parallel. Software & Apps polish: per-icon tooltips, extra table columns, an app sort dropdown, relocated search, and a cleaner compact view. A warning now appears when the Connected Devices Platform Service is set to Manual or Disabled, since some Windows features depend on it. Download: Winhance 26.06.12 | 61.5 MB (Open Source) Links: Winhance Website | Github | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Microsoft Windows 11 Pro and Office Home & Business 2024 is still 69% off by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can save 69% on Windows 11 Pro + Microsoft Office Home & Business 2024. Upgrade your computing experience with Windows 11 Pro. This cutting-edge operating system boasts a sleek new design and advanced tools to help you work faster and smarter. From creative projects to gaming and beyond, Windows 11 delivers the power and flexibility you need to achieve your goals. With a focus on productivity, the new features are easy to learn and use, enhancing your workflow and efficiency. Whether you're a student, professional, gamer, or creative, Windows 11 Home has everything you need to take your productivity to the next level. New interface. easier on the eyes & easier to use Biometrics login*.Encrypted authentication & advanced antivirus defenses DirectX 12 Ultimate. Play the latest games with graphics that rival reality. DirectX 12 Ultimate comes ready to maximize your hardware* Screen space. Snap layouts, desktops & seamless redocking Widgets. Stay up-to-date with the content you love & the new you care about Microsoft Teams. Stay in touch with friends and family with Microsoft Teams, which can be seamlessly integrated into your taskbar** Wake & lock. Automatically wake up when you approach and lock when you leave Smart App Control. Provides a layer of security by only permitting apps with good reputations to be installed Windows Studio Effects. Designed with Background Blur, Eye Contact, Voice Focus, & Automatic Framing Touchscreen. For a true mouse-less or keyboard-less experience TPM 2.0. Helps prevent unwanted tampering Windows 11 Pro also includes a number of productivity-focused features, such as the ability to snap multiple windows together and create custom layouts, improved voice typing, and a new, more powerful search experience. Personal and professional users will enjoy a modern and secure computing experience, with improved performance and productivity features to help users get more done. Only on Windows 11 Pro If you require enterprise-oriented features for your daily professional tasks, then Windows 11 Pro is a better option. Set up with a local account (only when set up for work or school) Join Active Directory/Azure AD Hyper-V Windows Sandbox Microsoft Remote Desktop BitLocker device encryption Windows Information Protection Mobile device management (MDM) Group Policy Enterprise State Roaming with Azure Assigned Access Dynamic Provisioning Windows Update for Business Kiosk mode Maximum RAM: 2TB Maximum no. of CPUs: 2 Maximum no. of CPU cores: 128 Good to know: Length of access: lifetime Redemption deadline: redeem your code within 30 days of purchase Access options: desktop Max number of device(s): 1 Version: Windows 11 Pro Updates included Click here to verify Microsoft partnership Created with ChatGPT The essentials to get it all done. Microsoft Office 2024 Home is the latest version of Microsoft’s renowned productivity suite, which includes essential applications like Word, Excel, PowerPoint, and OneNote. This version is specifically designed for individuals and families seeking reliable tools for various home tasks, including document creation, spreadsheet management, presentation design, and note-taking. Office Home 2024 is for students and families who want classic Office apps on their Mac or PC. A one-time purchase installed on 1 PC or Mac for use at home or school. Lifetime license for MS Word, Excel, PowerPoint, & OneNote One-time purchase installed on 1 Windows PC for use at home or work Instant Delivery & Download – access your software license keys and download links instantly Free customer service – only the best support! Microsoft Office 2024 Home or Business for PC or Mac includes: Microsoft Office Word Microsoft Office Excel Microsoft Office PowerPoint Microsoft Office OneNote Is it legit? Click here to verify Microsoft partnership Good to Know ONE-TIME PURCHASE INSTALLED ON 1 DEVICE This licensing type will be connected with your Microsoft Account, NOT your actual device. This is a one-use code. The product you are purchasing is NOT MICROSOFT 365. Please read the product details. Redemption deadline: redeem your code within 30 days of purchase Access options: desktop Full versions No subscriptions – no monthly/annual fees Version: 2024 Updates included Here's the deal: This Microsoft Office Pro 2024 + Windows 11 Pro bundle normally costs $448.99, but this deal can be yours from just $134.97, that's a saving of $314. For full terms, specifications, and license info please click the link below. Microsoft Office Pro 2024 + Windows 11 Pro for just $134.97 (was $448.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • Of course the problem was Secure Boot's new certificates. Install media created by the official Media Creation Tool is already signed with a valid certificate from Microsoft, so maybe that certificate isn't "up-to-date" enough for machines with the new ones installed in the UEFI. There's really no other logical explanation.
  • Recent Achievements

    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
    • One Month Later
      agatameier earned a badge
      One Month Later
    • Week One Done
      agatameier earned a badge
      Week One Done
    • Week One Done
      ssd21345 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      518
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      147
    4. 4
      ATLien_0
      95
    5. 5
      Steven P.
      77
  • Tell a friend

    Love Neowin? Tell a friend!