16F505

78 views
Skip to first unread message

Zet Weeh

unread,
May 10, 2020, 6:34:10 PM5/10/20
to jallib
Hi
I never worked with small PIC's.
I want to use the internal oscillator of the 16F505.
Is it correct I need to change in the library 16F505 in the oscillator part: 

pragma fuse_def OSC 0x7

in

pragma fuse_def OSC 0x4

Best regards,
Peter

Sunish Issac

unread,
May 11, 2020, 1:01:46 AM5/11/20
to jal...@googlegroups.com
No need to change the include file, use the modified blink sample below, which should work


--
include 16f505                     -- target PICmicro
--
-- This program assumes that a 4 MHz int osc.

pragma target clock 4_000_000      -- oscillator frequency
--
pragma target OSC      INTOSC_NOCLKOUT           -- Int osc, no clockout
pragma target WDT      DISABLED                  -- watchdog
pragma target MCLR     INTERNAL                  -- internal reset
--
-- The configuration bit settings above are only a selection, sufficient
-- for this program. Other programs may need more or different settings.
--
--
enable_digital_io()                 -- make all pins digital I/O
--
-- A low current (2 mA) led with 2.2K series resistor is recommended
-- since the chosen pin may not be able to drive an ordinary 20mA led.
--
alias  led       is pin_B0          -- alias for pin with LED
--
pin_B0_direction = OUTPUT
--
forever loop
   led = ON
   _usec_delay(100_000)
   led = OFF
   _usec_delay(400_000)
end loop
--

Sunish

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/6dcbce49-7c22-4788-a843-1a953abbd5f4%40googlegroups.com.

Zet Weeh

unread,
May 11, 2020, 4:45:54 PM5/11/20
to jallib

Hi Sunish

Thanks for your fast reply. I have three questions ( written in red).

xx -- In the datsheet on page 40 I see some configuration-bits but the register has no name. Is it still possible to use those bits?


pragma target clock 4_000_000      -- oscillator frequency
--
pragma target OSC      INTOSC_NOCLKOUT           -- Int osc, no clockout ………..>>>>> in the datasheet and in the library16F505:  I can't find 'noclkout'

pragma target WDT      DISABLED                  -- watchdog
pragma target MCLR     INTERNAL                  -- internal reset
--
-- A low current (2 mA) led with 2.2K series resistor is recommended
-- since the chosen pin may not be able to drive an ordinary 20mA led.  ……….>>>>>> in the datasheet the pin can deliver 25 mA/that is enough for a standard led
--
--Best regards,

Peter

Op maandag 11 mei 2020 00:34:10 UTC+2 schreef Zet Weeh:

Rob CJ

unread,
May 12, 2020, 1:51:45 AM5/12/20
to jallib
Hi David,

Not sure which bits you mean on page 40. In general if bits that are defined as XX are not relevant and should not be used.

The INTOSC_NOCLKOUT  is called a bit differently in the datasheet since there can be inconistencies between the datasheet and what Microchip releases as chip information. It is best to look at the JAL device file for your chip, all configuration are shown at the end of the device file.

One pin can indeed drive 25 mA and in general the maximum for a standard LED is 20 mA. It is not the intention of the sample program to show that a LED can blink bright but just to show that the LED blinks. You can change the resistor value to e.g. 330 Ohm but you have to keep in mind that the chip itself cannot handle 25 mA on all ports at the same time. From the top of my head I thought that the chip in total can handle only a maximum 75 mA.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Zet Weeh <zet....@gmail.com>
Verzonden: maandag 11 mei 2020 22:45
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] Re: 16F505
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

Oliver Seitz

unread,
May 12, 2020, 2:03:55 AM5/12/20
to jal...@googlegroups.com
The blink samples are generated by a script. They all use a certainly named port pin.

Once a user complained that the blink sample did not work. It was due to a read/modify/write problem on a certain chip, which actually could only drive 3.5mA on the standard pin. There were solutions discussed, including to have different blink samples which use a per-chip selected pin that can drive 25mA. That would have been a huge amount of work for a very small effect. So the solution chosen was to just recommend a low current LED for all samples.


Greets,
Kiste


Am Mo., Mai 11, 2020 at 22:45 schrieb Zet Weeh

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit

Rob CJ

unread,
May 12, 2020, 3:31:05 AM5/12/20
to jal...@googlegroups.com
Hi Kiste,
Good to know some of the history, I did not know that. Thanks.

Kind regards,
Rob


Met vriendelijke groet,
Rob Jansen

From: 'Oliver Seitz' via jallib <jal...@googlegroups.com>
Sent: Tuesday, May 12, 2020 8:03:52 AM
To: jal...@googlegroups.com <jal...@googlegroups.com>
Subject: AW: [jallib] Re: 16F505
 

Zet Weeh

unread,
May 12, 2020, 7:50:56 AM5/12/20
to jallib
Hi everybody

Thanks for the answers. I learned a lot.

The question of page 40 was not clear. I'll try again:
A register has a name like OSCCAL. I can use that name in a pragma.


OSCCAL register.JPG

On page 40 of the datasheet PIC 16F505 I found:

Configuration word register.JPG

This register has no name. How can I now use FOSC 100.

Hope my question is now clear.

Best regards, Peter

Rob CJ

unread,
May 12, 2020, 7:59:15 AM5/12/20
to jal...@googlegroups.com
Hi Peter,

The configuration word is set using the pragma.

Kind regards,

Rob


Met vriendelijke groet,
Rob Jansen

From: jal...@googlegroups.com <jal...@googlegroups.com> on behalf of Zet Weeh <zet....@gmail.com>
Sent: Tuesday, May 12, 2020 1:50:56 PM
To: jallib <jal...@googlegroups.com>
Subject: [jallib] Re: 16F505
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

Zet Weeh

unread,
May 12, 2020, 8:09:02 AM5/12/20
to jallib
Hi Rob
 
So I can write:
 
pragma target FOSC100 

Kind regards, Peter

Rob CJ

unread,
May 12, 2020, 12:00:22 PM5/12/20
to jallib
Hi Peter,

No the pragma fills the configuration registers. These are special registers in the PIC and are also programmed separately since they are not part of the normal program memory.

For example, the pragma MCLR INTERNAL will clear the MCLR bin in the Config register.

Note the following. The datasheet for the PIC12F508/509/16F505 has a different config word for the 16F505, the one might have looked at was for the 12F508/509.

If you look at the datasheet for the 16F505 you see for FOSC:


and in the device file for the 16F505 you find:

pragma fuse_def OSC 0x7 {                -- Oscillator Selection bits
       RC_CLKOUT = 0x7                   -- External RC oscillator/CLKOUT function on RB4/OSC2/CLKOUT pin
       RC_NOCLKOUT = 0x6                 -- External RC oscillator/RB4 function on RB4/OSC2/CLKOUT pin
       INTOSC_CLKOUT = 0x5               -- Internal RC oscillator/CLKOUT function on RB4/OSC2/CLKOUT pin
       INTOSC_NOCLKOUT = 0x4             -- Internal RC oscillator/RB4 function on RB4/OSC2/CLKOUT pin
       EC_NOCLKOUT = 0x3                 -- EC oscillator/RB4 function on RB4/OSC2/CLKOUT pin
       HS = 0x2                          -- HS oscillator
       XT = 0x1                          -- XT oscillator
       LP = 0x0                          -- LP oscillator

So as  you see the pragma map on the config bits.

I hope this clarifies it.

Kind regards,

Rob



Verzonden: dinsdag 12 mei 2020 14:09

Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] Re: 16F505
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

Zet Weeh

unread,
May 13, 2020, 5:33:43 PM5/13/20
to jallib
Hi Rob

Thanks for your help.

I used the right config word; only the 16F505 has FOSC 100.

Now I know how it works I found the rest of the config word also.

There is written:

pragma fuse_def MCLR 0x20 {              -- RB3/MCLR Pin Function Select bit
       EXTERNAL = 0x20                   -- RB3/MCLR pin function is MCLR
       INTERNAL = 0x0                    -- GP3/MCLR pin function is digital input, MCLR internally tied to VDD


but GP3 is of the 12F508/509. I think this has to be RB3?

Best regards,
Peter

Rob CJ

unread,
May 14, 2020, 2:24:04 AM5/14/20
to jal...@googlegroups.com
Hi Peter,

I need to check where the comments come from I do not know why microchip uses the different terminology for that.

Kind regards,

Rob


Verzonden: woensdag 13 mei 2020 23:33

Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] Re: 16F505
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

Sunish Issac

unread,
May 14, 2020, 1:29:06 PM5/14/20
to jal...@googlegroups.com
Hi Peter, 
Sorry for the late reply. 

Easy thing for you to do is to burn the hex to the chip with the modified sample I shared. 

Regarding GP3, its just the comment. RB3 .

Kind regards,
Sunish



--

Zet Weeh

unread,
May 15, 2020, 3:51:49 AM5/15/20
to jallib
Hi Sunish

I think GP3 is a slip of the pen.

And for the moderator: this issue can be closed: I know what I wanted to know.
Everybod: Thanks for the help.

Kindly regards,
Peter

Oliver Seitz

unread,
May 15, 2020, 4:00:12 AM5/15/20
to jal...@googlegroups.com
Probably :-)

I recall it is used in some old datasheets of controllers which only have a single I/O port for "General Purpose".

Greets,
Am Fr., Mai 15, 2020 at 9:51 schrieb Zet Weeh

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit
Reply all
Reply to author
Forward
0 new messages