PDA

View Full Version : newbie needs help!!!!



fishingsetx
- 14th October 2004, 04:25
Hello,

I need some help writing a program. I have some experience with Vbasic, but I have no experience programming chips other then copying them. Ive been using tlc 555 timers in hobby projects, but I want to use something more powerful and easier to modify. Im using a 12F629. I wrote a simple program, but im sure ive left ALOT out:

Symbol pir = GP5
symbol cam = GP4
Loop:
IF pir = high THEN
high cam
PAUSE 1000
low cam
PAUSE 180000
ENDIF
GOTO Loop

where GP5 is an input and GP4 is an output.

Ive tried reading 20 different help files, but they all pertain to the 16xxxx series chips. And I just Seem to get lost.

could someone please post a sample program along these lines, or could someone please edit my programand repost it?

If I just knew the proper format and how to set the chip up, this wouldn't be a porblem, but I just cant seem to figure it out. What I need is the entire thing. not just the loop section of the code.


Thanks,
Fish

mister_e
- 14th October 2004, 05:02
must be more like this



CMCON=7 ;disable internal voltage comparator

pir VAR GPIO.5 ;define GPIO.5 pin as pir
cam VAR GPIO.4 ;define GPIO.4 pin as cam
loop100times VAR BYTE ;define variable for big delay loop



loop:
loop100times=100
if pir then ;mean if pir=high
cam=1 ; do the same thing as HIGH cam
pause 1000 ; pause 1 sec as request
cam=0 ;same as LOW cam

; now do the big delay
while loop !=0
pause 1800
loop100times=loop100times-1
wend
endif
goto loop


if i well understand what your project do is waiting for a high state on pir pin then send 0 level to cam pin 1 sec after send high level to cam pin during 180 sec (3 minutes) right??? but i think something is missing!!! let me know the exact thing you want to do...

As i read you're a newbie so take care of MCLR (pin 4) is pulled up with resistor(4.7K-10K) to 5 volt supply.

it's suppose to work well now.

regards

mister_e
- 14th October 2004, 05:11
if you don't have the datasheet of your device, get it there
http://ww1.microchip.com/downloads/en/DeviceDoc/41190c.pdf

Ingvar
- 14th October 2004, 10:22
Hi Fish,

1. "pir" is very similar to "PIR1" which is register in the pic. I'd use a different name. It probably will work but i'd still pick a different name, just to be safe. I'll leave it alone for now.

2. You should declare your variables(pins) in a different manner.

3. You need to tell PBP that "pir" is an input. This could be done with the INPUT command.

4. It's probably also a good idea to set "cam" in a known state at startup. I'm guessing LOW.

5. The pause command can only accept values less than 65536. This means that you need to change pause 180000 to three pause 60000 instead.


Soooooo, with the changes made your program looks like this.

pir VAR GPIO.5
cam VAR GPIO.4

LOW cam
INPUT pir
Loop:
IF pir = 1 THEN
HIGH cam
PAUSE 1000
LOW cam
PAUSE 60000
PAUSE 60000
PAUSE 60000
ENDIF
GOTO Loop

I'd also recommend that you read the PBP manual(all of it) aleast a couple of times. You should also get familiar with you pic, read the datasheet ........ boring, i know but it's essential to know what resources you have to play with.

Cheers
/Ingvar

fishingsetx
- 20th October 2004, 01:09
Thanks guys,

I'll try those codes as soon as I can. I've been using picbasic pro at www.compilespot.com, but it wont let me compile either of those code samples. It tells me that they are too big for my account (thats what I get for using a free compiler). They compile into ASM, but not to hex.

Mister_e,

That is exactly what I want to do. I want to set up a security camera to catch tresspassers/poachers on my property, and I dont have the cash for a security system or to purchase a compiler. I will have to add some more code before it will work, but I want to get a simple program working so that I will have an idea on how to write it. I have a few other projects im working on that need timers too.

mister_e
- 20th October 2004, 03:43
hi fishingsetx ,
i see what you mean. For now, for your purpose, for your budget why not using Visual Basic to acces to LPT1 port ??? everything will be done as you wish with a minimal investement and time but will need a PC to run it. Depending if you have one PC in extra.

Or in the worst case, you can learn Assembly language of Microchip. With MPLAB (free IDE of microchip) you'll be able to compile your stuff. You can also build your own PIC programmer see this one
http://www.lancos.com/prog.html

or this one
http://www.myke.com/elcheapo.htm

but it support only a few PIC. Maybe some others free stuff can be avalaible on the net too. Have a look. let us know.

good luck.

regards