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 support@ccsinfo.com

Trouble getting PIC10f320 to run

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ralpok



Joined: 21 Dec 2005
Posts: 25

View user's profile Send private message

Trouble getting PIC10f320 to run
PostPosted: Sat Feb 09, 2013 12:57 pm     Reply with quote

I have a project I have started with the PIC10f320 micro controller. I want to just get a simple program running toggling PIN4 (GP2) on the device. As far as I can tell I am unable to even get this running and since this chip/compiler doesn't support debugging I am a bit lost. The program I have tried to run is:

I am running Win 7:
CCS Studio: PCWHD 4.134

Code:

#case
#include <10f320.h>
#device ADC=10
#fuses NOWDT
#use delay (internal=8000000)

void main()
{
   int8 velocity[10];
   int16 avgVelocity = 0;
   int ndx = 0;
 
   delay_ms(2000);

   set_tris_a(0x00);
   output_high(PIN_A2);

   while (1)
   {
      output_toggle(PIN_A2);
      delay_ms(10);
   }
}


Any thoughts people have on why I can't get the pin to toggle would be appreciated. I even disconnected it from anything else on my circuit board to make sure something wasn't holding it low.
temtronic



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

View user's profile Send private message

PostPosted: Sat Feb 09, 2013 1:42 pm     Reply with quote

I don't use that PIC but ...

1) check to see what other peripherals can also use that pin. Typically the
ADC will default to being 'attached'. Also comparitors, UART, MSSP,etc.

2) What pullup resistor are you using? Some PIC pins are open drain and need a load..

3) Is that pin configurable as an OUTPUT ? While most are, some aren't all depends on the PIC

Check the datasheet it'll soon tell you the defaults for the I/O pins as well as functionality(I/O, I only,O only)

Also...be sure to have 'release' selected as the build configuration within MPLAB.


hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Sat Feb 09, 2013 3:52 pm     Reply with quote

On the 10F320, A0 to 2, wake up as analog. This overrides port I/O. You need to turn this off.

From the data sheet:
"Note: The ANSELA bits default to the Analog
mode after Reset. To use any pins as
digital general purpose or peripheral
inputs, the corresponding ANSEL bits
must be initialized to ‘0’ by user software."

Best Wishes
ralpok



Joined: 21 Dec 2005
Posts: 25

View user's profile Send private message

PostPosted: Tue Feb 19, 2013 10:47 am     Reply with quote

Thank you guys for all your help. Your advice and input got me heading in the correct direction and I was able to pretty quickly get this up and running. In the end I had to manually set the PORTA, LATA, ANSELA, and TRISA registers in order to get it working. I followed the assembly that was in the datasheet and this seems to work. I can probably do this using the CCS Libraries in some way but I am not sure how. In case anybody else is interested I will post my working code.

Code:

#case
#include <10f320.h>
#device ADC=10
#fuses NOWDT, INTRC
#use delay (internal=8000000)
#use standard_io(A)

#byte PORTA = 0x05
#byte LATA = 0x07
#byte ANSELA = 0x08
#byte TRISA = 0x06

void main()
{
   int8 velocity[10];
   int16 avgVelocity = 0;
   int ndx = 0;
 
   delay_ms(2000);

   PORTA = 0x00;
   LATA = 0x00;
   ANSELA = 0x00;
   TRISA = 0x00;

   output_high(PIN_A2);

   while (1)
   {
      output_low(PIN_A2);
      delay_ms(10);
      output_high(PIN_A2);
      delay_ms(10);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Tue Feb 19, 2013 1:16 pm     Reply with quote

1) TRIS is set for you.
2) PORT/LAT registers are set for you.
3) setup_adc_ports.....

Best Wishes
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Wed Mar 06, 2013 10:37 pm     Reply with quote

I'd suspect that the reason your later code works and the first code didn't is the following.
original code:
Quote:
#fuses NOWDT


updated code:

Code:
#fuses NOWDT, INTRC


Without "INTRC" specified it defaulted to looking for an external clock. If you didn't have that clock, no instructions were executed at run time. And no pin was toggled.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 06, 2013 11:09 pm     Reply with quote

Look at the Fuses in the .LST file for his first program:

Quote:
Configuration Fuses:
Word 1: 3EC6 INTRC BROWNOUT NOWDT PUT MCLR NOPROTECT NOLVP LPBOR BORV19 NOWRT NODEBUG


When the compiler sees the "internal" keyword in the #use delay()
statement, it enables the INTRC fuse:
Quote:
#case
#include <10f320.h>
#device ADC=10
#fuses NOWDT
#use delay (internal=8000000)


However, I personally prefer to specify it in the #fuses statement and
not in the #use delay().
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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