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

Advice on a simple program

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



Joined: 24 Sep 2007
Posts: 2

View user's profile Send private message

Advice on a simple program
PostPosted: Mon Dec 10, 2007 4:30 pm     Reply with quote

Hello all I am having trouble getting the simplest of programs to actually do something once it gets on the chip.

I am testing out a PIC16F628A and I can't seem to get any of the pins to "pulse", though everything seems to work fine in MPLAB SIM30 version 3.60.00.00. I am developing with MPLAB IDE 7.60.00.00, compiling with the CCS C compiler 4.0.38, and programming with Quasar electronics PIBmicro programmer version 201106. I have verified that I get a clock pulse on the board but do not see any of the pins on port b pulsing, can you provide any advise?
Code:

#include <16F628A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fixed_io(b_outputs=PIN_B0,PIN_B1,PIN_B2,PIN_B3,PIN_B4,PIN_B5,PIN_B6,PIN_B7)

void main()
{
   int8 toggle = 0xFF;
   set_tris_b(0x00);
   while (1) {
      toggle = ~toggle;
      output_b(toggle);
   }//while
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 10, 2007 5:34 pm     Reply with quote

You don't need to set fixed i/o mode or TRIS. Just let the compiler
handle it. If you use the CCS i/o functions, the compiler will put in
code to properly handle the TRIS. You don't even have to think about it.

Here's a simple test program that toggles Pin B0. I specified the NOMCLR
fuse, because it's possible that you forgot to put a pull-up resistor on
the MCLR pin. With the NOMCLR fuse, this won't matter. The PIC will
still run the program even without the MCLR pull-up.

If it doesn't work, I would suspect your programmer, or maybe you
don't have a crystal and its capacitors properly connected to the PIC.
Code:

#include <16F628A.h>
#fuses HS, NOWDT, PUT, NOLVP, NOMCLR
#use delay(clock=20000000)

//==========================
void main()
{

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Dec 11, 2007 10:20 am     Reply with quote

In case your crystal might not be functioning properly, you could try using the internal oscillator to see if it works.

Code:
#include <16F628A.h>
#FUSES NOWDT
#FUSES PUT
#FUSES NOMCLR
#FUSES NOLVP
#FUSES INTRC_IO
#use delay(clock=4000000)


void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_4MHZ);

   while(1)
   {
     output_b(0x00);
     delay_ms(500);
     output_b(0xFF);
     delay_ms(500);
   }
}


Ronald
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