PDA

View Full Version : PIC16F767 blinking code



DanPBP
- 23rd September 2006, 08:14
Hello Guys,

I'm having some problems trying to make this pic to work, do you see anything wrong with my blinking code?

@ DEVICE PIC16F767, INTRC_OSC_NOCLKOUT, WDT_ON, PROTECT_OFF
OSCCON=%01111000 '8Mhz
TRISB = 0

loop:
High PORTB.7
Pause 500
Low PORTB.7
Pause 500
GoTo loop
End

Anything missing on the @ statement?

Thank you very much.

Regards,
Daniel.

paul borgmeier
- 23rd September 2006, 12:03
Two ideas to try:

1) Try OSCCON %01110000 instead of %01111000 (you do not appear to be switching from a Primary OSC - see first few paragraphs of datasheet section 4.6 and description (and foot note) of OSCCON<3>)

2) What are you doing with MCLR - is it tied high?

DanPBP
- 24th September 2006, 06:24
Hi Paul,

Thanks for your help, I've been working with pics for almost four years now, but never used the internal oscillator before.

I think I'm having some problems with my parallel programmer, because is not programming the code.

Do you know if the 16F767 need any special requirement to be programmed?

Thank you very much.

Regards,
Daniel.

DanPBP
- 11th October 2006, 03:03
At last, after two weeks and a new programmer, a 16F767 working blinking code:

@ DEVICE PIC16F767, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE PIC16F767, WDT_ON ; Watchdog Timer
@ DEVICE PIC16F767, PWRT_ON ; Power-On Timer
@ DEVICE PIC16F767, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic16F767, PROTECT_OFF ; Code Protect Off

OSCCON=%01110000

main:
High PORTB.7
Pause 500

Low PORTB.7
Pause 500

GoTo main
End

sayzer
- 11th October 2006, 03:31
Hi Daniel,

Is "DEFINE OSC 8" necessary in this case or not?

Eventhough you set OSCCON, how does PBP know that it is 8Mhz?

------------------

DanPBP
- 11th October 2006, 03:57
Because OSCCON=%01110000 sets the internal oscillator to 8Mhz...

Read the 16F767 datasheet section 4.6.3 for other frequencies...

PICs makes me love and hate them at the same time.... :)

mister_e
- 11th October 2006, 05:20
In those situation, you need to take a break and have a cup of coffee
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1118&stc=1&d=1160540385">

sayzer
- 11th October 2006, 07:04
Because OSCCON=%01110000 sets the internal oscillator to 8Mhz...

For sure it does set it to 8Mhz but don't we also need to state DEFINE?


---------------------

DanPBP
- 11th October 2006, 14:42
I don't think so... So far It's working fine...

I think that DEFINE OSC is for external oscillators only, but not sure...

mister_e
- 11th October 2006, 14:56
NOPE, DEFINE is a compiler directive and MUST be added at the top of the code. OSCCON is a PIC register that must be set like all the otheres. Let's Say TXSTA, RCSTA, SPBRG.

Do a simple Test, with your current OSCCON setting do a simple LED blink. use DEFINE OSC 4.. then use DEFINE OSC 8

what happen?

sayzer
- 11th October 2006, 16:28
NOPE, DEFINE is a compiler directive and MUST be added at the top of the code. OSCCON is a PIC register that must be set like all the otheres. Let's Say TXSTA, RCSTA, SPBRG.

Do a simple Test, with your current OSCCON setting do a simple LED blink. use DEFINE OSC 4.. then use DEFINE OSC 8

what happen?


That is what I thought so.
Daniel, could you pls test it and post the result?


-----------------

DanPBP
- 16th October 2006, 09:11
With DEFINE OSC 8 the LEDs are blinking slowly...

With DEFINE OSC 4 the LEDs are blinking faster...

I'm confused... :|

mister_e
- 16th October 2006, 14:25
Normal... they have to blink twice the speed of DEFINE OSC 8 right?