PDA

View Full Version : PIC16F628A Will not run at all....



thasatelliteguy
- 17th May 2014, 11:00
Can someone please tell me what I am missing? It seems to program, but no matter what I do, I can't get anything useful out of this POS...

#CONFIG
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _BODEN_ON
#ENDCONFIG
define OSC 4
TRISB.1 = 0
TRISB.2 = 0
LOW PORTB.2
LED var PORTB.1
START:
HIGH LED
PAUSE(500)
LOW LED
PAUSE(500)
HIGH LED
PAUSE(500)
LOW LED
PAUSE(500)
GOTO START

aratti
- 17th May 2014, 12:43
I don't see the oscillator register settings. You have to turn off comparators (if any). Did you pulled up the MCLR pin?

Cheers

Al.

thasatelliteguy
- 17th May 2014, 15:36
I don't see the oscillator register settings. You have to turn off comparators (if any). Did you pulled up the MCLR pin?

Cheers

Al.

Yes MCLR is 5V+

Isn't that what _INTRC_OSC_NOCLKOUT is for?

Is there a way to set the config bits using binary in pbp3? I have been searching for hours and its extremely frustrating to have so many different ways to do it apearantly, and none of them seem to work right. And the one I KNOW will work right, I can't find a damn syntax for....

My pic has a 14 bit config and I want 10000111111000 but I cannot figure out the command to enter it....

towlerg
- 17th May 2014, 15:54
You could use assembler directives (if PBP allows them)

thasatelliteguy
- 17th May 2014, 17:59
ok I got the PIC to run... But now I got no LCD. I may have jacked with it so much I trashed it. I hope not...

'************************************************* ***************
'* Name : HandHeld
'* Author : John Moore
'* Notice : Copyright (c) 2010
'* : All Rights Reserved
'* Date : May 16, 2014
'* Version : 1.0
'* Notes :
'* :
'************************************************* ***************
#CONFIG
__config 10000111100001
#ENDCONFIG
CMCON = 7

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44


LCDOUT $FE, $01
START:
LCDOUT "HELLO FKD"
LCDOUT $FE, $C0 "UP WORLD!"

GOTO START

Somebody see something I am missing that's making the LCD play dead? Contrast works, no response past that tho...

mark_s
- 17th May 2014, 21:32
Try the code below. I added some pause statements.




'************************************************* ***************
'* Name : HandHeld
'* Author : John Moore
'* Notice : Copyright (c) 2010
'* : All Rights Reserved
'* Date : May 16, 2014
'* Version : 1.0
'* Notes :
'* :
'************************************************* ***************
#CONFIG
__config 10000111100001
#ENDCONFIG


DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44

CMCON = 7
TRISB = 0 ' make portb output. probably already done in lcd defines, but good habit to set all port dir.
pause 1000 'let lcd initiate

LCDOUT $FE, $01
START:
LCDOUT "HELLO FKD"

LCDOUT $FE, $C0 "UP WORLD!"

pause 100 ' slow down
GOTO START

end

thasatelliteguy
- 19th May 2014, 05:29
I have no clue. Now I'm back to not working at all. And on top of that, now I've lost the page I found with the binary info to set the clock and I'm right back to square one cuz I can't set the clock. Everytime I try anything I find online, the syntax is wrong and I can't find it in the datasheet. After 2 solid months of this BS I'm about ready to use my Eastwing to fix it.....

thasatelliteguy
- 19th May 2014, 06:13
OK! Thanks for the help everyone! I'm pretty sure I hosed up the LCD now. I went and kicked the S*** outta the neighbor's dog for about 20 min, then came back and tried again.... I remembered that I saved a "I know this s*** works" file for this chip when I finally got it running. It's set for 4mhz. I was using a 12 crystal, so my ten second pause lasted only 3. Fair enough. I switched to an 8, 5 seconds, cool. Switched to a 4.00, and 10000 = 10 seconds... fabulous! Added the code for the LCD, LED still blinky blinky.... awesome! Added the LCD to the circuit.... LED still blinky blinky, contrast and backlight still work, but no other activity from the LCD.....

#CONFIG
__config 10000111100001
#ENDCONFIG

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44

LED VAR PORTB.1
CMCON = 7
TRISB = 0 ' make portb output. probably already done in lcd defines, but good habit to set all port dir.

High LED
PAUSE(1000)
LOW LED
LCDOUT $FE, $01

START:
LCDOUT "HELLO FKD"
LCDOUT $FE, $C0, "UP WORLD!"
HIGH LED
PAUSE(1000)
LOW LED
PAUSE(1000)
GOTO START
end

HenrikOlsson
- 19th May 2014, 06:40
Hi,
The problem is that previously there was two different ways of setting the CONFIG bits depending on which assembler you were using. With the introduction of PBP3 both those ways got superseded by a, MUCH better, third way.

With PBP3, which you must have since you've been using the #CONFIG/#ENDCONFIG directives the easiest way is to look in the DEVICE_REFERENCE folder and open up the .INFO file for your particular device. There you will find two things, A) What PBP is using by default and B) All the options available. Just remember that whenever you put the #CONFIG/#ENDCONFIG in your program ALL of the PBP default settings will be replaced so make sure that you either include a setting for all selections or know what they are by (hardware) default.

Yet another option is to use the new meCONFIG from meLabs and let it generate the CONFIG code for you.

The internal oscillator of the 16F628A is 4MHz by default, and there is no oscillator register setting, only a frequency select bit in PCON, so you shouldn't need to do "anything" really - except for selecting it of course. The .INFO file for the 16F628A shows two selections INTRC_OSC_NOCLKOUT and INTOSC_OSC_NOCLKOUT however they both result in the same thing, namely that the two LSB's of the CONFIG word being cleared which matches the datasheet for the INTOSC with I/O on RA6/RA7 selection.


My pic has a 14 bit config and I want 10000111111000 but I cannot figure out the command to enter it....
This, however does not look correct if what you want is the internal oscillator. As far as I can see this would select external low power crystal mode - not internal oscillator.

Then, in your actual code you had

#CONFIG
__config 10000111100001
#ENDCONFIG
Which again doens't look correct, this would select XT-oscillator.

So, please clarify which mode it is you want. If it's the internal oscillator then the code in the original post looks fine to me. There are no analog functions on PortB.

Which device programmer are you using? Are you sure that it's actually programming the CONFIG bits into the device?

/Henrik.

EDIT: OK, you posted while I was researching and typing.

thasatelliteguy
- 19th May 2014, 22:30
Sorry. Yes I am using an external on that chip. What I am doing is building a self-acquiring satellite system for data. (HughesNet) It will have a MC in the dish itself where all the "important thinking" will be happening. And then there will be a wireless handheld device connected via HC-05's. This will also allow for a cell phone app to control it via a customized BTserial-type app.

I just got the handheld to start (sorta) working now (minus the blown LCD I'm now waiting for)
I got the HC-05's linked

I just blew the last 688 I had for the embedded half. I switched out to a PICAXE14M2 I had laying around. (BTW this is the chip that got me over to PIC from Arduino) Since I now have a picKIT3, I wiped the bootloader and am using it as a 1825. This board is soldered already, and I used the pins for the CLK for something else. The internal clk would be fine but now a 10000 pause is 80 seconds. I cannot go down past OSC 4, and this is still 8 times to slow. How do I rectify this?



Is it really hijacking if it was your own thread?? ;-)

thasatelliteguy
- 19th May 2014, 22:39
Hi,
With PBP3, which you must have since you've been using the #CONFIG/#ENDCONFIG directives the easiest way is to look in the DEVICE_REFERENCE folder and open up the .INFO file for your particular device. There you will find two things, A) What PBP is using by default and B) All the options available. Just remember that whenever you put the #CONFIG/#ENDCONFIG in your program ALL of the PBP default settings will be replaced so make sure that you either include a setting for all selections or know what they are by (hardware) default.

Yet another option is to use the new meCONFIG from meLabs and let it generate the CONFIG code for you.


Yes, thank you. I had found this right before reading your post. Honestly, with the three different ways, plus finding C code in searches as well, this makes learning how to do the config extremely frustrating. Every time you think you understand a little part of it, it gets changes on you 2 more times...lol I found the reference to the configs in the device folder in the PBP manual and now FINALLY I understand it. (Sure wish I had known about that low voltage programming before I scrapped out that chip turning off MCLRE!) I haven't checked out the melabs tool yet, maybe I will. So far I am totally unimpressed with MPLAB altogether. I am so sick of retyping my work because they have boycotted the tilde for some reason. Also, pasting ANYTHING with most symbols locks it up tight too. I'm about to try out MC Studio....

HenrikOlsson
- 20th May 2014, 06:41
Hi,
Yes, I understand it's confusing with the pre PBP3 style CONFIG. It's a lot better with PBP3 than it was before though! However, I've got no sympathy for looking at C code and trying to implement THAT in PBP :-)

As for MPLAB(X) there is ONE reason (for me that is) to use it with PBP and that's source level debugging, if you don't need that then you don't need MPLAB(X). Personally I've tried to get MBLABX up and running twice and given up both times, feeling very stupid on both occasions.

/Henrik.

Archangel
- 20th May 2014, 18:48
Yes MCLR is 5V+

Isn't that what _INTRC_OSC_NOCLKOUT is for?



The config tells the PIC you want it to use the internal OSC, DEFINE OSC 4 tells PBP you are using 4 mhz so it knows how to adjust it's timing to agree with your intentions. I believe 4mhz is PBP default, but would not depend on defaults, period. Always define in your code what you expect, and the surprises (like not working) disappear.

thasatelliteguy
- 23rd May 2014, 07:26
I have now been on MC Studio for a couple days, and I have to say it rocks compared to mplabx. It auto-corrects capitalizations, and best of all it doesn't seize like an epileptic in a disco every five minutes...