PDA

View Full Version : PIC16F886 not running.



Lilleljung
- 4th January 2015, 18:56
Hello everybody.
I need help. I just cant get a simple blink-program to work with picbasic pro. I have tried the same (almost) program in GCB, and the chip works.
No problem when I compile.
Is there any kind soul out there who can help me getting started with PBP3, so I can blink the d***m LED??

Archangel
- 4th January 2015, 19:03
Let us see what you have got, and we will help YOU make it work.

read data sheet re:ANSEL ANSELH ADCON0 ADCON1
PICs typically default to analog ports and YOU MUST tell them to do digital.

Lilleljung
- 4th January 2015, 20:08
Im not very good at pics yet, but im learning :)

This is what I have. I just want the PIC to light up. I have the LED connected to PORTB.0

I have tried a lot of different examples, but none works.

__________________________________________________ _
TRISB = %11111111
TRISC = %00000000
ANSEL = %00000000 ' Make AN0-AN7 digital
ANSELH= %00000000 ' Make AN8-AN13 digital
PORTB = 1


main:
portb=1
pause 100
goto main
__________________________________________________ ___

This works in GCB, but I think that compiler does a lot in the background for me.

Lilleljung
- 4th January 2015, 20:42
Updated code

TRISB = %00000000
ADCON0 = %00000000


ANSEL = %00000000 ' Make AN0-AN7 digital
ANSELH= %00000000 ' Make AN8-AN13 digital
PORTB = 1



main:
portb=1
pause 100
goto main

Archangel
- 5th January 2015, 00:49
To make it blink you have to turn it off too
PortB.0 = 0
pause 100

Do you have a config statement.

Don't forget to tell PBP whay Oscillator speed.
DEFINE OSC 4

I have not studied this chip but it has OSCON registers and OSCTUNE registers.

Try OSCCON = %01100000 sets oscon to 4mhz (default)

muddy0409
- 5th January 2015, 00:52
Um........That wouldn't blink the led (which is on PB0?) it would just turn it on permanently.

Your main should be something like...

main:
portb.0 = 1
pause 100
portb.0 = 0
pause 100
goto main


Could also be

main:
portb = 0
pause 100
portb = 1
pause 100
goto main

Hope this helps.
About time I offered some help, instead of just asking for help, for a change.

Acetronics2
- 5th January 2015, 18:55
Hi, Peter

Have a Happy new Year !

we also could write it :




PORTB = 0
TRISB = %00000000
ADCON0 = %00000000

ANSEL = %00000000 ' Make AN0-AN7 digital
ANSELH= %00000000 ' Make AN8-AN13 digital

WHILE 1
TOGGLE PortB.0
pause 300 ' just to see something ...
WEND

END



Note PBP+ chip defaults are not shown here ... but don't NEVER forget they exist !!!

Lilleljung
- 5th January 2015, 19:54
Hi everybody and thanks for all the input.
Youre right, it wont blink. I just want to get the LED light up so I see that something is happening. For now, nothing works and no LED lights up. I have connected LEDs to all PORTB, so I can see if anything is going on on the chip.
I have tried all of your suggestions here but still dont work.

I thougt that the CONFIG was in the INC-file in PBP? Do I have to write something in code to make it start?

Acetronics2
- 5th January 2015, 20:37
a little scheme ( the real one ... ) would be useful now ... especially for the RESET pin ...

Lilleljung
- 5th January 2015, 23:04
I did a schematic in PCB express and this is exactly how its connected. I just want some LED to light up.
This one works perfect then I use GCB and PICPgm to program the chip. I use PICPgm to program it now too.7667

Updated the code to use some LEDS on PORTC too, but no luck...

DEFINE OSC 4

OSCCON = %01100000

PORTB = 0
PORTC = 1
TRISB = %00000000
TRISC = %00000000

ADCON0 = %00000000

ANSEL = %00000000 ' Make AN0-AN7 digital
ANSELH= %00000000 ' Make AN8-AN13 digital

WHILE 1
TOGGLE PortB.0

toggle portc.0
toggle portc.1


pause 300 ' just to see something ...
WEND

END

skimask
- 6th January 2015, 04:43
Osccon = %01100001

richard
- 6th January 2015, 05:16
default pbp3 fuse config

__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF

yet you have no pull up resistor on mclre_pin (1)
no vss on pin 8
no current limiting resistors for leds ( will cause rmw issues)
what is that unspecified thing between portb7 and mclre ?

Acetronics2
- 6th January 2015, 06:57
LilleJung,

PLEASE ....

open your Datasheet and begin by the supply circuit, then the Reset (MCLR) wiring ... one more trail from those, and your '886 is fried ...

Alain

PS:@ Skimask: ... the well known guy ???

rmteo
- 6th January 2015, 07:56
PS:@ Skimask: ... the well known guy ???

http://www.picbasic.co.uk/forum/showthread.php?t=19652&p=130436#post130436

Lilleljung
- 6th January 2015, 10:17
YEAH!!!, almost.....
The config statement helped a bit, now the LEDs on PORTC blinks. But nothing on PORTB.
I set MCLRE_OFF instead of MCLRE_ON and now I even can have the programmer connected and the chip works.
I have a pull-up resistor on MCLR also, but it works without it too. And current limiting resistors on the LEDs.
Now all I want is to get PORB to blink, then im up and running. I really want to migrate to PBP. GCB was great, but a little too many bugs for me.

PORTB.6 and PROB.7 is always connected to the programmer circuit (a homemade AN589 programmer).

The thing is that when I used the original circuit and wrote the code in GCB, everything worked...

New code...
_______________________________________
#config
__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
#endconfig

DEFINE OSC 4

OSCCON = %01100001

PORTB = 0
PORTC = 1
TRISB = %00000000
TRISC = %00000000

ADCON0 = %00000000

ANSEL = %00000000 ' Make AN0-AN7 digital
ANSELH= %00000000 ' Make AN8-AN13 digital

WHILE 1
TOGGLE PortB.0

toggle portc.0
toggle portc.1


pause 300 ' just to see something ...
WEND

END
_____________________________

muddy0409
- 6th January 2015, 10:53
Your schematic also is not showing a connection between the programmer and negative power (Vss)
I imagine that should be the spare terminal on the program connector?
Which programmer are you using?

skimask
- 6th January 2015, 14:27
Quit using TOGGLE. It's a R/M/W instruction. Set it high, pause, set it low, pause, loop.

Demon
- 6th January 2015, 19:11
Suggest reading the first few chapters of PBP manual.

Robert

Lilleljung
- 6th January 2015, 21:25
The circuit works. If i do the same thing in GCB, I have no problem. Its just to get PBP to do the same thing. But the config solved most of it. just a few things left, like make the analog to digitla outputs. But I hope to solve that tonight.
Im using a AN589 programmer, and its works great with code from GCB.

I did read the first chapters, but I just couldnt get the PIC started.

Somehow the portb is solved too. I changed PortB to portb, programmed it, and now, for some undefined reason. it works....
After that, I can use PortB (with caps) again and it works!!!
Dont know why, dont care for the moment, im up and running...

Thank you all for all the help.

Ill be back if something else wont work for me.. :-)

Demon
- 6th January 2015, 21:35
Search the forum for ALLDIGITAL. It will help you determine what you need to make all pins digital.

Robert