Blink a led with a 12f629

267 views
Skip to first unread message

Jan Willem

unread,
Nov 5, 2009, 6:34:05 PM11/5/09
to jallib
Sorry for my bad englisch, but i try it.
I have a 12F629 with a Wisp648 and JalV2. I can program my 12F629 with
a sample .hex file. It is a .hex file that Pin7 go high en low (0V and
5V) every second (its working perfect) I have download it from www.voti.nl
(http://www.voti.nl/blink/n_index.html).
When i open the .jal file and i change the file to this:

include 12f629 (i change this to my chip)

var bit LED is pin_a0
pin_a0_direction = output
LED = high



When i compile this .jal file he give no errors and no warnings. But
when i load it in my 12F629, output 7 is not change high. We can help
me with this problem?

Many thanks,

JW

Rob Hamerling

unread,
Nov 6, 2009, 2:38:58 AM11/6/09
to jal...@googlegroups.com

Hi Jan Willem,

Jan Willem wrote:
> Sorry for my bad englisch, but i try it.
> I have a 12F629 with a Wisp648 and JalV2. I can program my 12F629 with
> a sample .hex file. It is a .hex file that Pin7 go high en low (0V and
> 5V) every second (its working perfect) I have download it from www.voti.nl
> (http://www.voti.nl/blink/n_index.html).
> When i open the .jal file and i change the file to this:
>
> include 12f629 (i change this to my chip)
>
> var bit LED is pin_a0
> pin_a0_direction = output
> LED = high

There can be many reasons! Please post your whole program source in a
message, then we can better diagnose the problem.
Did you also try the 12F629_blink.jal sample from the Jallib collection?

Regards, Rob.


--
Rob Hamerling, Vianen, NL (http://www.robh.nl/)

vasile surducan

unread,
Nov 6, 2009, 5:12:15 AM11/6/09
to jal...@googlegroups.com
Hi Jan,
Pin A0 is also AD channel input and comparator input.
You have to change it first as digital output.
The procedure doing this is called in jalV2 library style "enable_digital_IO" and can be found in the include 12F629 file , even a more logical name was disable_analog&comparator_input.
 
Vasile

 

Jan Willem

unread,
Nov 6, 2009, 9:57:10 AM11/6/09
to jallib
Hi Rob and Vasile,

Tanks for your reactions.
In the map 'Files' a have place the zip '12F629 Blink_a_led'.
Inclusive a screendump of my JALV2 program.
I hope you can help me with this (probable little) problem.

The code is now:

include 12f629 -- target PICmicro
include jlib

enable_digital_io()

var bit led is pin_A0
pin_A0_direction = output
--
--forever loop
led = on
--_usec_delay(250000)
--led = off
--_usec_delay(250000)
--end loop

Many thanks,

Jan Willem

Jan Willem

unread,
Nov 6, 2009, 10:01:18 AM11/6/09
to jallib
Hi Rob,

I have place in the map Files the zip '12F629 Blink_a_led'. I hope
that you can find the problem

Many tanks,

Jan Willem

Sebastien Lelong

unread,
Nov 6, 2009, 10:09:05 AM11/6/09
to jal...@googlegroups.com
Hi Jan,

Just FYI, with Google Groups, you can attach files on emails. This is much more user-friendly than posting to file section (it's better to put files in this section when they are aimed to be accessible from an URL or if you want to frequently refer to it).

Cheers,
Seb

2009/11/6 Jan Willem <jwkl...@gmail.com>



--
Sébastien Lelong
http://www.sirloon.net
http://sirbot.org

Rob Hamerling

unread,
Nov 6, 2009, 10:58:06 AM11/6/09
to jal...@googlegroups.com

Jan Willem wrote:

> In the map 'Files' a have place the zip '12F629 Blink_a_led'.
> Inclusive a screendump of my JALV2 program.
> I hope you can help me with this (probable little) problem.

I found your ZIP file.
It seems you are mixing 2 development environments: Wouter and Jallib.
That makes debugging difficult, not only for yourself but also for
people who would like to help you. Since you report your problem in
Jallib, you are supposed to report only problems with the Jallib
environment (otherwise go to Jallist).

>
> The code is now:

> include 12f629 -- target PICmicro
> include jlib
>
> enable_digital_io()
>
> var bit led is pin_A0
> pin_A0_direction = output
> --
> --forever loop
> led = on
> --_usec_delay(250000)
> --led = off
> --_usec_delay(250000)
> --end loop

This program looks like the 12f629_blink.jal sample in Jallib. Did you
try that *unchanged* ? It should work, it does here!

Remove the line with 'include jlib': that is not a Jallib library.
You don't need any library at all for this program!

You do need to specify some fuse_defs, why did you remove these?
pragma target CLOCK, OSC and WDT are really essential!

Why did you make the other changes above?
What do you expect this program to do now?

Effectively it is not more than:

> include 12f629 -- target PICmicro

> enable_digital_io()
>
> var bit led is pin_A0
> pin_A0_direction = output
> --

> led = on

A few question you should be able to answer:
What happens after the last statement?
Does the program end after the last statement?
Does it return, and if yes to what after the last statement.
Or are the memory locations after the last statement executed?
If so what is in those memory locations?
And if yes, what happens at end of memory? Does the program end, or does
it wrap around to the first program statement?

I fear you don't know any of the answers, otherwise you would not have
changed the program like you did. But this is elementary knowledge!
Have you any learning book for PICs? Any beginners book contains the
answers.

Back to the Jallib sample for this PIC. It should blink the led twice a
second. Try it and tell us what you see (or do not see what you expect).

a.faber

unread,
Nov 6, 2009, 11:00:34 AM11/6/09
to jal...@googlegroups.com
Hi Jan willem,
You also commented out the forever loop, this will put the PIC in sleep mode
after execution, to keep the PIC alive you need to have the forever loop

so change
--forever loop
led = on
--_usec_delay(250000)
--led = off
--_usec_delay(250000)
--end loop

into

led = on

forever loop
end loop


Hope this will solve your problem

Albert

Jan Willem

unread,
Nov 6, 2009, 1:12:16 PM11/6/09
to jallib
Hi Rob,

Thanks for your answer.

Wich part of my program is from Wouter? The 12F629.jal file is your
file, only the line 'include jlib' is from Wouter, but i have try to
compile it without this line, compiling is OK, but the .hex file is
not good. Pin A0 is not high.
Also i have try the tip from Albert, but also compiling OK, .hex not
good (pin A0 not high).
The example from jallib is with crystal, i use te internal crystal
(WDT).

Can you please give all .jal files wich need for compile a .hex file
in JALv2 that make the pinA0 high?

I can't find what i do wrong. Maybe i have the wrong JalV2 compiler?

My chip is OK, because when i use the .hex file from the voti site,
pinA0 is switch high and low every second!

My code is now (but not working) with the 12F629 from jallib:
------------------------
include 12f629 -- target PICmicro

enable_digital_io()

var bit led is pin_A0
pin_A0_direction = output
--

forever loop
led = on
end loop
-----------------------

William

unread,
Nov 6, 2009, 1:24:03 PM11/6/09
to jallib
Welcome JW!

Thank you for giving JALV2 and JALLIB a try. By now you may have
gotten your questions answered, and your program is probably running
just fine.

I sense from your questions that you may be just beginning with
embedded programming. That is great --- everyone here had to start at
the beginning too.

We are all volunteers here, and your questions may indicate that we
need to improve our documentation, so that JALLIB is more useful to
those who are just getting started.

We have a document: http://code.google.com/p/jallib/wiki/JallibAbsoluteMininum
that may be worth revising to include:

The history of the JAL language -- how it
started with Wouter, and the JALLIST, and how JALV2 was invented later
and how this JALLIB all fits together.

Books, such as those by Bert van Dam.

William

ps: Your chip, the 12F629, does not actually have any A/D channels.
If you do want to experiment with A/D, the companion chip is the
12F675 is a favorite of mine.

William

unread,
Nov 6, 2009, 1:27:29 PM11/6/09
to jallib
JW,

Sorry, I missed your most recent question until now.

We recommend that your program be exactly these statements:

http://code.google.com/p/jallib/source/browse/trunk/sample/12f629_blink.jal

Also, we assume you have downloaded, and have installed one of the
following:

http://code.google.com/p/jallib/downloads/list

William

William

unread,
Nov 6, 2009, 1:36:24 PM11/6/09
to jallib
After closer reading, I think you are saying that you don't have a
crystal, in which case, you must revise the example program. You
should change as follows:

pragma target clock 4_000_000
pragma target OSC INTOSC_NOCLKOUT

When I have time, I will test these changes here, and submit a new
sample program

Sorry for any confusion,

William


On Nov 6, 12:27 pm, William <bvwe...@gmail.com> wrote:
> JW,
>
> Sorry, I missed your most recent question until now.
>
> We recommend that your program be exactly these statements:
>
> http://code.google.com/p/jallib/source/browse/trunk/sample/12f629_bli...

Rob Hamerling

unread,
Nov 6, 2009, 2:06:09 PM11/6/09
to jal...@googlegroups.com

Jan Willem wrote:

> Wich part of my program is from Wouter? The 12F629.jal file is your
> file, only the line 'include jlib' is from Wouter, but i have try to
> compile it without this line, compiling is OK, but the .hex file is
> not good. Pin A0 is not high.

That is exactly what I meant: jlib.jal is not a Jallib library. Why
would you add it? None of the Jallib blink samples use any library.

> Also i have try the tip from Albert, but also compiling OK, .hex not
> good (pin A0 not high).
> The example from jallib is with crystal, i use te internal crystal
> (WDT).

WDT has nothing to do with Oscillator.
There are blink samples in Jallib which use the Internal oscillator,
e.g. 12F509_blink.jal. Copy the fuse_defs to your program.


> Can you please give all .jal files wich need for compile a .hex file
> in JALv2 that make the pinA0 high?

NONE! No libraries needed for these simple blink programs!

> I can't find what i do wrong. Maybe i have the wrong JalV2 compiler?

Compiler 2.4l is OK.

> My chip is OK, because when i use the .hex file from the voti site,
> pinA0 is switch high and low every second!

Because your program is incomplete! And creating a program that does
*not* work is far much easier than creating one that does work, and
getting it to work as expected is a number of steps further!

>
> My code is now (but not working) with the 12F629 from jallib:
> ------------------------
> include 12f629 -- target PICmicro
>
> enable_digital_io()
>
> var bit led is pin_A0
> pin_A0_direction = output
> --
>
> forever loop
> led = on
> end loop

Of course it doesn't work when you don't specify the required fuse_defs
as I suggested in my previous message?

Try the following:
> --


> include 12f629 -- target PICmicro

> --
> -- This program uses the internal oscillator at 4MHz
> pragma target clock 4_000_000 -- oscillator frequency
> -- configuration memory settings (fuses)
> pragma target OSC INTOSC_NOCLKOUT -- internal oscillator
> pragma target WDT disabled -- no watchdog
> pragma target MCLR external -- reset externally
> --
> enable_digital_io() -- disable analog I/O (if any)
> --
> -- You may want to change the selected pin:
> alias led is pin_A0


> pin_A0_direction = output
> --
> forever loop
> led = on

> _usec_delay(250000)
> led = off
> _usec_delay(250000)
> end loop

Sebastien Lelong

unread,
Nov 6, 2009, 1:12:39 PM11/6/09
to jal...@googlegroups.com
Hi

you may also want to have a look at this "blink a LED" tutorial, not
the same chip but same logic...

http://justanotherlanguage.org/content/tutorial_blink_a_led


Cheers
Seb
--
Sébastien Lelong

William

unread,
Nov 6, 2009, 4:19:33 PM11/6/09
to jallib
Very nice tutorial Seb!

When I get time, or perhaps you'll beat me to it, wouldn't it be great
to have one for the 8-pin parts, and using the internal oscillator?

William

On Nov 6, 12:12 pm, Sebastien Lelong <sebastien.lel...@gmail.com>
wrote:
> Hi
>
> you may also want to have a look at this "blink a LED" tutorial, not  
> the same chip but same logic...
>
> http://justanotherlanguage.org/content/tutorial_blink_a_led
>
> Cheers
> Seb
> --
> Sébastien Lelong
>

Jan Willem

unread,
Nov 6, 2009, 5:52:34 PM11/6/09
to jallib
Rob, Sebastien and William,

Tanks for your answers!

I have try the code example of Rob. The code is nearby OK. The pinA0
go not high, but i feel that the code is nearly OK. The fuses are
really needed. I don't no what the bottleneck is now, but maybe you
see?

Now i go sleeping (in the Netherlands it is 23:51), and tomorrow i am
working, but tomorrow in the evening or monday in the morning i am
curious to your anwers!

Again tanks and good bey,

Jan Willem

Sebastien Lelong

unread,
Nov 6, 2009, 5:00:46 PM11/6/09
to jal...@googlegroups.com

>
> Very nice tutorial Seb !

Yes and written by Matt ! as you say, nice tutorial, highly detailed
and covers a lot, including jallib pack structure, programming,...

>
cheers
seb

vasile surducan

unread,
Nov 7, 2009, 3:18:33 AM11/7/09
to jal...@googlegroups.com
Hi Jan,
 
Even if you heard the ideea that jal is the easiest language in the world, you still need to read completely the microcontroller datasheet before watching on any simple tutorial about blinking LED's.
In fact any tutorial should start with the following lines:
1. compiler documentation must be identified and read (for the first time at least like a story)
2. microcontroller documentation must be read (again, first time like a story, next 100 times like the bible)
3. all erata sheets must be identified and know that manufacturer problems exists and are already known
4. examples available with compiler distribution or on jallib must be identified, some of them works perfect as they are described but could not work properly on your specific application.
5. a source code compiled without errors means nothing in the real word.
 
Even if 1 to 5 passed OK, you may still have the problem of a damn LED which does not blink as you want. An this is valabile even if you are a beginner or advanced user.
 
best luck,
Vasile

 
On 11/6/09, Jan Willem <jwkl...@gmail.com> wrote:

Rob Hamerling

unread,
Nov 7, 2009, 4:14:38 AM11/7/09
to jal...@googlegroups.com

Hi Jan Willem

Jan Willem wrote:

> I have try the code example of Rob. The code is nearby OK.

I don't understand the 'nearby'. I have actually tested my code on a
real 12F629 and it works OK. Maybe your 12f629 (or the port) is defect.

> The pinA0
> go not high, but i feel that the code is nearly OK. The fuses are
> really needed. I don't no what the bottleneck is now, but maybe you
> see?

Where should I look?

Note: If you would like us to help you, then you should make it as easy
and effective as possible for us. We don't want to waste our time on
having to collect info from elsewhere or guessing what you mean.

Jan Willem

unread,
Nov 11, 2009, 11:45:50 AM11/11/09
to jallib
Hi Rob,

I have copy your code (the following) into my Jal Edit and i have
compile it:

=======================================================

include 12f629 -- target PICmicro
--
-- This program uses the internal oscillator at 4MHz
pragma target clock 4_000_000 -- oscillator frequency
-- configuration memory settings (fuses)
pragma target OSC INTOSC_NOCLKOUT -- internal oscillator
pragma target WDT disabled -- no watchdog
pragma target MCLR external -- reset externally
--
enable_digital_io() -- disable analog I/O (if any)
--
-- You may want to change the selected pin:
alias led is pin_A0
pin_A0_direction = output
--
forever loop
led = on
_usec_delay(250000)
led = off
_usec_delay(250000)
end loop

======================================================

The next .hex file is created:

======================================================
:020000040000FA
:100000000508A200073099008316051083122214F8
:100010002208850083120313FB30A000C630A10024
:100020000A128A11A10B10280A128A11A00B0E289D
:10003000000022102208850083120313FB30A00069
:10004000C630A1000A128A11A10B22280A128A11B5
:08005000A00B20280000062887
:02400E00F4318B
:00000001FF
======================================================

When i load this .hex file into my 12F629 chip, pin A0 is not going
high and low.
You have tested your code (your .hex file) in your 12F629 chip en
pinA0 is going high and low OK.
Can you give me, or can you compare what the different is between your
and my .hex file? The only reason that your code is working OK at your
chip and not at my chip, is that your .hex file is not the same as
my .hex file.
PinA0 of my chip is OK, because when i load the .hex file of Wouter,
pinA0 is going high and low.

I am very interesting what your .hex file is.

Best regards, Jan Willem

funlw65

unread,
Nov 11, 2009, 1:10:54 PM11/11/09
to jallib
Hmm, guys you forgot about this:

assembler
-- ========================
bsf _status, _rp0 -- bank 1
-- ========================
call 0x3ff -- get the factory calibrated OSC value
movwf osccal -- for accurate timing
-- ==================
bcf _status, _rp0 -- bank 0
-- ==================
end assembler

Should be included in device file for 12F629 and 12F675. Also, you
must pay attention at burning time, to not override that location of
flash memory....

a.faber

unread,
Nov 11, 2009, 2:09:47 PM11/11/09
to jal...@googlegroups.com
Hi Jan Willem,
Can you also describe your schematic, i.e. do you use a de-coupling
capacitor close the the power lines, how about the reset line, do you have a
pull-up resistor?
Albert

----- Original Message -----
From: "Jan Willem" <jwkl...@gmail.com>
To: "jallib" <jal...@googlegroups.com>

Rob Hamerling

unread,
Nov 11, 2009, 2:15:20 PM11/11/09
to jal...@googlegroups.com

Hi Jan Willem,

Jan Willem wrote:

> I have copy your code (the following) into my Jal Edit and i have
> compile it:

> ======================================================


> :020000040000FA
> :100000000508A200073099008316051083122214F8
> :100010002208850083120313FB30A000C630A10024
> :100020000A128A11A10B10280A128A11A00B0E289D
> :10003000000022102208850083120313FB30A00069
> :10004000C630A1000A128A11A10B22280A128A11B5
> :08005000A00B20280000062887
> :02400E00F4318B
> :00000001FF
> ======================================================

A compare shows that your hex file is exactly the same as mine (not
surprisingly!). Nevertheless I loaded it into my 12F629 and the led on
pin_A0 blinks as expected.

> When i load this .hex file into my 12F629 chip, pin A0 is not going
> high and low.

> You have tested your code (your .hex file) in your 12F629 chip en
> pinA0 is going high and low OK.
> Can you give me, or can you compare what the different is between your
> and my .hex file? The only reason that your code is working OK at your
> chip and not at my chip, is that your .hex file is not the same as
> my .hex file.

There must be another reason since the hex files are identical.

> PinA0 of my chip is OK, because when i load the .hex file of Wouter,
> pinA0 is going high and low.

I assume you used b675i-2.hex, I couldn't find any for the 12F629.
When I load this file into my 12F629 the led on A0 blinks as expected!

> I am very interesting what your .hex file is.

I'm afraid the problem is not with the hex file, and I have run out of
ideas what it could be!

Rob Hamerling

unread,
Nov 11, 2009, 2:58:44 PM11/11/09
to jal...@googlegroups.com

funlw65 wrote:
> Hmm, guys you forgot about this:
>
> assembler
> -- ========================
> bsf _status, _rp0 -- bank 1
> -- ========================
> call 0x3ff -- get the factory calibrated OSC value
> movwf osccal -- for accurate timing
> -- ==================
> bcf _status, _rp0 -- bank 0
> -- ==================
> end assembler

You are right that OSCCAL should be loaded with the calibrated value in
that high-memory location. And not only for the 2 PICs you mention, but
also for a number of others. I have a note in my todo list: 10Fs,
12F508,509,510,519,629,675 and 16F505,506,630,676, maybe more.

I think a simple 'asm movwf OSCCAL' as very first instruction will be
enough, because with a reset the program counter is set to the last
memory location (e.g. DS41239D 4.7.1 and 9.2.2).

Changing OSCCAL is fine tuning, omitting OSC calibration will not be the
cause that a led doesn't blink at all, only the blink frequency may be a
bit different.

When an accurate frequency is a required an external oscillator is the
way to go.

We have discussed the OSCCAL issue in the begin-period of the Jallib
group and decided then to spend out time on more urgent things.

> Should be included in device file for 12F629 and 12F675.

And in some others, if in the device files at all. It requires
co-operation with the compiler, because the compiler decides where code
is store in memory. Maybe it should be a pragma.

> Also, you
> must pay attention at burning time, to not override that location of
> flash memory....

True, use a proper programmer!

Wayne

unread,
Nov 11, 2009, 3:40:53 PM11/11/09
to jal...@googlegroups.com

Rob

I have been having a problem with, what I thought was with baud rate, in
a test file using the internal clock of the 16f628a. I noticed that
there was no OSCCAL in the device file. Not knowing for sure if that
(or me) was a problem, I grep'ed the svn device files for OCSCAL. I
come up with 289 devices with no OSCCAL in the files and 306 that have
OSCCAL in them.

Thought I must be mistaken as I did not realize you had done 'that' many
(595) devices, I just put it into my notes and continued to see if I
could get this k107 working.

Up till then I had been using 2 & 3 Terminal resonators but order some
20Mhz xtals Monday to see if maybe that is my problem. Live & learn.

Regards

Wayne

funlw65

unread,
Nov 11, 2009, 3:59:20 PM11/11/09
to jallib
I compiled/loaded this code and my 12f629 is working nice (using libs
from svn and pickit 2 with low pin count demo board):

include 12f629 -- target PICmicro
--
-- This program uses the internal oscillator at 4MHz
pragma target clock 4_000_000 -- oscillator frequency
-- configuration memory settings (fuses)
pragma target OSC INTOSC_NOCLKOUT -- internal oscillator
pragma target WDT disabled -- no watchdog
pragma target MCLR external -- reset externally
--

assembler
-- ========================
bsf _status, _rp0 -- bank 1
-- ========================
call 0x3ff -- get the factory calibrated OSC value
movwf osccal -- for accurate timing
-- ------------- start -------------------
-- ========================
bcf _status, _rp0 -- bank 0
-- ========================
end assembler


enable_digital_io() -- disable analog I/O (if any)
--
-- You may want to change the selected pin:
alias led is pin_A0
pin_A0_direction = output
--
forever loop
led = on
_usec_delay(250000)
led = off
_usec_delay(250000)
end loop

Vasi

funlw65

unread,
Nov 11, 2009, 4:22:00 PM11/11/09
to jallib
Hi Albert,

I tried right now on a bread board and is working with and without
pull-up resistor on MCLR.

Vasi

a.faber

unread,
Nov 11, 2009, 4:54:04 PM11/11/09
to jal...@googlegroups.com
That's by accident and not by design! Try touching the reset pin with your
fingers or switch on a fluorescent light bulb in the room, it will probably
reset, or if you toggle the pin(s) next to reset pin, it might cause a reset
due to capacitive coupling (which is quite high on bread boards)
Albert


----- Original Message -----
From: "funlw65" <fun...@gmail.com>
To: "jallib" <jal...@googlegroups.com>
Sent: Wednesday, November 11, 2009 10:22 PM
Subject: [jallib] Re: Blink a led with a 12f629



Hi Albert,

I tried right now on a bread board and is working with and without
pull-up resistor on MCLR.

Vasi

funlw65

unread,
Nov 11, 2009, 4:59:19 PM11/11/09
to jallib
Ok, I believe you. On such a small devices, I use MCLR internal to
have all pins available. But if MCLR is external, then should have the
correct circuit so, I believe it was an accident.
Vasi

Rob Hamerling

unread,
Nov 12, 2009, 3:39:46 AM11/12/09
to jal...@googlegroups.com

Hi Wayne,

Wayne wrote:

> I have been having a problem with, what I thought was with baud rate, in
> a test file using the internal clock of the 16f628a. I noticed that
> there was no OSCCAL in the device file. Not knowing for sure if that
> (or me) was a problem, I grep'ed the svn device files for OCSCAL. I
> come up with 289 devices with no OSCCAL in the files and 306 that have
> OSCCAL in them.
>
> Thought I must be mistaken as I did not realize you had done 'that' many
> (595) devices, I just put it into my notes and continued to see if I
> could get this k107 working.

There are currently 'only' 306 device files in Jallib. When I grep
OSCCAL 17 of these appear to contain OSCCAL (306-289 = 17), and 16f628
is not among these.

>
> Up till then I had been using 2 & 3 Terminal resonators but order some
> 20Mhz xtals Monday to see if maybe that is my problem. Live & learn.
>

I have several test boards with USART using a resonator (16 and 20 MHz)
and didn't ever notice a communications problem which pointed to an
aberration of the frequency. Maybe I was lucky to have good resonators.

Reply all
Reply to author
Forward
0 new messages