Assuming we refer to the first program, the ENDIF it there at the end.
On the snippets it is missing, but I doubt that this can compile anyway.
Ioannis
Assuming we refer to the first program, the ENDIF it there at the end.
On the snippets it is missing, but I doubt that this can compile anyway.
Ioannis
I don't use this particular Model T PIC, so I reserve the right to miss some quirks. Here are things I would check:
1. You don't list your CONFIGs, but try disabling the WDT. It could be resetting on you.
2. Try enabling CLKOUT and verify oscillator. On one project I did years ago, I had the crystal too far from the OSC pins and it would work for a few seconds then Peter out.
3. Not sure which PORT PIN is MCLR, but you only have one Input in your TRISx Registers. MCLR should be a "1" (even though it probably defaults to Input Only). Don't forget the pull-up resistor.
4. Make sure there are no other default settings triggering things unexpectedly (like Comparator or something).
5. I think you already tried removing the PICkit3 programmer before trying the code. Using PORTB.7 probably ties into a PICkit3 programming pin.
Some food for thought, things to try. Hope it helps.
Code:#CONFIG cfg1 = _INTRC_OSC_NOCLKOUT ; INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN cfg1&= _WDT_ON ; WDT enabled cfg1&= _PWRTE_OFF ; PWRT disabled cfg1&= _MCLRE_OFF ; RE3/MCLR pin function is digital input, MCLR internally tied to VDD cfg1&= _CP_OFF ; Program memory code protection is disabled cfg1&= _CPD_OFF ; Data memory code protection is disabled cfg1&= _BOR_OFF ; BOR disabled cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled cfg1&= _LVP_OFF ; RB3 pin has digital I/O, HV on MCLR must be used for programming cfg1&= _DEBUG_OFF ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins __CONFIG _CONFIG1, cfg1 cfg2 = _BOR40V ; Brown-out Reset set to 4.0V cfg2&= _WRT_OFF ; Write protection off __CONFIG _CONFIG2, cfg2
Ok here are answers.
1. PORTB.7 is connected via 10K resistor to MPSA42 transistor, which drives buzzer.
2. I tried replacing it with led, different buzzer, no difference. Sometimes it works, sometimes it does not.
3. I've used another PIC16F887 - no change.
4. Of course I've tried disconnecting pickit 3 - no difference.
5. This problem ONLY occurs with PORTB.7 as output and PORTA.0 as input. Say if I don't query PORTA.0 for input and just make PORTB.7 high/low from the code, it works fine.
6. All remaining ports (except PORTA 1 & 2 which are connected to DS3231) are connected via 10K resistors to MPSA42 transistors, which drive nixie tube cathodes and work fine.
7. MCLR, WDT and others are disabled, as you can see from above config.
WDT is ON on your code but I doubt that this is causing troubles as the compiler takes care of this.
MCLR: is it tied to Vss or Vdd?
Ioannis
Last edited by Ioannis; - 22nd April 2020 at 14:41.
MCLR is disabled and used as button input - tied to VDD via 10K resistor and button pulls it down to VSS. It works fine.
Hmmm, if you are using a 10k pull-up to VDD and a button to ground, do you have an additional 10k resistor between the button and PORTA.0? If so you have a voltage divider possibility where the Input thresholds occasionally do not exceed min/max, thus the sporadic results. (again, stabbing at unknowns)
Try using 4.7k resistors instead of 10k resistors for isolation. I had a project where I used 10k for MCLR. It was used in a noisy environment where it would occasionally RESET. I replaced the 10k with a 4.7k and the unintended RESET stopped.
Bookmarks