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

I need help for 12F675 code

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







I need help for 12F675 code
PostPosted: Fri Nov 13, 2009 10:51 pm     Reply with quote

I am starter for PIC programing. I use CCS-C and MPLAB 8.40. Also I use ICD 2 for programmer and debugger. My program has two external inputs, and two outputs. When (0,0) is input signal, the chip has to be in sleep mode, and when other signal is coming in, the predefined sequence is out as a output signal. I use the 20 MHz external oscillator as a clock input for GP5.

Since I am really newbie to PIC, I just use CCS-C project wizard and basic functions in help file. The following code is not working at all... But I don't know the reason. When I tried to compile the c code by using CCS-C, there is no error and warning, but the code is just not working. Please help me and let me know the wrong part and the possible solution.

*The code is little long, but the functions are really simple... I don't know why it is not working at all. Plz teach me in anyway.
Code:

#include <12F675.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES EC_IO                    //External clock
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BANDGAP_HIGH         
#use delay(clock=20000000)
#define GP0   PIN_A0
#define GP1   PIN_A1
#define GP2   PIN_A2
#define GP3   PIN_A3
#define GP4   PIN_A4
#define GP5   PIN_A5

// global flag to send processor into sleep mode
short sleep_mode;

// external interrupt to control sleep_mode
#int_EXT
void  EXT_isr() {
static short rest_signal=FALSE;

   if(input(GP3))         // check weather signal is 01 or 00
      rest_signal=TRUE;
   if(!rest_signal)        // if signal is 00(rest)
   {
      rest_signal=TRUE;    // the 00 signal in
      sleep_mode=TRUE;        // activate sleep
      ext_int_edge(L_TO_H);   // change interrupt to wakeup
   }
   else                       // if signal is 01(right_turn)
   {
      rest_signal=FALSE;   // reset the rest_mode
      sleep_mode=FALSE;       // reset sleep flag
      ext_int_edge(H_TO_L);   // reset interrupt to wait sleep
   }
}

// sequence for forward motion
void sequence_forward (void)
{
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
 
   delay_ms(100);  // preventing overheatting
   
   delay_ms(2000); // 0
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   delay_ms(2000); // 0
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
 
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
 
   delay_ms(100);  // preventing overheatting
}

// sequence for right turn
void sequence_right (void)
{
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   delay_ms(2000); // 0
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   delay_ms(2000); // 0
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
}

// sequence for left turn
void sequence_left (void)
{
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   delay_ms(2000); // 0
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP0);
   delay_ms(2000);
   output_low(GP0); // -1
   
   delay_ms(100);  // preventing overheatting
   
   delay_ms(2000); // 0
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
   
   output_high(GP4);
   delay_ms(2000);
   output_low(GP4); // 1
   
   delay_ms(100);  // preventing overheatting
}

// main program for sequence control and sleep management
void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);
   
   sleep_mode=FALSE; // initiate sleep flag
   output_low(GP0);
   output_low(GP4); // set initial output ground
   ext_int_edge(H_to_L); // init interrupt triggering for 00 signal
   enable_interrupts(int_EXT);
   enable_interrupts(GLOBAL);
   
   delay_ms(1000); // tunning delay
   
   while(TRUE){
   if(sleep_mode)          // if sleep flag set
         sleep();          // make processor sleep
         
   if(input(GP2) && input(GP3)) // when 11 signal, forward motion
      sequence_forward ();
   else if(input(GP2) && !input(GP3)) // when 10 signal, left turnning
      sequence_left ();
   else if(!input(GP2) && input(GP3)) // when 01 signal, right turnning
      sequence_right ();
     
   delay_ms(10);
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 15, 2009 1:21 am     Reply with quote

My advice is, for debugging purposes, get rid of the code in those huge
routines. Comment it out. Replace it with some simple code that just
turns on an LED for one second. This can be done in 3 lines of code.

Also, consider reducing your control inputs to just one pin, for this test.

Reduce the complexity until you can get something that works. Then
add the complexity back in, a little bit at a time. Test it at each step
to prove that it still works.
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sun Nov 15, 2009 3:59 am     Reply with quote

For start try to enable:

Code:
#fuses PUT


Power Up Timer prepares the PIC to start correctly. And as PCM programmer said, try first just to "blink" leds and then step up with complexity.
You are using sleep mode try first to determine if your PIC goes and comes out of sleep mode as it should. Wink
Ttelmah
Guest







PostPosted: Sun Nov 15, 2009 4:03 am     Reply with quote

One further 'obvious comment', is that the INT_EXT code tests GP3. INT_EXT on a 12F675, is on GP2.....

Best Wishes
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