Author Topic: Rapid fire Code in C  (Read 2934 times)

Offline Anonamous

  • The Unknown Identity
  • Granny Spanker
  • *
  • Posts: 472
  • Post quality +14/-1
  • Gender: Male
  • Electrical Engineering Student
Rapid fire Code in C
« on: September 05, 2010, 09:22:35 AM »
does anybody have an example of code written in C. I dont really know where to start with writing it in C and an example would really help.

Offline hyper999

  • Acidmods Alumni
  • Millennium Poster
  • *
  • Posts: 1158
  • Post quality +544/-3
  • Research and Development
Re: Rapid fire Code in C
« Reply #1 on: September 06, 2010, 03:43:54 AM »
well to start off your gonna want an interupt routine that occurs somthing like every 1ms then keep the output tristate or high or low depending on the controller type using a counter to count the number of interupts before you swap the output do this repeatadly

Offline Anonamous

  • The Unknown Identity
  • Granny Spanker
  • *
  • Posts: 472
  • Post quality +14/-1
  • Gender: Male
  • Electrical Engineering Student
Re: Rapid fire Code in C
« Reply #2 on: September 06, 2010, 08:54:40 AM »
ok... well, i think im gonna have my brother do it though since he understands a lot more C than i do. thx ill see what he thinks of that.

Offline d3v1ld0g

  • Guppy
  • *
  • Posts: 5
  • Post quality +0/-0
  • Acidmods User
Re: Rapid fire Code in C
« Reply #3 on: September 08, 2010, 08:54:05 PM »
The most basic way to do it would be to turn an IO port on/off after a certain amount of delay cycles. Here is a simple one for the PIC12F863 using HiTech C.

Code: [Select]

#include <htc.h>

__CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTCLK);


void init(){

// CHANGE ANALOG CHANNELS TO DIGITAL I/O
CMCON0 = 0x07; // SET COMPARATOR OFF, CIN and COUT PINS AS I/O
    ANSEL = 0x00; // SET ANALOG INPUTS OFF

TRISIO = 0x00; // SETUP I/O BITS
GPIO = 0x00; // SET I/O BITS LOW

}

void main(){

init();

while(1){

GPIO =0x01;

_delay(50000); // delay 50k cycles
                                      //  50k cycles  seems to work good when using the internal clock

GPIO = 0x00;

_delay(50000);

}

}


And just add a switch between GPIO0 and the Right Trigger.

Im a beginner at this stuff just like you, so if i get corrected, listen to them.

Offline hyper999

  • Acidmods Alumni
  • Millennium Poster
  • *
  • Posts: 1158
  • Post quality +544/-3
  • Research and Development
Re: Rapid fire Code in C
« Reply #4 on: September 11, 2010, 05:35:51 PM »
Yes that will work but for rapid fire you want to switch between tristate and the unpressed state of the trigger ( high or low depending on controller type ) so that when the trigger is pressed the pic then repeatedly forces it unpressed without you having to physically unpress it

Offline Anonamous

  • The Unknown Identity
  • Granny Spanker
  • *
  • Posts: 472
  • Post quality +14/-1
  • Gender: Male
  • Electrical Engineering Student
Re: Rapid fire Code in C
« Reply #5 on: September 12, 2010, 08:02:24 AM »
The most basic way to do it would be to turn an IO port on/off after a certain amount of delay cycles. Here is a simple one for the PIC12F863 using HiTech C.

Code: [Select]

#include <htc.h>

__CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTCLK);


void init(){

// CHANGE ANALOG CHANNELS TO DIGITAL I/O
CMCON0 = 0x07; // SET COMPARATOR OFF, CIN and COUT PINS AS I/O
    ANSEL = 0x00; // SET ANALOG INPUTS OFF

TRISIO = 0x00; // SETUP I/O BITS
GPIO = 0x00; // SET I/O BITS LOW

}

void main(){

init();

while(1){

GPIO =0x01;

_delay(50000); // delay 50k cycles
                                      //  50k cycles  seems to work good when using the internal clock

GPIO = 0x00;

_delay(50000);

}

}


And just add a switch between GPIO0 and the Right Trigger.

Im a beginner at this stuff just like you, so if i get corrected, listen to them.

ahh i see, this helps tremendously thank-you

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal