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

Help Migrating from 12F683 to 16F684

 
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

Help Migrating from 12F683 to 16F684
PostPosted: Thu Jul 19, 2007 1:57 pm     Reply with quote

I am a total newb to this so please forgive me if mine is a stupid question. But could someone look at my code and tell me what to change to make it compatible with a 16f684. Also would the command PORTC.1 be for pin9 if not how would I activate the individual pins. Currently i am using a 12f683 which only has one port so I was using GPIO.5 = 1 to take it high. Here is a condensed version of my code. Any suggestions would be appreciated.

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

#include "12F683.H" //PIC chip file (don't also specify in cmd prompt)
#include "delay_ms.h" //Delay function used below

#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 = 0b11001111; // SET AS INPUT
CMCON0 = 0x07; // Set GP<2:0> to digital I/O
ANSEL = 0;
WPU = 0b00000011;
}

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

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

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

// Is GP 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 PIN 5 AS OUTPUT
GPIO.2 = 0; // Pin 5 output ( trigger on)
delay_ms(65);

GPIO.2 = 1; // trigger off
delay_ms(100);

GPIO.2 = 0; // 2nd pin3 output (trigger on)
delay_ms(40);


} else { // rapid fire
TRISIO.2=0 // SET PIN 5 TO OUTPUT
GPIO.2 = 0;
delay_ms (50);
GPIO.2 = 1;
delay_ms (50);
TRISIO.2=1 // SET PIN5 BACK TO INPUT
}
}
} 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
GPIO.4 = 0;
delay_ms (40);
GPIO.4 = 1;

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

Thanks,
RB
Code:
Code:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 19, 2007 3:24 pm     Reply with quote

This is CC5X code. It won't compile with CCS.
Guest








PostPosted: Fri Jul 20, 2007 6:29 am     Reply with quote

So how do I convert it to compile wth CCS for 16f684?

RB
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 20, 2007 1:06 pm     Reply with quote

I tried to help you in this other thread, by giving you working code
that would toggle the state of an LED on or off, every time you press
a button. That code consisted of the wait_for_keypress() function
given in this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=19874&start=1
Then I gave you a test program to call that function in this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=31432&start=5

But you just declared that you have "always the same problem" and
gave up. You didn't even say what the problem is.

I tested the code given in the links above before I posted it, on a
PicDem2-Plus board and it sure does work. So I don't want to
convert CC5x code when I gave you fully working code in CCS.
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