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

Need help with code.

 
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

Need help with code.
PostPosted: Tue Jul 10, 2007 2:22 pm     Reply with quote

I tried to write some code to do this but I am a total noob and connot get it to save my life. If anyone is willing to wrtie some code to performe the following functions on a 12f683 I would be willing to pay.
Below is what I need.

How the chip is Wired.

Pin 1 to +5v Power
Pin 2 is to Y button connection ( take low to activate)
Pin 3 is to X button Connection ( take low to activate)
Pin 4 No used
Pin 5 is to R trigger ( take low to activate)

Pin 7 is to Right input button ( for activating doubleshot and Rapidfire)

** input button are connected to pin7 and ground**

Pin 8 To ground

Press pin & to activate Doubleshot.
------------------------------------------------------------------------
ok here is the double shot sequence and timings. Remember to activate a pin it mus tbe taken low because the pins are wired to the ground part of the optocoupler and the R trigger.

pin5 on
Delay (50 Miliseconds)

Pin5 off
delay (100 Miliseconds)

Pin5 on
Delay (50 Miliseconds)

Pin2 on " pin5 still remains on"
delay (150 miliseconds)

Pins 2 and 5 off and Pin 3 on
Delay (50 miliseconds)

Pin3 off
Delay (50 miliseconds)

Pin3 on
Delay (100 miliseconds)

Pin3 off
Delay ( 100 miliseconds)

Return to start.

-----------------------------------------------------

PLeae help, I give up
Thanks,
Rb8720
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2007 5:44 pm     Reply with quote

Here's a routine that waits for a button to be pressed. (Just one button).
http://www.ccsinfo.com/forum/viewtopic.php?t=19874&start=1

Here's a program that uses that function.
http://www.ccsinfo.com/forum/viewtopic.php?t=29366&start=7

Here's button code that will work with multiple buttons.
http://www.ccsinfo.com/forum/viewtopic.php?t=23837


I don't want to write your code for you. I'm just giving you some hints.
Guest








PostPosted: Tue Jul 10, 2007 6:44 pm     Reply with quote

Thanks, another questions. Do i hve to enable the internal pullupresistor for the input pins and if so what is the command?

Thanks,
RB8720
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2007 7:12 pm     Reply with quote

Yes, you need to enable the internal pull-ups, or if they're not available,
then you need to add an external pull-up on each button pin.

Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look in the chapter on "Built-in Functions". At the start of that chapter
there's a list of all the CCS functions. Look in the section on "Discrete i/o".
It will be obvious what function you need.
Guest








PostPosted: Tue Jul 10, 2007 7:37 pm     Reply with quote

I found this to use as a test and it worked on gp5 with an Ecternal pullup. but when I tried to change it to gp1 it would not work. To chang it I replace the 5's with 1's. Am i missing something?



//////////////////////////////////////////////////////////////////////
//
// File: 16F675_switch-debounce.c
//
// Author: J F Main.
//
// Description:
//
// Switch debounce - show debounced key on LED.
//
// Compiler : mikroC, mikroElektronika C compiler
// for Microchip PIC microcontrollers
// Version: 5.0.0.3
//
// Note Testing:
//
// Tested on 16F675
//
// Requirements:
//
// Target : 16F675
//
// Notes :
//
// Uses internal oscillator.
//
// Version:
// 1.00 15/Apr/06 - Initial release.
//
// Copyright : Copyright © John Main 2006
//
// Free for non commercial use as long as this entire copyright notice
// is included in source code and any other documentation.
//
//////////////////////////////////////////////////////////////////////

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

TRISIO = (1<<5); // set as output except bit 5 GP5=i/p



}

//////////////////////////////////////////////////////////////////////
int get_key(void) {

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

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

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

return 1; // key ok so return valid
}

////
//////////////////////////////////////////////////////////////////////
// Start here
void main() {
unsigned int i,c;

init_ports();

// Start up flash the LED 6 times
for(i=0;i<6;i++) {
GPIO = (1<<4);
delay_ms(100);
GPIO = 0;
delay_ms(100);
}

while (1) {

// Key hit yet ?
while(GPIO & (1<<5)) { ; } // wait for input going low.

// Is the key hit (and vis it valid) ?
if ( get_key() ) {
GPIO |= (1<<4); // Key valid so flash LED once
delay_ms(300);
GPIO &= ~(1<<4);
}
// Key released yet ?
while( !(GPIO & (1<<5)) ) { ; } // wait for input going high.

} // infinite while
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2007 7:39 pm     Reply with quote

Quote:
Compiler : mikroC, mikroElektronika C compiler

This is not a MikroC board. I don't want to do support for a 2nd compiler.
Here is the MikroC forum:
http://www.mikroe.com/forum/
Guest








PostPosted: Tue Jul 10, 2007 8:21 pm     Reply with quote

SOrry, I didn't know there was a big difference.
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Wed Jul 11, 2007 5:38 am     Reply with quote

Hello,
you can find a sample at http://www.ccsinfo.com/forum/viewtopic.php?t=31029 exactly there http://www.ccsinfo.com/forum/viewtopic.php?t=31029&start=7

you also need to add a loop for wait the button pushed like:
Code:


  while ( input(PIN_A7) ) ;
  ...
  the doubleshot and Rapidfire sequence
  ...
  //debounce after the sequence.
  while ( !input(PIN_A7) ) ;
  delay_ms(50);
 


dro.
_________________
in médio virtus
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