View previous topic :: View next topic |
Author |
Message |
rb8720
Joined: 04 Jun 2007 Posts: 13
|
Need help with code. |
Posted: Tue Jul 10, 2007 2:22 pm |
|
|
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
|
|
|
Guest
|
|
Posted: Tue Jul 10, 2007 6:44 pm |
|
|
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
|
|
Posted: Tue Jul 10, 2007 7:12 pm |
|
|
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
|
|
Posted: Tue Jul 10, 2007 7:37 pm |
|
|
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
|
|
Posted: Tue Jul 10, 2007 7:39 pm |
|
|
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
|
|
Posted: Tue Jul 10, 2007 8:21 pm |
|
|
SOrry, I didn't know there was a big difference. |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
|
|