PDA

View Full Version : 12F629 beginning



Davidpower
- 26th September 2007, 10:34
Hi you all again!

Iīm already working with pics a little bit thanks to your help but didnīt work with these mcus for nearly a year.
Iīm working with 16F628A and this is already ok for me, LCD text and frequency counters even
digitally rev limiters for engines with two BCD rotary switches, works all fine.

BUT: I need a little helper-program and donīt want to waste a 16F628 for this. The 12F629 could do just fine even without crystal etc. I just need one pin as Input and one as output for example for a LED.

So what: I donīt even know how to start anything in PICBasic Pro (got the full version!!)
for example something like blink.pbp .

I can load a hex file into the PIC but i dont know how to adress the pins , start the intern oscillator . Thats for starters.

hey donīt laugh that loud! iīm a mechanical by profession with just a few electrons in my veins.

Thanks in Advance !

mister_e
- 26th September 2007, 12:52
Configuration fuse : http://www.picbasic.co.uk/forum/showthread.php?t=543

This one use GPIO instead of PORTA-PORTB
TRISIO instead of TRISA-TRISB

and you need to disable the analog comparator... same as 16F628 CMCON=7


maybe the following would be enough to start
http://www.picbasic.co.uk/forum/showthread.php?t=1966&highlight=blink+12F629

Davidpower
- 27th September 2007, 08:02
Thanks Mister_e!
The blink.pbp works with my 12F629 with pin 7 as output which is ok for me.

Leaves one problem: I want to make for example pin 7 (GP0) output and pin 2 (GP5) Digital Input for frequency measure purposes. The program will switch the LED on when the input gets a lower than specified frequency . The program is no problem, just the PIN order.

So theres one thing I see: I have to concentrate on a very small Number of different Pics to get used to them. My favorites: 12F629, 16F628A, 16F876A. That should do for the next years or so. Iīve learned the old school "two transistor 6-18V circuits" when I was 14. Thats 30 years ago. Now Iīm wriggling around sportscar engines and some electronics knowledge comes in handy you know.

mister_e
- 27th September 2007, 13:33
I suggest you have a look to 12F683. Really nice one for a 8 pin device, PWM, A/D, Comparator and much more codespace.

16F88 is also a nice one. Nice replacement for the 16F628

16F88x are nice as well... OH well, hard to find my favourite... i had 50-60 different model before in stock. And Microchip seems to release a brand new model each week. :eek:

Davidpower
- 27th September 2007, 21:58
Hi Guys,

my program shows a flaw but i dont know where.

depending on the press of a button at GPIO.1 a led should flash defferent at GPIO.0.

************************************************** **************
'* Name : Blink4.pbp *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 26.09.2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE pic12F629, WDT_ON ; Watchdog Timer
@ DEVICE pic12F629, PWRT_ON ; Power-On Timer
@ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
@ DEVICE pic12F629, CPD_OFF ; Data Memory Code Protect
@ DEVICE pic12F629, PROTECT_OFF

DEFINE OSCCAL_1K 1' Set OSCCAL for 1k
cmcon = 7 ' Comparator OFF


TRISIO = %11111110 ' Set GPIO 0 as output 1-4 as input

if gpio.1 = 1 then
pulsout GPIO.0,10000
else
pulsout GPIO.0,2000

endif

I missed something, but dunno what. The led reacts at the first command line, whether theres a gpio.1 = 1 or gpio.1 = 0
but never at the button itself. it doesnīt find the input.

HELP!

mackrackit
- 27th September 2007, 22:13
If that is all of your code it is stopping at the endif.



MAIN: 'Add this for a loop name.
if gpio.1 = 1 then
pulsout GPIO.0,10000
else
pulsout GPIO.0,2000

endif
GOTO MAIN 'Add this to start the loop again

Davidpower
- 1st October 2007, 19:00
ok, this works but I donīt know how to adress in and outputs of the 12F629

'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 26.09.2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE pic12F629, WDT_ON ; Watchdog Timer
@ DEVICE pic12F629, PWRT_ON ; Power-On Timer
@ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
@ DEVICE pic12F629, CPD_OFF ; Data Memory Code Protect
@ DEVICE pic12F629, PROTECT_OFF

DEFINE OSCCAL_1K 1' Set OSCCAL for 1k
cmcon = 7

trisio.5 = 1 ' port5 is an input

led1_status var bit
button1 var gpio.5
led1 var gpio.0

main:

if button1 = 0 then ' if the button is pressed

led1_status = 0 ' make it 0
pulsout GPIO.0,10000
pause 50 'debounce

else

led1_status = 1 ' the last state was a 0 so now make it a 1
pulsout GPIO.0,2000

pause 50 'debounce

endif
goto main

there has to be a simple straightforward command to define inputs and outputs

what the heck is it? I know the tris option for the 16F628A which works fine but doesnīt seem to work for me on the 12F629..why? This looks like "I define one port and hope the others work somehow for me" what do I miss? the explanation in the picbasic pro handbook doesnt help a bit because it adresses only the bigger Pics

mister_e
- 1st October 2007, 19:22
Yes TRIS will work... but you need to use the according name as per the datasheet.... TRISIO will do the job as expected.

Sure the PBP handbook will not cover it. TRISIO, TRIS is not a PBP command, just a PIC register.

You could still use

INPUT GPIO.0
OUTPUT GPIO.1
and so on.

TRISIO= %00000001 ' set GPIO.0 as input, other to output... when possible (MCLR)

it's not a bad idea to set initial value to your PORT as well.

Don't forget, all i/o are set as input at POR.

try this one


@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE pic12F629, WDT_ON ; Watchdog Timer
@ DEVICE pic12F629, PWRT_ON ; Power-On Timer
@ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
@ DEVICE pic12F629, CPD_OFF ; Data Memory Code Protect
@ DEVICE pic12F629, PROTECT_OFF

DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1k
CMCON = 7

TRISIO = %00100000 ' port5 is an input

Button1 var gpio.5
Led1 var gpio.0

GPIO = 0 ' clear all outputs
PAUSE 50 ' internal OSC settle time... more than safe

main:

if button1 = 0 then ' if the button is pressed
pulsout Led1,10000
while Button1 = 0 : wend
pause 50

else
pulsout Led1,2000

endif

goto main

Davidpower
- 1st October 2007, 22:06
thanks Mister_e,

so I could define my ports for the 12F629 and best of all one input and one output covers my needs...
at last I got my ultimate program: counting pulses on GPIO.5 and give a signal if a limit is exedeed:
'************************************************* ***************
'* Name : count12F629_1 *
'* Author : Davidpower *
'* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 26.09.2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE pic12F629, WDT_ON ; Watchdog Timer
@ DEVICE pic12F629, PWRT_ON ; Power-On Timer
@ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
@ DEVICE pic12F629, CPD_OFF ; Data Memory Code Protect
@ DEVICE pic12F629, PROTECT_OFF

DEFINE OSCCAL_1K 1' Set OSCCAL for 1k
cmcon = 7

trisio.5 = 1 ' port5 is an input

LED var gpio.0
Cnt VAR word ' Cnt is a word variable

Cnt = 0
LED = 0
rpt :
Count gpio.5, 500, CNT

if CNT > 10 then
LED = 1
Else
LED = 0
ENDIF
Goto RPT

END ' End of program

of course it doesnīt work and I dont know why. gets TTL square wave signal to GPIO.5 and recognizes the signal in another program when slow enough, that means it recieves and the voltage etc. is ok. Whats wrong?

please help

mister_e
- 1st October 2007, 22:15
Yeah but you also need to define LED as output. By default all I/o are configured as input... so TRISIO=%11111111.

what if you're using the following

TRISIO=%11111110 ' Set GP0 as output, other to input
This will set all I/Os in one shot, and configure GPIO.0 as an output

You could still leave your current TRISIO setting as is but use HIGH LED and LOW LED instead. HIGH/LOW set the according pin to Output for you.

Depending the frequency you want to measure, COUNT may work well or not. I would use a internal timer instead for that... but it's me.

First make sure there's no real big DC offset which could trick the TTL threshold level.. hence produce weird/erratic results.

What happen if you comment the DEFINE OSCCAL... line?

Davidpower
- 1st October 2007, 22:35
Thats the trick: the high GPIO.5 / low GPIO.5 makes the trick!

my program needs to be refined but what the heck it works.

And last not least: hey man that was a real FAST answer ! You need no sleep?
Thanks VAR WORD

mister_e
- 1st October 2007, 22:37
mmm, yeah i may sleep few hours/week :D Advantage to have dual screen in front of you :D

One for the work, the other for forum and other stuff.

Glad to hear it works!

YouAreWelcome VAR LONG ' for PIC18 only ;)