PDA

View Full Version : Newbie need Help 16F627a



azmax100
- 17th January 2009, 10:59
Hi all,

I have problem with my first experience with of PBP PIC
My first attemp is blink an LED.

here is my program

CMCON = 7


TRISB.1 = 0


LED VAR PORTB.1 ' alias PORTB.4 to LED

loop: high LED ' turn on LED connected to PORTB.1
Pause 5000 ' delay for 5 seconds

low LED ' turn off LED connected to PORTB.1
Pause 1000 ' delay for 1 seconds

GoTo loop ' loop and blink LED forever

My problem
The LED did not turn on but when I (accidently) touch one of the pic pin the
led will on for a while then off again.

Can somebody help me with this problem.

Really need help from all the gurus in this forum.

Thanks and regards.

Archangel
- 17th January 2009, 18:21
Do you have a crystal and capacitors attached to the OSC pins, or a resonator? Add this to your code DEFINE OSC 4 . Use 4 if you are using 4mhz xtal, if you are using faster xtal you will need to change your default config statement to accept it.

Bruce
- 17th January 2009, 18:43
Kind of sounds like you left the /MCLR pin floating.

Archangel
- 17th January 2009, 19:01
Kind of sounds like you left the /MCLR pin floating.

DOH ! I missed that one . . :D

azmax100
- 18th January 2009, 04:19
Hi all.
thanks for the reply.
Joe S. I'm using 20mhz xtal. After Define still the same.

Bruce what should i do with the MCLR pin. I am totally zero with PIC but have some experience with BS2.

Archangel
- 18th January 2009, 08:19
Hi all.
thanks for the reply.
Joe S. I'm using 20mhz xtal. After Define still the same.


OK 20 mhz will not work with the default config statement, to use 20 mhz you must change it or comment it out of the PIC16F627A.INC file located in the PBP Directory. The Default config is set to use XT_OSC and the 20 mhz requires HS_OSC, what it does internaly is to provide the oscillator with more power, as it is needed to run that fast. Study this link : http://www.picbasic.co.uk/forum/showthread.php?t=543 As for the MCLR PIN tie a resistor about 5k ohm from mclr to thr 5v+ supply. To reset the PIC you then momentaraly ground it, OR in the config statement you turn it off and use it as an I/O.

azmax100
- 18th January 2009, 13:17
Joe S.
After editing the INC file in PBP I got this message

Error [113] c:\pbp\16f628.inc 22 : Symbol not defined (_HC_OSC)

For your info I'm using 16F628 now cause i broke some of the 16F627a pin while
remove it from my icsp.

Theres already a 10k resistor and a diode in series on my icsp module.

The LED blink when i touch the osc pin.

here's my code:
DEFINE OSC 20
CMCON = 7
OPTION_REG.7 = 0



TRISB.0 = 0
LED VAR PORTB.0 ' alias PORTB.0 to LED

loop:
high LED' turn on LED connected to PORTB.0
Pause 500 ' delay for .5 seconds

low LED ' turn off LED connected to PORTB.0
Pause 500 ' delay for .5 seconds

GoTo loop ' loop and blink LED forever

azmax100
- 19th January 2009, 15:31
I got my LED to blink. Problem solve. This is my first lesson. Under microcode studio compile and program option I uncheck the MPASM option. I should not use the MPASM compiler.

For other newbies please learn from my mistake.

Thanks to all the forum members.

Bruce
- 19th January 2009, 16:32
Hi azmax100,

FYI it really should work with either MPASM or the PM assembler. Look in your 16F628.INC and see if all config options are the same for both the PM & MPASM config settings.

It may be that you have some config options set different in the MPASM config line.

For example - say your 16F628.INC file has something like this



NOLIST
ifdef PM_USED
LIST
include 'M16F62x.INC' ; PM header
device pic16F628, hs_osc, wdt_on, pwrt_on, mclr_off, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F628, r = dec, w = -302
INCLUDE "P16F628.INC" ; MPASM Header
__config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
NOLIST
endif
LIST

Now let's say you're using the default PM assembler & not MPASM. When you compile, PBP knows you're using the PM assembler, so it uses these configuration settings --

device pic16F628, hs_osc, wdt_on, pwrt_on, mclr_off, lvp_off, protect_off

With a 20MHz crystal, you want/need the hs_osc setting. If you do not have a pull-up resistor on the PIC /MCLR pin, you also want the mclr_off setting.

Why? Because HS_OSC provides a higher drive level required by the higher speed 20MHz crystal. XT_OSC provides a lower drive level, which may or may not work.

MCLR_OFF turns OFF the external reset function on the /MCLR pin, so the external pull-up resistor isn't necessary.

Now, let's say you have no external pull-up, and you're using the 20MHz crystal, and you switch to use the MPASM asembler.

Again, when you compile, PBP will now know you're using the MPASM assembler, and it will now use the config settings shown above that look like this --

__config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF

Now it doesn't work because you have _XT_OSC (which doesn't provide enough drive to work with your 20MHz crystal), and you have the reset function enabled for the /MCLR pin with no pull-up to Vcc, and /MCLR is floating.

That would for sure cause erratic behaviour.

Just FYI. Config settings make a BIG difference.

Archangel
- 19th January 2009, 20:14
Hi azmax100, . . .



Just FYI. Config settings make a BIG difference.
This area seems to trap more new programmers than all the others, and is the most neglected, (by the current group of book authors), subject I have seen. This is one of those areas I am sure BRUCE will not neglect in his book. BTW Bruce, how is that coming ?

Archangel
- 19th January 2009, 20:30
Joe S.
After editing the INC file in PBP I got this message

Error [113] c:\pbp\16f628.inc 22 : Symbol not defined (_HC_OSC)

For your info I'm using 16F628 now cause i broke some of the 16F627a pin while
remove it from my icsp.
Theres already a 10k resistor and a diode in series on my icsp module.
The LED blink when i touch the osc pin.


Hi Azmax100,
First off, Congratulations on your sucess, It is so irritating to pour your time and effort into a project and it does not work as expected.
I have commented out the default config statements for the chips I use most often and always insert the config statement into my code.
This gives me flexibility to quickly change things like OSC, WDT, MCLR, BOD, and I never have to go hunt for the config settings in another file.

azmax100
- 20th January 2009, 04:11
Bruce
Thanks for the time explaining. I've spend three days just to make the LED to blink. I've experienced with Basic stamp 2. I know it's a little bit harder to play with PIC but I am willing to learn.
I will start a robotic project shown by you in rentron.com. For sure the will be a lot of of (silly) question. he he
Anyhow thanks to you and Joe s.

Fredrick
- 20th January 2009, 07:20
Do you have to change the configuration for the XS_osc and HS_osc in the .INC file or can i´t be done in the pbp program like this?


@ device pic16F628, hs_osc

azmax100
- 20th January 2009, 11:27
Fredrick
I include this
@ DEVICE pic16F628, HS_OSC in my program. Now it run smoothly.

azmax100
- 21st January 2009, 07:38
Bruce

(correction)

You are wright. The problem I can't compile with MPASM because it is not in the same directory with PBP. I read it somewhere in this forum post by Melanie.(do I spell it correctly).It's a good guide. Thanks Mel.

And regarding the book that you are written ( i read it in another thread) that's a good Idea. I am not going to be an ee engineer. I am learning this uC thing as a hobby. But might be someday my boy will be. It's good to share knowledge with other people and I consider what you have done and going to do will benefit others in future. After all we human being will leave all we have when the time come. So why not doing something good for others while we can.

This is my 2cents.