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.

PIC10f200 Help Programming

Status
Not open for further replies.

alanbacklund87

New Member
Hello all,

I'm very new to programming and have a a few PIC10F200 microcontrollers with a PicKit2 programmer that I'm having trouble using.

I need this small chip for the project I am attempting so a much larger and easier chip to use is most likely out of the question.

I am not familiar with programming AT ALL and have tried tinkering with C language without success.

The program I need to write is this

when power is applied

LED 1 comes on and stays on until later described,

after LED 1 turns on, LED 2 waits 200ms then turns on stays on for 500ms, then LED 2 turns back off for 500ms, then LED 2 turns back on and stays on infinite.

After the LED 2 led stays on infinite, LED 1 turns OFF and stays OFF infinite.

ANY HELP WOULD BE GREATLY APPRECIATED!!!!
 
I wouldn't even try to use a high level language on these...only 16 bytes of ram. I would think it's asm all the way on these....Vladimir Soso **broken link removed** does do a basic compiler for these....
 
well, i've attempted to use MPLAB IDE but I would be willing to use ANYTHING that will work!

I'm just too new to this to really understand the correct steps to assemble a code into a hex file.
 
GCBasic compiles for the 10F series, it is an open source compiler. High level compilers use, temp variables in math, delay routines, etc. As mentioned, ram variables will quickly run out for the 10F's. Simple led routines are feasible:

Code:
#chip 10f200, 4 
#config INTRC_OSC	

dir GPIO b'001000'

Main: 
For test = 1 to 3 
SET GPIO.0 ON 
SET GPIO.1 OFF 
WAIT 50 10ms 
SET GPIO.0 OFF 
SET GPIO.1 ON 
WAIT 50 10ms 
Next
GPIO = 0
wait 1 s

For nib = 1 to 7 
GPIO = nib 
wait 50 10ms
Next
GPIO = 0
wait 1 s
goto Main
 
Like I said, I'm very new to all of this. I've only been reading up on all of this for about 2 or 3 weeks and just kind of hit dead ends on understanding the whole concept.

How would I program that code that you wrote to my microcontroller?
 
Now I created a hex file using that code you pasted in the above post but when I program it to my chip, it says "invalid OSCCAL value detected". what should I do now?
 
The OSCCAL may have been wiped out from previous tinkering with MPASM? Never fear as the PICKIT 2 will regenerate it for you by going to the tools tab, and clicking OSCCAL. It will warn that everything is going to be erased, and press OK if I remember that right. Upon successful completion the OSCCAL value will show up in the PICKIt 2 menu screen, you can copy it down if you want.

That was fast, you already had GCBasic downloaded?
 
yes i downloaded it and loaded that code you provided. I noticed you can view as text or icons. I then hit compile and download and then saved the file into a new folder.

Then using pickit2 I imported the hex file and now it is appearing to program jsut fine however none of the led's blink.

My OSCCAL issue was fixed by just running the chip off of the pickit2 VDD and VSS outputs.

I've got 25 of these chips so if I screw anything up permanently then I'm ready to try a different chip.

Am i skipping a step to get the leds to blink?
 
So you attempted to use the Hitech C Compiler through the standard MPLab installation?

As other people have mentioned, there are various programs that you can use, such as GCBasic as NickelFlipper posted, and Oshonsoft (not free, trial version) as Ian has mentioned.

In terms of programming BASIC is the beginners language, however, I would say if you can, write your code in C!

With regards to C you have to remember that everything that is a command MUST end in a semi colon ( ; ), apart from statements that "jump".

For example:
Code:
void main(void)
{
   int i = 0;
   for(i = 0; i < 500; i++)
   {
      __delay_ms(1);
   }
}
void main(void)
This is what is commonly referred to as the "entry point" it is the "main" point in which your application will execute, and will always be called "main".
"void" is nothing, quite literally, when you void something you make it non existant, so, what this is doing is saying that the function "main" will not return anythiing, which is the "void" before the text "main". Nor will it expect any parameters to be passed to it, which is the "void" inside the brackets after "main".
The curly brackets "{}" symbolise the start and end of a function, this is present on every function, and any chunk of code that needs to be executed before comming out, like the for loop. You will notice that there is no semicolon ( ; ) at the end of this line of code.
int i = 0;
Here you will notice the semi colon, basically this line defines a variable with the name "i" of type integer, which is a whole number, we are also initialising it to "0", which just means it will start with a value of "0". If we put "i = 1" then the variable "i" will be initialised with the value of "1".
for(i = 0; i < 500; i++)
This is called a "for loop", quite simple, you will notice that the parameters of "for" is seperated by 3 semicolons, but does not end in a semi colon, the code inside of the for loop is also contained within curly brackets.
The first instruction of the "for loop" is to initialise "i" to 0, the next parameter makes the "for" loop check if it is below 500, if it is below 500 then carry on and do what is inside the "for loop", the last paramter increments i, we could of used i=i+1, but in C/C++ they give us special operators to do things more simplistically, such as the ++ operator, we can also use -- to decrement the variable by 1.
So, the 3 parameters are start condition (int i = 0;), the clause ( i < 500;) and finally the end condition (i++).

This can be written as:
i equals 0
(loop) if i is less than 500 do the following
delay by 1 millisecond
if i is not less than 500 then exit other wise increment i and go back to loop.

So, you can see from the above that the code will simply call what is inside the for loop "n" number of times, "n" in this case being 500 (0 - 499) = 500 times.
Another common mistake is that "i<500" means 499, not 500. If "i" hits 500 then it will exit the loop but because we start at "0" 0 to 499 = 500 times. (Hope that makes sense!).

__delay_ms(1);
Observe the semicolon at the end of this statement.

This is a built in routine specific to HITECH C that will delay by 1 millisecond, it wont run as is, it needs a few variables set up to define the clock speed (the speed at which the instructions are run at).

When dealing with PIC's in particular, you will note that the smaller 8 pin variants use what is called GPIO, General Purpose Input / Output. This is addressed as a single "port" and individual bits, so GPIO.0, GPIO.1, GPIO.2 etc.
When you move on to the bigger chips this will change to actual port "names", this will be in the convention of "RA, RB, RC, RD, RE" etc, it's not a massive change, just make sure that you dont try and address the bigger chips with "GPIO" as it wont work! you can address "RA.0" for example instead.

For your LED project, as blinky LED's are a hardware reference to a software's "hello world", I assume you have the correct electronics knowledge to interface the LED's with the pins?

Hope this helps and gives you a basic insight into C and PIC programming.

Wilksey
 
You may need to unplug the PICKIT 2 programmer and repower the circuit, sometimes it can hold MCLR low, which is the master clear, which effectively holds the chip in reset.
 
when i write the hex code to the chip the hex reads as

946 C08 006 076 2B6 506 426 C32 034 929 406 526 C32 034 929 C03
096 703 A04 066 C01 034 93E 075 2B5 215 026 C32 034 929 C07 095
703 A18 066 C01 034 93E A03 003 A28 C0A 032 073 930 2F4 A29 800
2B3 C8E 031 C01 030 2F0 A35 2F1 A33 2F2 A31 2F3 A31 800 CE8 032
C03 033 930 2F4 A3E 800 CCF 002 066 800 FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF
FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF

when i click "read" it comes up as identical code. I'm assuming that this means the programming process is working just fine.

I'm supplying about 6 volts to the VDD pin and Ground to the VSS wire. Are there any other pins that need to see inputs?
 
You've got the target power (orange) light visible? by checking the VDD PICkit 2 ON box. The code assumes the power to the leds is sourced by the micro pins. These are standard 20ma leds?, then check polarity by switching around, verifying the long lead (Anode) is on the micro pin side, or the flat side (Cathode) is on the ground side.

If the pic has seen an over voltage situation, say higher than 5.5V or 6V, then the chip could have been permanently damaged. This is hard to do if you are using the PICkit 2 as the target power.

PS: just saw your new post. Don't use battery power, use the PICkit 2 power, you may have smoked the chip.
 
Last edited:
I got it working. Fried chip was the problem.

The blinking pattern isnt what I need but I'll mess with it for a bit and see what I can do. I might need some help.

Thanks so far though. This is a HUGE step for me although it's very simple for ya'll
 
Last edited:
Anything over 5V tends to mess the logic up also, especially when looking at UART stuff.

You have to walk before you run!!

We were all there once, so we can appreciate what it is like! Sometimes its still not that simple for us!! If it was there wouldn't be any need for forums like these!
 
Well. Hopefully I'll actually start understanding these things alot more. At the moment you basically just handed it to me and I still don't know what I'm doing. I'm at least on the right track and can build off of what i've got. THANKS A TON MAN
 
This tutorial helped me a lot
,Its in assembly and C ,, Just get a program working and play around to see what works and what doesnt , Then build on that

Bernie

gooligum electronics **broken link removed**
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top