Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Programming Problem

Status
Not open for further replies.

DMW

New Member
Hello, this is my first micro-controller project so im not sure whats wrong

Im trying to program a PIC16F877A via serial RS232 port in C and a JDM programmer.

Im using MPLAB and a free HI-TECH C compiler.

Ive looked at many tutorials and they seem to differ a lot from one another or are for assembly language.

I cant get the PIC to program, although im not even sure my code / setup is correct. What ive done so far is:

project > project wizard
device 16F877A
tool suite > HI-TECH Universal Toolsuite
save project
dont add any existing files [they are in assembly and wont compile with C?]

they file>new
save main.c

in main.c [after added to project]

#include <pic.h> //i think thats the right header.
void main()
{
TRISD = 0x00;
PORTD = 0xFF;
}

that should just output 1's on the D port correct? im not sure if my headers are correct, alot of examples use "#use delay <clock=4000000>", but thats throws up an error if i use it.

Then i goto programmer > select programmer
then i have no idea which to use, if i try
MPLAB PM3

with the chip and programmer connected and COM1 set, it says:
"No programmer detected. Please try the current operation again"

or

PICSTART
"PICSTART Plus not found. Please verify serial connection and try the current operation again."

Is my program correct, ive tried this with different IC's and still doesn't work, is my programmer hardware broken?

Thank you in advance
Dominic
 
If your programmer isn't listed in MPLAB, then you can't use it from MPLAB. The JDM is NOT supported via MPLAB. You need to find the *.HEX file generated by MPLAB (Usually in the same folder as the source code) and load THAT into the software designed for your JDM programmer. Then use the JDM programmer software to program the PIC.
 
Last edited:
Thankyou i assumed all the hardware programmers where the same, and it was just the software that was different. Thanks ill give this another go,

Do you think the code is correct?
 
I don't use HI-TECH C, but it looks like you've missed setting up the config register. In C18 it goes like this:
#pragma config WDT = OFF, LVP = OFF //etc
You might also want to include at the end of your code:
while (1){;}
because I don't know if HI-TECH C provides an endless do nothing loop when the "end" of main() is reached.
 
felis:
it complies fine,
Its just the header, <pic.h> seems very generic when theres lots of headers for defined PIC's, and the lecture notes i got these off was for 16F877 not the 877A - and im not sure on the difference between them.

Kchriste:
i think ive done that by going under:
configuratoin> configuration bits


i would try out the code but now when i try and use the software programmer that came with the hardware programmer i get

ERROR -> Wrighting address 0x000000
Written 0x2FF9 Read: 0x3FFF

[if i goto verify or program all]

if i goto hardware test it goes
"hardware ok."

and if i goto
detect device it says

detected> UNKNOWN
and resets the device back to 16F84


its doing this with both the PIC's i have, also noticed the LED on the programmer never lights - i assume it is supposed to.
 
OOHH FFS turns out i had the pic in the programmer upside down - hope its not damaged :S
 
Probably not, since the serial port can't supply much current. Give it a try.
 
DMW: '877 and '877A are similar. MPLAB knows the difference in programming, I think there's negligible difference in coding.

pic.h pulls in different headers based on the device you set in MPLAB.

remember to set the config fuses correctly, or the osc won't start and it will sit there like a pudding.
 
matc said:
remember to set the config fuses correctly, or the osc won't start and it will sit there like a pudding.

can you expand on that? the configuration fuses meaning the configuration register?

i have set mine to:
Oscillator = HS
Watchdog timer = off
Power-up timer = on
Brownout detect = off
Low voltage program = disable
Flash program write = write protection off
Data EE code protect = off
Code protect = off
HEX: 3F32

4Mhz crystal with 2 x 22pf capacitors

current setup:
**broken link removed**

but yet my LED still wont light. It sucessfully programs and verifies the PIC chip.

Could my powersupply be a problem?, being a poor student ive just hooked this up to my USB port, it reads only 4.79 volts on the Voltmeter, and 500ma should be plenty? Also to turn it on im just "plugging" in the USB port, should i try and get a S/R flipflop with a push to break switch to make a debounce switch?

Thanks

note and i did fix the code to read
TRISB = 0x00;
PORTB = 0xFF;
 
Last edited:
Have you placed a while(1); at the end of your main program?

I.E.
Code:
#include <pic.h> //i think thats the right header.
void main()
{
	TRISB = 0x00;
	PORTB = 0xFF;
	While(1);
}

I haven't used HiTech C and don't know how you setup the config value. Can you confirm your config value in the software you are using to program the chip.

Mike.
 
Do you have a 0.1 uf cap' on the VDD and VSS lines? If not, this could easily prevent the PIC from running.
 
yes i do have a while(1); statement :) pommie

mike no i don't, is this crucial? i shall add a capacitor across the lines as soon as i can get hold of one, thanks, at the moment my smallest is 1uF
 
That should work - but I've read your posts, and are you sure you're actually compiling and programming the device correctly?
Sequence for you is probably:
- Compile main.c
- Tell the JDM what hex file to use? (not sure, not used it)
- Program the device
- Read back from the device with the programmer, and check that some reasonable code has been programmed.

Unless you are certain you are correctly programming it, you might not be. I can't see any programming inputs on your circuit diagram. The readback I mentioned above from the device is a double check that everything is working ok.

Other suggestions:
- 4.7 V should be fine.
- Test your LED is the right way round by temporarily jamming the PIC output high.
- Test VDD/VSS pins are correctly wired
- Set the osc to XT (but doubt that's the problem)
- Hold MCLR low for a brief second to reset the chip from whatever state it was in.
- Set GIE to 0 to make sure interrupts are disabled
- Got another pic? just in case you blew the first one up.
- Power decoupling (capacitor) is unlikely to be the problem but is good practice.
- If you have a 'scope, check that the osc is oscillating. Try a different crystal. Check the caps are really 22pf (should work without them too in my experience).
 
thanks for the reply, i can test this better on monday when i have access to the lab.

One thing i am abit unsure of, is that my hex file is as such:

C:
#include<pic.h>
void main()
{
PORTB = 0xFF;
TRISB = 0x00;
while(1)
{;}
}

HEX
:02000000F92FD6
:0E0FF200FF3083120313860083168601FF2F43
:00000001FF

but whe i open my hex file in WINPIC800, only the first two bytes change value, and no data changes, screenshots:
https://i12.photobucket.com/albums/a239/muzzwezz/winpic800.jpg
[youd have to excuse why ive blanked my username, basically never leave your room unlocked while reformatting your computer, a drunk neighbor decided to choose my username for me...]

as you can see it seems only two bytes have been read? is this correct?




edit

i am using a hardware programmer though RS232, so i physically remove the chip from the breadboard and put it into the programmer.

LEDS work fine, ive tested them :)
 
Last edited:
drunk neighbour set your username? haha :)

Ok - forget the data setting, that stuff doesn't matter.

You should have a lot more than 2 instruction bytes set - that's only one instruction slot. (3FFF = 14 bits = one instruction).
 
yes, worst bit is you can change the name on the login screen, but not on the actual C drive :p

damn so ither its not compiling correctly or its not being read correctly from winpic?

whats the best way to find which the error is? try finding / opening another hex file?
 
DMW said:
yes i do have a while(1); statement :) pommie

mike no i don't, is this crucial? i shall add a capacitor across the lines as soon as i can get hold of one, thanks, at the moment my smallest is 1uF

1uF would be fine.

BTW, your HEX file contains no config fuse information, so unless you're setting it manually in your programmer software you're not setting the config fuses at all.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top