PDA

View Full Version : Please help a new guy get going with a PIC10F222



Quacker
- 27th May 2006, 17:46
Hello all!

I'm new to programming and that means that the least clearly documented area in programming (setting up the registers) has stopped me cold. I'm coding a 10f222 and I can get my program compiled, but it will not run. I strongly suspect that I don't understand what registers I need to set up. So I ripped down the program and I'm simply asking for GPIO.2 to pulse on and off (get the LED to light). Still nothing.

What would be great is if someone would post a listing that DID work and I then could compile and run it. That would confirm that everything over here is working correctly, and who knows, I might even learn something!

Thanks,
Q

paul borgmeier
- 27th May 2006, 22:20
I believe the default Config settings is for GP3 to be used as MCLR (which means GP3 must be tied high). Could this be the cause of your problem?

Although I have never used this PIC, this should blink GP0 at 1 Hz

ADCON0 = 0 ; all pins digital
TRISIO = 0 ; all pins output (except GP3)

Main:
GPIO.0 = 1 ; GP0 = high
pause 500 ; Pause 500 mS
GPIO.0 = 0 ; GP0 = Low
pause 500
goto Main

End

Good Luck,

Paul Borgmeier
Salt lake City, Utah
USA

Quacker
- 28th May 2006, 01:26
I have just gotten the chip to ALMOST work correctly. The only port that I can't get control of is GP.2. This port is shared with a clock that seems to be part of the timer, Tmr0. I can't tell from the data sheet, how to gain control. Perhaps someone can help. I figure that once i'm in control of the ports hat it will be much easier to get them to do what I want. Here is the listing that works. Note that GP.3 is always an input and I don't expect to see an noutput on it. Yes, I did throw the kitchen sink at it, but hey...

@ Device PIC10F222, IOFSCS_4MHZ, MCPU_OFF, WDT_OFF, PROTECT_OFF, MCLR_OFF

tmr0= %00000000
TRISIO =%0000
ADCON0 = %000000
GPIO = %0000

Start:
high gpio.2 'test
high gpio.0
high gpio.1

pause 1

low gpio.2
low gpio.0
low gpio.1

pause 9

goto start

mister_e
- 29th May 2006, 14:33
data sheet section 4.5 OPTION REGISTER

Now try


@ Device PIC10F222, IOFSCS_4MHZ, MCPU_OFF, WDT_OFF, PROTECT_OFF, MCLR_OFF
OPTION_REG.5=0 ' TOCS = FOSC/4
ADCON0 = 0
TRISIO =0
GPIO = 0

Start:
high gpio.2 'test
high gpio.0
high gpio.1

pause 500

low gpio.2
low gpio.0
low gpio.1

pause 500

goto start

Quacker
- 30th May 2006, 00:18
Thanks Steve!

I was hacking around last night and finally figured out the "OPTION_REG.5 = 0" To show you how new I am, I didn't know 'til then that I could actually change a specific register bit, let alone that the OPTION register was actually called the OPTION_REG!

BTW, Jeff at MELabs confirmed that the ADCIN command does not run properly on this chip (yet?). The command executes but stuffs the answer in the adres register, not the one you specify.

All-in-all though, a pretty impressive little chip.

Best,
Q

mister_e
- 30th May 2006, 14:14
it's not so hard to do your own ADCIN so far. Just writing and reading the according register. It's pretty well explain in the datasheet. Will be faster and much code efficient.

Quacker
- 31st May 2006, 01:16
Thanks,

As soon as I figured out that I could have my way with individual register pins, everything got easier. I am also wondering if there are any clever tricks out there that I can use to fit in a few more VAR's. I'm out of space and my program isn't quite finished.

mister_e
- 31st May 2006, 03:34
if you can, post your code here. We may see few thing to be shrink. Next step.. switch to a bigger one... like 12F675 or my favourite one 12F683.

512 Byte is really easy to fill... worst when using ANY Basic or C compiler.

Unfortunately those baby 10F don't have internal EEPROM... busted!

Quacker
- 1st June 2006, 00:56
I have enough memory for program (512 bytes) but not for data (23 bytes). What I was just thinking of, was to use generic VAR's instead of specific ones, on the theory that if a VAR was used in only a segment of the program, that I might borrow the space and reuse it later in the same progam. Sort of like this example where instead of using a "basket for apples" and a "basket for oranges" I use basket#1 over and over:

start:

Get number of apples
put in basket#1
Divide by number of children and distribute
.
.
.
(Sometime later if I'm really done with the apples)

Get number of oranges
put in basket#1

Divide by number of children and distribute

clear basket#1 (optional)
goto start

My software friend almost fainted at the prospect but in a pinch, it could save me from running out of data memory and thus save the SOT23-6 from becoming an SOIC-8, right?

mister_e
- 1st June 2006, 01:16
still unsure of everything 'round what i suggest, but i guess the EXT modifier could help you on that. Darrel may confirm that thought. I have to experiment around this one when i'll find time... there's still some healling to do here and pending project to finish first :D

http://www.picbasic.co.uk/forum/showthread.php?t=3891

paul borgmeier
- 1st June 2006, 05:46
Not 100% sure what you are after but ...
Your software guy probably likes code that is well documented and easy to read – don't we all. I do the following all the time when in your situation. I set up a variable that I plan to use locally and then set up an alias to that variable.

Example:

AppleCount var BYTE ; define variable in RAM
OrangeCount var AppleCount ; alias to AppleCount

; early in the program
For AppleCount =1 to 10
Do Something
Next AppleCount
.
.
.
;Latter in the program

OrangeCount = PORTB

Select Case OrangeCount
Case 1
Do something
Case Else
Do something else
End Select

As you can see, the variable is reused and readability is maintained.

Paul Borgmeier
Salt lake City, Utah
USA

Quacker
- 2nd June 2006, 01:32
Great Paul,

I set up a number of aliases and it works fine, even when the ram was so full that one more "something VAR BYTE" chokes the compiler.

I'm all set!