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

Please Check My code (B0 Interrupt)

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



Joined: 23 Sep 2003
Posts: 12
Location: South KOREA

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

Please Check My code (B0 Interrupt)
PostPosted: Tue Feb 22, 2005 7:58 am     Reply with quote

Dear Master.

Code:


#include<16F874.h>
#device pic16f874 *=8 adc=10
#use delay(clock=4000000)

int x, count, state;

void reset()
{
   state == 0;
   output_high(pin_C5);
   output_c(0x00);
   output_d(0x00);
   printf("%c%c%c",0xa1,0,1);
   printf("%c Stop               %c",0xa2, 0);
}
#INT_EXT
ext_isr()
{
   reset();
}

void cylinder1_Up()
{
   if(state == 0) break;
   output_low(pin_D0);
   while(!input(pin_A0)) {}
}

void cylinder1_Dn()
{
   if(state == 0) break;
   output_high(pin_D0);
   while(input(pin_A0)) {}
}

void cylinder2_Up()
{
   if(state == 0) break;
   output_low(pin_D1);
   while(input(pin_A1)) {}
}

void cylinder2_Dn()
{
   if(state == 0) break;
   output_high(pin_D1);
   while(!input(pin_A1)) {}
}
void vacum1_ON()
{
   if(state == 0) break;
   output_high(pin_D2);
}
void vacum1_OFF()
{
   if(state == 0) break;
   output_low(pin_D2);
   output_high(pin_D3);
   delay_ms(200);
   output_low(pin_D3);
}

void servo_init()
{
   while(!input(pin_e1)) {}
   output_low(pin_D4);
   output_low(pin_D5);
   output_low(pin_D6);
   output_low(pin_D7);

   delay_ms(100);
   output_high(pin_C4);
   delay_ms(100);
   output_low(pin_C4);
   delay_ms(200);
   while(!input(pin_e2)){}
}

void Move_Home()
{
   if(state == 0) break;
   output_high(pin_D4);
   output_low(pin_D5);
   output_low(pin_D6);
   output_low(pin_D7);

   delay_ms(100);
   output_high(pin_C4);
   delay_ms(100);
   output_low(pin_C4);
   delay_ms(200);
   while(!input(pin_e2)) {} }

void move_cpruf() 
{
   if(state == 0) break;
   output_low(pin_D4);
   output_high(pin_D5);
   output_low(pin_D6);
   output_low(pin_D7);

   delay_ms(100);
   output_high(pin_C4);
   delay_ms(100);
   output_low(pin_C4);
   delay_ms(200);
   while(!input(pin_e2)) {} 
}

void move_tray_x() 
{
   if(state == 0) break;
   x = count%10;

   if(x == 1)
   {
      output_high(pin_D4);
      output_high(pin_D5);
      output_low(pin_D6);
      output_low(pin_D7);
   }
   else if(x == 2)
   {
      output_low(pin_D4);
      output_low(pin_D5);
      output_high(pin_D6);
      output_low(pin_D7);
   }
   else if(x == 3)
   {
      output_high(pin_D4);
      output_low(pin_D5);
      output_high(pin_D6);
      output_low(pin_D7);
   }
   else if(x == 4)
   {
      output_low(pin_D4);
      output_high(pin_D5);
      output_high(pin_D6);
      output_low(pin_D7);
   }
   else if(x == 5)
   {
      output_high(pin_D4);
      output_high(pin_D5);
      output_high(pin_D6);
      output_low(pin_D7);
   }
   else if(x == 6)
   {
      output_low(pin_D4);
      output_low(pin_D5);
      output_low(pin_D6);
      output_high(pin_D7);
   }
   else if(x == 7)
   {
      output_high(pin_D4);
      output_low(pin_D5);
      output_low(pin_D6);
      output_high(pin_D7);
   }
   else if(x == 8)
   {
      output_low(pin_D4);
      output_high(pin_D5);
      output_low(pin_D6);
      output_high(pin_D7);
   }
   else if(x == 9)
   {
      output_high(pin_D4);
      output_high(pin_D5);
      output_low(pin_D6);
      output_high(pin_D7);
   }
   else if(x == 0)
   {
      output_low(pin_D4);
      output_low(pin_D5);
      output_high(pin_D6);
      output_high(pin_D7);
   }

   delay_ms(100);
   output_high(pin_C4);
   delay_ms(100);
   output_low(pin_C4);
   delay_ms(200);
   while(!input(pin_e2)) {}   
}

void cpruf()
{
   if(state == 0) break;
   output_high(pin_c2);
   delay_ms(100);
   output_low(pin_c2);
   while(!input(pin_a5)) {}   
}

void home()
{
   if(state == 0) break;
   output_high(pin_c1);
   delay_ms(100);
   output_low(pin_c1);
   while(!input(pin_a5)) {}   
}

void move_tray_y()
{
   if(state == 0) break;
   if (count == 10 || count == 20 || count == 30 || count == 40 || count == 50 || count == 60 || count == 70 || count == 80 || count == 90)
   {
      output_high(pin_C3); //Move Tray
      delay_ms(100);
      output_low(pin_C3);
   }
   else if (count == 100)  //Go Home~!
   {
      output_high(pin_C1);
      delay_ms(100);
      output_low(pin_C1);
      count = 1;
   }
}

void start()
{
    move_home();
   cylinder1_dn();
   cylinder2_Dn();   
   vacum1_ON();     
   delay_ms(200);
   cylinder2_Up(); 
   delay_ms(200);
   move_cpruf();   
   delay_ms(100);
   cylinder2_Dn();   
   delay_ms(200);
   cpruf();         
   cylinder2_Up();   
   delay_ms(200);
   move_tray_x();   
   delay_ms(100);
   cylinder2_Dn();   
   vacum1_OFF();   
   cylinder2_Up();
   cylinder1_up();
   move_home();
   if(state == 0) break;
   else count = count + 1;
   move_tray_y();
}


void main()
{
   setup_adc_ports(NO_ANALOGS);
   ext_int_edge(0,L_TO_H);
   enable_interrupts(int_ext);
   enable_interrupts(global);
                        // 7 6 5 4 3 2 1 0
   set_tris_a(0x3F);    //     I I I I I I
   set_tris_b(0xFF);    // I I I I I I I I
   set_tris_c(0x00);    // O O O O O O O O
   set_tris_d(0x00);    // O O O O O O O O
   set_tris_e(0xFF);    //           I I I

   output_c(0x00);
   output_d(0x00);
   output_e(0x00);

   x = 0;
   count = 1;
   state = 0;

   output_high(pin_c0);

   while(1)
   {
a:
      if(state == 0)
      {
          if(input(pin_B1))   //Start?
         {
            servo_init();
            home();
            state = 1;
         }
      }
      else if(state == 1)
       {
         if(input(pin_B1)) start();
         else if(input(pin_B2)) cylinder1();
         else if(input(pin_B3)) cylinder2();
         else if(input(pin_B4)) Vacum1();
         else if(input(pin_B5)) Move_Home();
         else if(input(pin_B6)) Move_cpruf();
         else if(input(pin_B7)) Move_Tray_x();
      }
      delay_ms(500);
   }
}


When turn on power than state == 0
than if B1 on Init.... and one more if B1 on start...
when running B0 On... It's like E-Stop...
than push B1... than Start... But... It's can't running...

Please check code...
_________________
Hello~?

This is South KOREA
My name is Sanghyouk Kim But Call me Nick
Sorry I'm poor English
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2005 11:10 am     Reply with quote

I did not check your whole program, but I did see one problem.
You have many functions like this:
Code:
void cylinder2_Dn()
{
   if(state == 0) break;
   output_high(pin_D1);
   while(!input(pin_A1)) {}
}


The problem is in this statement:
if(state == 0) break;

This is not the correct way to use the "break" statement.
See the following link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/state_2.asp

I did not study your program in detail, but I think you probably
want to return from the function if the state is 0. So use the
"return" statement as shown below:

void cylinder2_Dn()
{
if(state == 0) return;
output_high(pin_D1);
while(!input(pin_A1)) {}
}

Your main problem is that you need to study the C language some more.
Before you use a statement, you need to look at example programs
and also to study the C manual.
NewSpace



Joined: 23 Sep 2003
Posts: 12
Location: South KOREA

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

I think...
PostPosted: Tue Feb 22, 2005 12:13 pm     Reply with quote

Sorry...
Ithink...
When push E-Stop button... than B0 on...
So...
Code:
void reset()
{
   state == 0;
   output_high(pin_C5);
   output_c(0x00);
   output_d(0x00);
}
#INT_EXT
ext_isr()
{
   reset();
}


and...
Push Start Button...
INIT..... ruturn...
_________________
Hello~?

This is South KOREA
My name is Sanghyouk Kim But Call me Nick
Sorry I'm poor English
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 22, 2005 12:28 pm     Reply with quote

I cannot write your program for you. You must do it.

But you must study the C language more.

This statement does not set the variable "state" equal to 0.
state == 0;

You need to write it like this:
state = 0;

Please study the C language before you write more code.
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