CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC10F220 won't execute code...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
marcusayoung



Joined: 03 Jun 2009
Posts: 28

View user's profile Send private message

PIC10F220 won't execute code...
PostPosted: Wed Jun 03, 2009 3:07 pm     Reply with quote

I'm trying to execute the "Hello World" of PICs by driving a GPIO high. I'm using a PIC10F220, MPLAB v8.30 with CCS compiler, PICKIT2 Programmer v2.61, PICKIT2, and demo board # AC163020.

My code is as follows (this is from a Gooligum tutorial: http://www.gooligum.com.au/tutorials/baseline/PIC_Base_C_1.pdf ):
Code:

#include <10F220.h>

#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3

#fuses NOMCLR,NOPROTECT,NOWDT,NOMCPU,IOSC4

void main()
{
    output_high(GP1);

    while (TRUE) {
        ;
   }
}

This code compiles and generates a .COF with other files including a .HEX. When I try to program the device from MPLAB, I don't get any warnings, but the code won't execute (GP1 won't go high). I take it out of reset and it still doesn't do anything...

I then used the PICKIT2 Programmer to successfully erase, import and write the hex file to the device. The result is no pins are high (except VDD of course), including GP1, when I assert any combination of VDD and MCLR. The board also does nothing at GP1 when powered stand alone by 5V.

I've tried moving "output_high(GPx);" around the code, such as in the while loop, and I've tried GP0, 2, and 3 as well. The result is the same every time, the pin I specify stays at 0V.

I would like to know what else I can try, or if I'm missing some configuration. I'd also like to stay away from assembly, which is why I'm working with C.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 4:02 pm     Reply with quote

I can't find a schematic for the AC163020. If you know where one is,
post a link to it.
marcusayoung



Joined: 03 Jun 2009
Posts: 28

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 4:25 pm     Reply with quote

I looked too, but i couldn't find one. This document shows all the header/jack pinouts though

http://ww1.microchip.com/downloads/en/devicedoc/bom.pdf

Its very similar to Microchip's Low Pin Count Demo board:

http://ww1.microchip.com/downloads/en/DeviceDoc/Low%20Pin%20Count%20User%20Guide%2051556a.pdf

I've been using it to debug along with the PICKIT2. The only difference i can find with respect to the 6 pin header called "BFMP" is it doesn't have an "AUX" like on the low pin count demo board. Note that my PIC10F220 is a DIP8.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 4:47 pm     Reply with quote

Your Bom link has the schematic. I found a separate document for it:
http://ww1.microchip.com/downloads/en/DeviceDoc/univ_adapter_0x-01793R2.pdf

Are you plugging the AC163020 into some other board ? If so, post a
link to the schematic for the other board. I want to see if there are
any spare pins (truly unconnected) on the 10F220.
marcusayoung



Joined: 03 Jun 2009
Posts: 28

View user's profile Send private message

PostPosted: Thu Jun 04, 2009 3:30 pm     Reply with quote

No, no other board besides the PICKIT2 at the 6-pin header. I've thoroughly ohmed out the connections from header to DIP socket, and everything checks out fine. I talked with Microchip and they seem to think its a bad PICKIT2.
marcusayoung



Joined: 03 Jun 2009
Posts: 28

View user's profile Send private message

PostPosted: Thu Jun 04, 2009 6:44 pm     Reply with quote

Actually, as I think of it more, and look at the datasheet for the 10F220, I wonder what "output_high" actually does. Your supposed to tri-state each pin to see an output, such as driving it high like I want to do. I saw the list of functions on the CCS site, but is there a list with function descriptions?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 04, 2009 7:35 pm     Reply with quote

It sets the TRIS for the specified pin to be an output and it sets the pin to
the specified level (high or low). This is the case for "standard i/o"
mode, which is the default mode of the compiler.

See the manual or the Help file:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
marcusayoung



Joined: 03 Jun 2009
Posts: 28

View user's profile Send private message

PostPosted: Fri Jun 05, 2009 10:49 am     Reply with quote

Thanks so much, this is exactly what i needed!

I got the two ADC pins (GPIO0 and 1) working great. there was an extra initialization needed, which was "SETUP_ADC_PORTS(0)," to make sure they were set as digital i/o.

Now i'm stuck initializing GPIO2, which is also TIMER0. i'd like to be able to drive this pin high like the others as a basic exercise.

I understand that standard_io is the default, but i think this pin requires a little more set up to use it as a GPIO since it defaults as a timer. I don't think the compiler understand this. I'm looking specifically at Table 5-2 on p.21 in the PIC10F220 datasheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/41270E.pdf

would i need to disable the timer and FOSC4 first or is some application of "set_tris_x()" sufficient?

also, what specifically does the "x" describe in "set_tris_x()?" the manual says x can be a,b,c,d,e,f,g,h,j, or k, but its not clear if these letters represent a set of pins like a = a0, a1, a2, a3 for GP0-GP3 in my case, etc.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 05, 2009 12:49 pm     Reply with quote

Quote:
Now i'm stuck initializing GPIO2.

Look on page 23 of the 10F220 data sheet. It explains how to make
each pin into a digital i/o pin.
http://ww1.microchip.com/downloads/en/DeviceDoc/41270E.pdf
For GP2 to be digital i/o, the FOSC4 and T0CS bits must be = 0.

The FOSC4 bit is in OSCCAL register, and it defaults to 0.

The T0CS bit is in the OPTION register and it defaults to 1.
So it must be cleared. The OPTION register can't be written to
directly. It can only be set by executing the OPTION instruction.
CCS provides a macro to do this. Put this code above main()
and call set_options() at the start of your program, with the
appropriate value to set the OPTION bits. See page 19 of the
10F220 data sheet.
Code:
#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}


Quote:
What specifically does the "x" describe in "set_tris_x() ?"
The set_tris_x() functions operate on the entire port (i.e., all bits in the
port). The parameter is a bitmask. Bits set to 0 will make those pins
into outputs. Bits set to 1 will make those pins into inputs.

You can set an individual pin to be an input with the output_float()
function. Use the pin constants from the 10F220.h file.

In later versions of the compiler, CCS added the output_drive() function
which is similar to output_float(), except it allows you to set the TRIS on
individual pins so they become output pins.
qbone



Joined: 04 Sep 2012
Posts: 6
Location: Danmark

View user's profile Send private message MSN Messenger

PostPosted: Tue Sep 04, 2012 9:11 am     Reply with quote

Hi there, sorry to stir up this old thread, but I figured if I started one of my own with same problem I would get my head chewed off.

I have the exact same problem as the OP, however I cannot get ANY pins to go high.

I am programming in MPLAB v8.85 and compiling the code using CCS C Compiler v4.093
My programmer is a PIC-MCP-USB (PICSTART+).

I believe I have tried all stated in this thread, but I can't get a single pin to go high.
This is my code:
Code:

#include <10F220.h>
#fuses NOMCLR,NOPROTECT,NOWDT,NOMCPU,IOSC4

#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}
void init() {
   set_options(0xDF); // Setting T0CKI to '0' - Default OPTION is 0xFF
   setup_timer_0(T0_INTERNAL);
   setup_adc(ADC_OFF);
   SETUP_ADC_PORTS(0);
}

void main() {
   output_high(GP0);
   output_high(GP1);
   output_high(GP2);
   while(TRUE) {
      ;
   }
}


This is my setup:
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 9:45 am     Reply with quote

In MPLAB...there is a 'build configuration' option..which is defaulted to 'debug'. Be sure to change to 'release' and then rebuild(F10). This will create the proper code to download to the PIC.

hth
jay
qbone



Joined: 04 Sep 2012
Posts: 6
Location: Danmark

View user's profile Send private message MSN Messenger

PostPosted: Tue Sep 04, 2012 12:33 pm     Reply with quote

temtronic wrote:
In MPLAB...there is a 'build configuration' option..which is defaulted to 'debug'. Be sure to change to 'release' and then rebuild(F10). This will create the proper code to download to the PIC.

hth
jay

Already did that. In fact, thats what I always do, I never use the debug Smile
And I know the programmer is working, as I have been using it on PIC16F886.

I am programming the PIC through ICSP
https://www.olimex.com/dev/images/PIC/PIC-ICSP-2.jpg
Connected
ICSP - PIC10F220
Pin1(MCLR) - Pin8(MCLR)
Pin2(Vdd) - Pin2(Vdd)
Pin3(GND) - Pin7(GND)
Pin4(PGD) - Pin5(ICSPDAT)
Pin5(PGC) - Pin4(ICSPCLK)
Pin6(PGM) - Pin7(GND)

Now the last one I am not a hundred percent sure of, but I read somewhere that, thats how I should do. Feel free to correct me Smile
Also, its worth saying I have no resistors connected except for the 10k from MCLR to Vdd.
And I have diodes from the programmers Vdd to the PIC and from my PSU to the PIC, so the programmer and PSU doesnt interfere with eachother (much ;))
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 1:14 pm     Reply with quote

1. You have an init() routine but you're not calling it.

2. The connection below is not needed or required and should be removed:
Quote:

Pin6(PGM) - Pin7(GND)


3. It's possible that your programmer erased the OSCCAL calibration
constant at the end of Flash Memory in the 10F220. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=40024
qbone



Joined: 04 Sep 2012
Posts: 6
Location: Danmark

View user's profile Send private message MSN Messenger

PostPosted: Tue Sep 04, 2012 1:59 pm     Reply with quote

Oh, I was under the impression it would just read from top and down.
So the only thing that its certain to run is main() ?

I will add the init() call, and remove the PGM connection when I get back to my work station tomorrow.
Actually the issue with me not calling the init() explains a bunch of problems I have had with programming my PIC16F886 haha (DOH!)

Also this OSCCAL problem mentioned in the thread looks pretty disturbing. Good thing there are sharp minds like you guys around :D
So if I understand you correctly, the addition of
Code:
#rom 0xFF = {0xC00}  // Put MOVLW 0x00 at end of ROM

will fix the OSCCAL issue?
Or should I use the following instead?
Code:
#byte osccal = 0x05
osccal = osccal & 0xfe;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 2:19 pm     Reply with quote

If the last ROM location was erased, then adding the #rom statement
will make the programmer re-program it with the new specified value.
This at least approximates the original state of the PIC, as shipped
to you from the factory.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group