View previous topic :: View next topic |
Author |
Message |
Ringo42
Joined: 07 May 2004 Posts: 263
|
help with pic16f506 |
Posted: Mon Oct 18, 2010 8:21 pm |
|
|
I'm using a 16f506 and CCS PCB C Compiler, Version 3.249
Here is my code
Code: | #include <16f506.h>
#fuses intrc_io,NOWDT
#use delay(clock=4000000)
Main()
{
while(1)
{
output_high(PIN_C2);
delay_ms(500);
output_low(PIN_C2);
delay_ms(500);
}
} |
It acts like it programs but nothing happens on pin C2. Any ideas? The chip only has a .1uf cap on vcc and a 10k pullup on mclr. No other circuitry except the programming header. I'm looking at pin C2 with an o-scope. Is there something else I need to do to get this to run?
Ringo _________________ Ringo Davis |
|
|
biozen
Joined: 08 Sep 2010 Posts: 10
|
|
Posted: Tue Oct 19, 2010 4:00 am |
|
|
You'll need to set up the port pins as inputs and outputs. Something like:
Code: | SET_TRIS_C(0b00000000); |
Regards,
Mohit Mahajan.
(Edit: Formatting) |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Oct 19, 2010 5:01 am |
|
|
biozen wrote: | You'll need to set up the port pins as inputs and outputs. Something like:
Code: | SET_TRIS_C(0b00000000); |
Regards,
Mohit Mahajan.
(Edit: Formatting) |
No he won't, he would only need to do this if he were using fastio.
Post the .lst code
It is most likely your fuse settings, you probably need NOLVP or something. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2010 12:36 pm |
|
|
I didn't immediately see anything wrong in the .LST file for vs. 3.249.
My suggestion is to use a pin that has no other functions, such as pin C3.
See if it still fails. If so, start looking at Programmer problems, external
circuit problems, soldering, component values, component orientation
(led anode/cathode), voltages, etc. |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Oct 19, 2010 12:40 pm |
|
|
I've tried lots of different fuse options. I even tried adding a xtal and changing the fuse to HS but nothing happens. When I probe the OSC pins they are both low. Shouldn't 1 be high and the other low (if the xtal did not start for some reason).
here is the latest C code
Code: | #include <16f506.h>
#FUSES NOWDT //No Watch Dog Timer
//#FUSES INTRC //Internal RC Osc
#FUSES HS //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#use delay(clock=4000000)
Main()
{
output_high(PIN_b2);
while(1)
{
output_high(PIN_b2);
delay_ms(200);
output_low(PIN_b2);
delay_ms(200);
}
} |
and the lst that goes with it.
*
0000: GOTO 015
0001: GOTO 002
.................... #include <16f506.h>
.................... //////// Standard Header file for the PIC16F506 device ////////////////
.................... #device PIC16F506
.................... #list
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... //#FUSES INTRC //Internal RC Osc
.................... #FUSES HS //Internal RC Osc
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES MCLR //Master Clear pin enabled
....................
.................... #use delay(clock=4000000)
0002: MOVF 10,W
0003: BTFSC 03.2
0004: GOTO 014
0005: MOVLW 01
0006: MOVWF 0E
0007: CLRF 0D
0008: DECFSZ 0D,F
0009: GOTO 008
000A: DECFSZ 0E,F
000B: GOTO 007
000C: MOVLW 4A
000D: MOVWF 0D
000E: DECFSZ 0D,F
000F: GOTO 00E
0010: NOP
0011: NOP
0012: DECFSZ 10,F
0013: GOTO 005
0014: RETLW 00
....................
.................... Main()
.................... {
0015: CLRF 04
.................... output_high(PIN_b2);
0016: MOVLW FF
0017: MOVWF 0F
0018: BCF 0F.2
0019: MOVF 0F,W
001A: TRIS 6
001B: BSF 06.2
.................... while(1)
.................... {
.................... output_high(PIN_b2);
001C: BCF 0F.2
001D: MOVF 0F,W
001E: TRIS 6
001F: BSF 06.2
.................... delay_ms(200);
0020: MOVLW C8
0021: MOVWF 10
0022: CALL 002
.................... output_low(PIN_b2);
0023: BCF 0F.2
0024: MOVF 0F,W
0025: TRIS 6
0026: BCF 06.2
.................... delay_ms(200);
0027: MOVLW C8
0028: MOVWF 10
0029: CALL 002
.................... }
002A: GOTO 01C
.................... }
....................
002B: SLEEP
Configuration Fuses:
Word 1: 0FF2 HS NOWDT NOPROTECT MCLR IOSC8
I have used several different pics before, but this is the first time I have tried a 506. I have tried 3 different chips, so it is not a bad one. Am I missing something special about this chip?
Ringo _________________ Ringo Davis |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2010 12:47 pm |
|
|
Use your programmer to read the program memory of the 16F506.
What's the value at address 0x3FF ? This is the last address.
It's supposed to hold the OSCCAL value. Post the HEX value that you
read there. |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Oct 19, 2010 5:58 pm |
|
|
How do i read the file to determine location 3ff?
Here is the entire file for the last code I posted.
:10000000150A020A10024306140A010C2E006D00A4
:10001000ED02080AEE02070A4A0C2D00ED020E0A54
:1000200000000000F002050A00086400FF0C2F0029
:100030004F040F02060046054F040F020600460556
:10004000C80C300002094F040F0206004604C80C19
:10005000300002091C0A0300FF0FFF0FFF0FFF0F04
:10006000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F20
:10007000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F10
:10008000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F00
:10009000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FF0
:1000A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FE0
:1000B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FD0
:1000C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FC0
:1000D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FB0
:1000E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FA0
:1000F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F90
:10010000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F7F
:10011000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F6F
:10012000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F5F
:10013000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F4F
:10014000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F3F
:10015000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F2F
:10016000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F1F
:10017000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F0F
:10018000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FFF
:10019000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FEF
:1001A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FDF
:1001B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FCF
:1001C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FBF
:1001D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FAF
:1001E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F9F
:1001F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F8F
:10020000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F7E
:10021000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F6E
:10022000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F5E
:10023000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F4E
:10024000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F3E
:10025000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F2E
:10026000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F1E
:10027000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F0E
:10028000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FFE
:10029000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FEE
:1002A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FDE
:1002B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FCE
:1002C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FBE
:1002D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FAE
:1002E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F9E
:1002F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F8E
:10030000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F7D
:10031000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F6D
:10032000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F5D
:10033000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F4D
:10034000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F3D
:10035000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F2D
:10036000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F1D
:10037000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F0D
:10038000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FFD
:10039000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FED
:1003A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FDD
:1003B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FCD
:1003C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FBD
:1003D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FAD
:1003E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F9D
:1003F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F8D
:10040000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F7C
:10041000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F6C
:10042000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F5C
:10043000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F4C
:10044000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F3C
:10045000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F2C
:10046000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F1C
:10047000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F0C
:10048000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FFC
:10049000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FEC
:1004A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FDC
:1004B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FCC
:1004C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FBC
:1004D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FAC
:1004E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F9C
:1004F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F8C
:10050000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F7B
:10051000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F6B
:10052000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F5B
:10053000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F4B
:10054000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F3B
:10055000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F2B
:10056000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F1B
:10057000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F0B
:10058000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FFB
:10059000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FEB
:1005A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FDB
:1005B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FCB
:1005C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FBB
:1005D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FAB
:1005E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F9B
:1005F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F8B
:10060000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F7A
:10061000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F6A
:10062000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F5A
:10063000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F4A
:10064000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F3A
:10065000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F2A
:10066000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F1A
:10067000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F0A
:10068000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FFA
:10069000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FEA
:1006A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FDA
:1006B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FCA
:1006C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FBA
:1006D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FAA
:1006E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F9A
:1006F000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F8A
:10070000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F79
:10071000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F69
:10072000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F59
:10073000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F49
:10074000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F39
:10075000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F29
:10076000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F19
:10077000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F09
:10078000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FF9
:10079000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FE9
:1007A000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FD9
:1007B000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FC9
:1007C000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FB9
:1007D000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0FA9
:1007E000FF0FFF0FFF0FFF0FFF0FFF0FFF0FFF0F99
:1007F000FF0FFF0FFF0FFF0FFF0FFF0FFF0F1C0C6F
:08080000FF0FFF0FFF0FFF0FB8
:021FFE00F20FE0
:00000001FF
;PIC16F506 _________________ Ringo Davis |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2010 6:13 pm |
|
|
Actually I was hoping you would go View Program Memory in MPLAB
and just scroll down to address 03FF and read the value of the word
at that location. |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Oct 19, 2010 6:16 pm |
|
|
I don't use mplab. Is there a way to do it with the CCS icd program? _________________ Ringo Davis |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Oct 19, 2010 8:28 pm |
|
|
If I do read configuration I get FF02 _________________ Ringo Davis |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2010 9:30 pm |
|
|
Actually I didn't want the configuration. I wanted you to read the PIC
with the programmer (ICD, etc.) and then look in the Program Memory
window of your IDE and see what the value at address 0x3FF is.
Your hex file does have 0xC1C (MOVLW 0x1C) at address 0x3FF, which
is a reasonable thing to have there. But because of various protection
mechanisms in various IDE's, I don't think that in fact guarantees that
the value in the actual PIC will be the same. That's why I wanted you
to read it. But I don't think we're making any progress on that.
Your reported Config word in your last post is weird. You reported FF02.
Your Hex file has 0FF2. Your .LST file also has 0FF2. So I don't know if
your PIC really has FF02 or you just transposed it in typing. I feel like
I want to give up.
You didn't say what your programmer is - whether it's an ICD of some
type or a home-built unit using icProg, etc. If it's home built, I suspect
that it may not support this PIC properly. That's just a guess. |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Oct 19, 2010 9:34 pm |
|
|
It was a copy and paste so I did not type it in wrong. I'll see if I can mplab installed tomorrow. Thanks for the help. _________________ Ringo Davis |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Wed Oct 20, 2010 8:42 am |
|
|
Oh yeah, and the programmer is the CCS ICD-U40. _________________ Ringo Davis |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 25, 2010 4:42 pm |
|
|
I bought a 16F506 (I added it to an existing order). I got it today and
installed in my 3M breadboard and compiled the following program and it
ran OK. It blinks an LED on pin C3.
To install your same version of the compiler (PCB 3.249), I downloaded
MPLAB vs. 7.41 and installed it. This put the PCB compiler in the "Third
Party" folder in the \Program Files\Microchip directory. I then copied
that PICC folder to my desktop. Then I put MPLAB vs. 8.56 back on my
system again. I saved out the vs. 4.073 PCB compiler that it installs,
and put a copy of its \PICC folder on my desktop (giving unique names
to each folder). Then I deleted it in the Microchip directory and put in
vs. 3.249. This all took a while and it was not totally fun. But anyway
I compiled the program below with v3.249 and ran it and it worked.
If you can't make this work, I'll take a photo of my 3M breadboard later
today and post it on Imageshack, and you can see how simple the
hardware setup is.
I'm wondering if you have mixed versions of the CCS compiler on your
system. For example, do you have vs. 4.xxx of the PCM compiler but
vs. 3.249 of PCB, with both of them in the same directory ? If so, only
the last one that was installed will be reliable. If you do it the way that I
did, where you have to go into MPLAB and specify the tool location, then I
think it's safe to have different versions on the same machine (of the
command line compilers). I'm not talking about the IDE versions. I
know, as Ttelmah has said, that you can have different versions of that
compiler on your system.
Anyway, try this:
Code: |
#include <16F506.H>
#fuses INTRC_IO,IOSC8,NOWDT,MCLR
#use delay(clock=8000000)
//=========================
void main()
{
while(1)
{
output_high(PIN_C3);
delay_ms(500);
output_low(PIN_C3);
delay_ms(500);
}
} |
|
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Mon Oct 25, 2010 8:02 pm |
|
|
After trying 4 different 506's I give up. The 505 works as well as the 688.
I'm using the 505 and pin c% does not work. The data sheet says
On power-up, TOCKI functionality is
enabled in the OPTION register and must
be disabled to allow RC5 to be used as
general purpose I/O.
But I can't figure out how to do it. What am I missing? The data sheet talks about the option register but does not give the address.
Ringo _________________ Ringo Davis |
|
|
|