View previous topic :: View next topic |
Author |
Message |
rb8720
Joined: 04 Jun 2007 Posts: 13
|
Help Migrating from 12F683 to 16F684 |
Posted: Thu Jul 19, 2007 1:57 pm |
|
|
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 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 19, 2007 3:24 pm |
|
|
This is CC5X code. It won't compile with CCS. |
|
|
Guest
|
|
Posted: Fri Jul 20, 2007 6:29 am |
|
|
So how do I convert it to compile wth CCS for 16f684?
RB |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 20, 2007 1:06 pm |
|
|
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. |
|
|
|