PDA

View Full Version : Programming a PIC 12F1822 Issues



natcsparky
- 24th July 2013, 05:21
HI,
I have a PICKIT 2 programming a 18F1822. Compiling the program works, but the program won't load. The same setup works for the 12F683. Any ideas?

Thanks

AvionicsMaster1
- 24th July 2013, 22:54
Easy one here. I can't find a datasheet for an 18F1822. Correct number, code, schematic and what you've done in the attempt to correct issue might help us help you.

natcsparky
- 25th July 2013, 00:59
Sorry about that. The part is right in one part of the post! It is a 12F1822.

The code is below - I am just trying to get a blinking light at this point(code from this forum). Thanks for your kindness is responding. As far as a schematic, I have 5 Volts, Ground and a connection to an LED on Port A.1 through a 1K resistor.

#CONFIG
_CONFIG _CONFIG1, _CLKOUTEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _BOREN_ON & _IESO_OFF & _FCMEN_OFF
_CONFIG _CONFIG2, _PLLEN_OFF & _LVP_OFF & _STVREN_ON & _BORV_19
#ENDCONFIG
PORTA = 0 ' LED Off
TRISA = 0 ' all outputs
OSCCON = %01101000 ' 4MHz internal
ANSELA = 0 ' all digital

Here:
HIGH PORTA.1
PAUSE 500
LOW PORTA.1
PAUSE 500
GOTO Here

END

wdmagic
- 25th July 2013, 01:30
Since your just testing this to begin with, I would leave out the oscon, let it run at whatever it wants. also swap location of the first tris and porta statement, and instead of using HIgh and Low, actually assign a value. see modified code below


#CONFIG
_CONFIG _CONFIG1, _CLKOUTEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _BOREN_ON & _IESO_OFF & _FCMEN_OFF
_CONFIG _CONFIG2, _PLLEN_OFF & _LVP_OFF & _STVREN_ON & _BORV_19
#ENDCONFIG
TRISA = 0 ' all outputs
PORTA = 0 ' LED Off
ANSELA = 0 ' all digital

Here:
PORTA.1 = 1
PAUSE 500
PORTA.1 = 0
PAUSE 500
GOTO Here
END

Also you replace the HERE loop with this code



Here:
Toggle PORTA.1
Pause 500
Goto Here:


you might want to make sure your led is actually hooked to PIN PORTA.1 and not PORTA.0, I have made this mistake in coding many times.

Dick Ivers
- 25th July 2013, 14:30
Are you using PBP3 and Microcode Studio version MCSX ?

Demon
- 25th July 2013, 14:32
Not sure about the semi-colon after GOTO HERE though.

Robert
:)

AvionicsMaster1
- 25th July 2013, 14:43
I also think you need to look at your CONFIG statement. PBP3 requires an indent and a double underscore to start the CONFIG statement and I don't think you can start a second line as you have done. Though if all you're trying to do is blink a light I'd leave all that stuff off and try it without.

RA0 is also a comparator input. On the 12F683 you need to turn the comparators off with CMCON = 7 and I think you need to do that with the CMxCON1 register. RA0 is also an input for a few other things and you'd think you wouldn't need to turn them off but you just might. One of the inputs is the ICSPDAT and the diode may be stopping the program loading. Try removing it, programm it, reinstall the LED and see if it works.

Also, if you didn't notice, wdmagic put the TRIS first and then the GPIO which I'm thinking is the preferred order. But they should come after the ANSEL, CMCON(if needed) and the OSCCON and DEFINE OSC settings.

If you think you might have the LED connected to a different pin on PORTA turn the whole port on with PORTA = %11111111.

Demon
- 25th July 2013, 16:12
Or maybe try another port just to get it blinking.

Robert

natcsparky
- 25th July 2013, 16:48
Thanks to all.

I have been successful in compiling, but will try these suggestions. The programming part is what is not working. Based on some more research, it appears that my problem may be the PICKIT2 firmware I am using. I am upgrading now, and will try the stand alone to load in the HEX file. Again, thanks to all.

natcsparky
- 25th July 2013, 16:49
Yes I am using PBP3 Gold and MCSX. Thanks

AvionicsMaster1
- 26th July 2013, 18:00
I see you're working this issue on the MELabs forum also. I think just about anything Darrel scribes is correct. In the last few years I've only seen him wrong once and that was only partially. Please post solution on both forums.

Dick Ivers
- 26th July 2013, 20:01
Hi natcsparky,
I tried your program using a breadboard circuit I had on hand with a 12F1822. After making corrections to the CONFIG lines as mentioned by AvionicsMaster, the program compiled OK with 60 program words. The hex file imported into MSCX with no problem, and the device programmed fine using ICSP.

Do you have the PicKit2 device file containing 12F1822? I think you must if you are able to compile as you say.

natcsparky
- 26th July 2013, 21:12
I have the latest device file and installed it per instructions. Did you use a PICKIT2? Microchip said (on the phone) today that it won't work and I need a PICKIT3.

Thanks

Dick Ivers
- 27th July 2013, 00:39
Yes, I'm using a PicKit2 .... also tried it with a clone Pic programmer, (ICP01-V2.0) and it worked as well. I use the PicKit2 for other F1 family parts as well with no problems. Hex file attached. Note: extension must be changed back to .hex.

Have you tried skipping around MCSX and loading directly to the PicKit2 Programmer software?

7037

natcsparky
- 27th July 2013, 06:47
It works! I borrowed a PICKIT3 and it programs just fine. Thanks to all for your help.

natcsparky
- 27th July 2013, 06:51
I tried the PICKIT2 GUI with the HEX file. Was not successful. Microchip says Pickit2 will not work, but I might try again. Thanks for the assistance.