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

converting from 12f683 to 16f84 or similar.

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



Joined: 04 Jun 2007
Posts: 13

View user's profile Send private message

converting from 12f683 to 16f84 or similar.
PostPosted: Mon Apr 21, 2008 2:16 pm     Reply with quote

I wrote some code a while back for a 12f683 with alot of help from others. I am astill a total newb. I got it working like i want but now I find myself in need of more inputs and outputs and was considering converting to a 16f84 or similar. How hard would it be to convert my existing code to work on 16f84? If needed I can post the code i have here.

Thanks,
RB8720
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 21, 2008 2:26 pm     Reply with quote

Quote:
How hard would it be to convert my existing code to work on 16f84 ?

That's an older PIC. It doesn't have an internal oscillator, or an A/D
or a comparator or anything, really. A better chip would be the 16F88.
Or possibly the 16F628 or 16F628A (no A/D in those two PICs).

Quote:
How hard would it be to convert my existing code ?

If you use the CCS functions entirely, then it should be fairly easy to
port the code from one PIC to another. Change the #include statement
to use the .H file for the new PIC. If you're using peripheral modules,
make sure you specify the correct pins, if required, by #use statements.
rb8720



Joined: 04 Jun 2007
Posts: 13

View user's profile Send private message

PostPosted: Mon Apr 21, 2008 4:57 pm     Reply with quote

thanks, i think i'll go with the 16f88. here is my code. could you tell me what i would need to change?

Code:

//PREPROCESSOR section/////////////////////////////////////////////////////////////////////////////////////////////

#include "12F683.H"      //PIC chip file (don't also specify in cmd prompt)

#include "delay_ms.h"      //Delay function used below
            //#include files must be in same folder as cc5x.exe if no path

#define pin7 1<<0               //Pin 7, bit 0
#define pin6 1<<1               //Pin 6, bit 1

#pragma config = 0b.0.1100.0100   //Brown-out Detect disabled (0)
            //Code Protect off (1)
            //MCLR set to 'Internal' (1) (LEDs don't flash with other setting)
            //Powerup timer enabled (0)
            //Watchdog timer disabled (0)
            //Oscillator set to INTRCIO (100)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void init_ports(void) {

   TRISIO = 0b11111111; // SET AS INPUT
   CMCON0 = 0x07;       // Set GP<2:0> to digital I/O
   ANSEL = 0;
   WPU = 0b00000011;
 

}

//////////////////////////////////////////////////////////////////////
int get_key (int button) {

   // Is GP5 low - no so exit
   if (GPIO & button) return 0; // no key yet

   delay_ms(1); // wait for key to settle

   // Is GP5 high ? yes so exit = false key.
   if ((GPIO & button) > 0) return 0; // was a false key so restart

   return 1; // key ok so return valid
}

////
//////////////////////////////////////////////////////////////////////
// Start here
void main () {
   unsigned int i, c;
   char next;
   uns16 ms;
   char button_func;

   init_ports();
   //GPIO = 0xFF;

   button_func = 0; // 0 = double shot, 1 = rapid fire - double shot is default
   while (1) {

      // Key hit yet ?
      while ((GPIO & pin6) && (GPIO & pin7)) { ; } // wait for input going low.

      // Is the key hit (and is it valid) ?
      if (get_key (pin7)) { // Double shot or rapid fire
         while (!(GPIO & (pin7))) { // loop until input goes high.
            if (button_func == 0) { // double shot
               
                  TRISIO.2 = 0;//SET TO OUTPUT
                  GPIO.2 = 0; // Pin 5 output ( trigger on)
                  delay_ms(67);
                  TRISIO.2 = 1;//SET trigger TO input
                  GPIO.2 = 1;  // trigger off
                  delay_ms(100);

               TRISIO.2 = 0;//SET trigger TO OUTPUT
               TRISIO.4 = 0; // SET X BUTTON TO OUTPUT
               GPIO.2 = 0; // 2nd pin5 output (trigger on)
               delay_ms(43);
               GPIO = 0b11101011; // pin 5 and pin 3 on (X Button)
               delay_ms(154);
               TRISIO.2 = 1;//SET trigger TO INTPUT
               TRISIO.4 = 1; // SET X BUTTON TO INPUT
               GPIO = 0b11111111; // pin 5 and 3 off
               
                  TRISIO.5 = 0; // SET Y TO OUTPUT
                  GPIO.5 = 0 ;//  Y BUTTON PIN2 ON
                   delay_ms(370);
                  TRISIO.5 = 1;// Y BACK TO INPUT
                  GPIO.5 = 1; // Y  off
                  delay_ms(450);

               TRISIO.5 = 0; // SET Y TO OUTPUT
               GPIO.5 = 0; // pin2 on
               delay_ms(37);
               TRISIO.5 = 1;// Y BACK TO INPUT
               GPIO.5 = 1; // Y OFF
               delay_ms(190); 
               
               
             
               
            } else { // rapid fire

               TRISIO.2 = 0; //TRIGGER TO OUTPUT
               GPIO.2 = 0;// TRIGGER ON
               delay_ms (250);
               TRISIO.2 = 1;// TRIGGER BACK TO INPUT
               GPIO.2 = 1;// TRIGGER OFF
               delay_ms (250)
             
            }
         }
      } else if (get_key (pin6)) { // Rapid reload
         OPTION = 0b.0010; //0 Assigns the prescaler to TMR0, 8 clock pulses per PIC
         ms = 0;         
         TMR0 = 2;
         do {
             next += 125;
             while (TMR0 != next);   // wait 1ms
             ms++;                 // increment timing counter
         } while (!(GPIO & pin6)); // loop until input goes high.
         if (ms < 2200) {          // button held less than 3000ms - rapid reload
             TRISIO.4 = 0; // X SET TO OUTPUT
             GPIO.4 = 0; // X ON
             delay_ms (40);
             TRISIO.4 = 1; //X TO INPUT
             GPIO.4 = 1;// X OFF
             delay_ms (1050);

             TRISIO.5 = 0; // Y TO OUTPUT
             GPIO.5 = 0; // Y ON
             delay_ms (400);
             TRISIO.5 = 1; // Y BACK TO INPUT
             GPIO.5 = 1; // Y OFF
             delay_ms (600);

             TRISIO.5 = 0; // Y TO OUTPUT
             GPIO.5 = 0; // Y ON
             delay_ms (400);
             TRISIO.5 = 1; // Y BACK TO INPUT
             GPIO.5 = 1; // Y OFF

          } else {
             if (button_func == 0) {
                button_func = 1;
             } else {
                button_func = 0;
             }
          }
      }
   } // infinite while
}


thanks rb
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 21, 2008 5:32 pm     Reply with quote

Your question is really that you want someone to convert your program
from the CC5X compiler to CCS.
Guest








PostPosted: Mon Apr 21, 2008 6:09 pm     Reply with quote

crap, i was thinking there were pretty much the same. Sorry. Im still very
new to this. So i guess the answer is yes to convert to ccs and convert to
16f88. any help would be greatly appreciated.

Thanks,
RB8720
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