PIC 12F629 programming help

Status
Not open for further replies.

koyaelektronic

New Member
Hello,

I am new to this forum,have been following it for some time now,and I decided to join.
I am looking to program a PIC 12F629 to do a very simple function,but I don't know the coding.
Here is what I need:
3 INPUTS
1 OUTPUT
IF INPUT 1 gets a positive impulse on it,and INPUT 2 gets a positive impulse on it,then OUTPUT releases positive impulse lasting 2 seconds.
IF INPUT 1 gets a positive impulse on it,and INPUT 3 gets a positive impulse on it,then OUTPUT releases 2x positive impulse lasting 1 second each.
My problem is I am not into coding at all.Now if someone could help me with writing a code for my project,it would be awesome,because I would like to start learning how to program PIC circuits.

With kind regards,
Sima

dougy83

Well-Known Member
Code:
out1		equ		0
in1			equ		1
in2			equ		2
in3			equ		3

state		equ		0x10

setup:
bsf 	STATUS, RP0 	; Bank 1
call 	3FFh 			; Get the cal value
movwf 	OSCCAL 			; Calibrate
movlw	0xFE			; GP0 is the output; all others are input
movwf      TRISIO
bcf 	STATUS, RP0 	; Bank 0

movlw	0xFF
movwf	state

loop1:
movfw	GPIO
andlw	(1<<in1)|(1<<in2)
xorlw	(1<<in1)|(1<<in2)
btfsc	STATUS,Z
goto	doSinglePulse
bcf		state,0

loop2:
movfw	GPIO
andlw	(1<<in1)|(1<<in3)
xorlw	(1<<in1)|(1<<in3)
btfsc	STATUS,Z
goto	doDoublePulse
bcf		state,1

goto	loop1

doSinglePulse:
btfsc	state,0
goto	loop1
bsf		state,0

bsf		GPIO,out1
delayms 2000
bcf		GPIO,out1
goto 	loop1

doDoublePulse:
btfsc	state,1
goto	loop2
bsf		state,1

bsf		GPIO,out1
delayms 1000
bcf		GPIO,out1
delayms 500
bsf		GPIO,out1
delayms 1000
bcf		GPIO,out1

goto 	loop2

Last edited:

Mr RB

Well-Known Member
If you prefer C here's some code you can put in your main() function loop;

Code:
  // code to make 0,1,2 pulses based on inputs
if(IN1)
{
if(IN3) make_pulse;
if(IN2 || IN3) make_pulse;
}

koyaelektronic

New Member
Hey guys,thank you for the info...As I said I am a complete n00b when it comes to PIC programming?
So:
1)What is delay ms macro,and how to create it?
2)What would be the correct header?
3)What compiler to use for programming this?

I have made PICKit 2 clone,and this is where my knowledge stops.

Kind regards,
Sima

Ian Rogers

User Extraordinaire
Forum Supporter
If you are going down the ASM route..

1) Depends on the crystal you are going to use... Ie.. a 20Mhz crystal's clock cycle is 200nS so you'll need to count 5000 clocks to make 1 millisecond..
2) include "p12f629.inc"
3) Compilers are for C, basic and pascal... You'll be using MPASM... comes bundled with MPLAB IDE.

The pickit clone should work fine with MPLAB IDE.

koyaelektronic

New Member
Hey Ian,

The device has 4Mhz internal oscillator,I guess you were talking about that?

Kind regards,
Sima

Ian Rogers

User Extraordinaire
Forum Supporter
Yes!! A 4Mhz crystal gives a 1uS clock cycle.... so 1000 clocks equal a millisecond...

There are many examples of this type of delay... I recomend you look at Nigel's tutorials link in my signature.. they will help you to get started...

koyaelektronic

New Member
PIC MPLAB screen

Hey Ian,

here is my progress so far,I have switched to PIC12F675,since there is no 629 in my store.
I have found the correct header,and inserted i correctly(hopefully).
The new clock is 20MHz.

WKR,
Sima

Attachments

• picprogram.jpg
97 KB · Views: 126

jpanhalt

Well-Known Member
Hi Sima,

Now, add your source file. You may want to put it in its own folder, because MPLab will add some files to it when you build (compile) the project. That is a personal preference and is certainly not any requirement.

John

koyaelektronic

New Member
Main.asm

Hey jpanhalt,

I have copied what dougy83 wrote earlier in the thread,and named it main.asm,and I had put in source files,so my project now looks like this.I think you meant for me to do that,right?

Kind regards,
Sima

Attachments

• picprogram2.jpg
97.9 KB · Views: 109

Ian Rogers

User Extraordinaire
Forum Supporter
The pic12f675 has a 4Mhz internal crystal aswell!!

Just put it all in a single file

Code:
	list	p=p12f675
#include <P12F675.inc>
__CONFIG(0x31DD)
errorlevel -302; gets rid of bank select error

; variables
var1	equ 	20h			; declare a byte
cnt		equ		21h
cnt1	equ		22h
cnt2	equ		23h

; vectors
org 	0
goto	init		; vectors go here

; initialisation
init
banksel	TRISIO
movlw	0
movwf	TRISIO
banksel	GPIO
movlw	0
movwf	var1
; main loop
loop
movf	var1,w
incf	var1
movf	var1,w
movwf	GPIO
andlw	.8
btfss	STATUS,Z
clrf	var1
call	delayMs
goto 	loop

delayMs	movlw	.248
movwf	cnt
nop					;  5 instructions
nop					;  +
nop					;  the loop.
dly		nop					; (4 x 248uS = 992)
decfsz	cnt,f		;  =
goto	dly			;  997
return				;  + three for the call = 1000uS

end

simple program with a 1mS delay and variables and config settings for internal OSC..

koyaelektronic

New Member
Sorry for bothering you guys,I just don't get,and I am dropping this.
Thanks for all who tried to explain
Bye bye

blueroomelectronics

Well-Known Member
Don't give up after 3 days.

Choose an 18F series PIC and try Swordfish BASIC (easy) or learn XC8 using MPLABX (moderate).

A good beginners book might also help, Myke Predko published some very good ones.

Status
Not open for further replies.

Replies
5
Views
1K
Replies
21
Views
20K
Replies
2
Views
976
Replies
11
Views
7K
Replies
5
Views
994