AcidMods Resources ----- ( These are helpful tools for modding ) > Pic Programmers and Programs

info/help C language programming pic

(1/5) > >>

cc600:
hello

I want to write my own rapid fire to 360 C language
( not for profit , just a personal desire ) to try programming peak.

I look at the asm sources to get an idea or try to understand a bit how the programs but I is not knowledge in assembly language not so obvious .....

I started in a small test of pressing the Sync button and LED lights up , but nothing is happening ( I doubted a little), yet without compilation error .....
my code just for lighting an LED :


--- Code: ---# pragma chip PIC12F683

/ / pin name
# define rttriger GPIO.0
# define lttriger GPIO.1
# define sync GPIO.3
# define LED GPIO.2

void Init ()
{
     // Set Frequency 8mhz
   OSCCON = 0b01110001 ;
 
     // Configure GPIO Port
   ANSEL = 0b00000011;     // Configure pins GP0 , GP1 as ANALOG
   Trisio = 0b00001011;    // GP0 , GP1 GP3 are input , rest is output
   GPIO = 0xFF;        // Set all pins to output high (0x00 = low)

     // Set Comparator
   CMCON0 = 7;        // Comparator is turned OFF
 }
void main ()
{
   INIT();

   while(1)
  {
    adc = ADC_Read(0);   // Get 10-bit results of AD conversion for GPIO0
    if(adc == 0)
    {
           //Trigger is not pulled
           ANS0_bit = 1;
           
      if ( adc > 409)
       {
//Trigger is pulled
             ANS0_bit = 0;
             RT = 0x00; // LOW RT ?
             sps;
             Delay_Cyc(adc);
        }
     }
  }; // End of run loop forever
} //End of main

--- End code ---

I have wanted to know if possible to have a base in C language
I do not demand a complete code , just a base to see and understand how I look a bit on the net, the 12F683 datasheet , etc.
but a little hard to understand the how of why ...... and little explanatory thing about it .


my goal was to begin to make a rapid fire , one mode, the easiest possible way to get familiar with .

thank you

RDC:
You are not going to get someone to walk you thru coding in C from the beginning, that's what a classroom and a teacher is for.

The first thing you need to do is Google it. If you can not find any information on programming ins C and the compiler you are using, then you are not looking for it.

Every C compiler is a little bit different also, so you will need to know what commands your compiler can use, or use one that someone else has already done something in so all of the commands are the same.

I use MikroC here, and while it looks similar to that, all C does, it is not the exact same and that would not compile here.

That code you have written there will not make an LED blink if you press Sync, that Sync Input is not even in the code loop there.

In MicroC, and using a 12F683, to make one of the controller LEDs blink with GP2 while you press Sync that is connected to GP3, you could do this..


--- Code: ---/*******************************************************************************
PIC12F683 @ 8MHz
Code for Blinking an LED on GP2 if Sync Button on GP3 is pressed
AcidMods
*******************************************************************************/

#define LED GP2_bit
#define SY GP3_bit

void INIT(){
OSCCON = 0b01110111;                    // Set 8mhz Frequency
CMCON0 = 7;                             // Comparator off
ANSEL = 0;                              // Analog Off
TRISIO0_bit = 0;                        //
TRISIO1_bit = 0;                        //
TRISIO2_bit = 0;                        // LED (set to Input or it will interfere with the controller being able to use it)
TRISIO3_bit = 1;                        // SYNC Button
TRISIO4_bit = 1;                        //
TRISIO5_bit = 1;                        //
}


void main() {                           // Start of Main

 INIT();                                // Initialize the PIC

while (1){                              // Start of Run Forever Loop

 while (SY == 0){                       // While the SYNC button is pressed
  TRISIO2_bit = 0;                      // Set LED pin to Output (must set back to an Input when finished with the LED)
  LED = 1;                              // Turn LED on
  delay_ms(300);                        // Time LED is on, 300ms
  LED = 0;                              // Turn LED off
  delay_ms(50);                         // Time LED is off, 50ms
  }
  TRISIO2_bit = 1;                      // Turns LED off and keeps the pin TRIS so the controller can use the LED
 }                                      // End of Run Forever Loop
}                                       // End of Main


--- End code ---

Again, Google whatever you are trying to figure out first, it is all out there, you just have to look for it. People are around here are glad to help, but they are not going to do all of the ground work for you.

cc600:
thank you for the answer man

I do not want to do all the work for me I'm still a "newbie" in C programming I still learn every day (and I think not having finished ..)

it's just to satisfy a personal curiosity

this is 2/3 days I work on has to look for information about why and how, but I began to mix my brushes with all that I have read the right and left

I'm just looking for a base not a complete code in order to study and understand the above

In any case, thank you for this piece of code will put it very useful already

hi

even a small problem peak does what I ask him, but there are still some gray area for me

for my test I put him three modes by his works against it crashes and stops after a tamping the trigger

the main.c:


--- Code: ---
/*******************************************************************************
   PIC12F683 @ 8MHz
        Code for simple rapid fire for xbox 360
                      for [url=https://www.acidmods.com]www.acidmods.com[/url]
*******************************************************************************/
void main()

{// Start of Main

    int mod = 0, i, sps[3] = {0 , 0, 0};
   
   INIT();                                // Initialize the PIC

while (1)
{                             
    if (SYNC == 0)
    {                    //if the SYNC button is pressed
         
                mod++;
            if(mod > 3)
             mode = 1;

           for(i = 0; i < mod; i++)
           {
           TRISIO2_bit = 0;// Set LED pin to Output
           LED = 1;// Turn LED on
           delay_ms(300);// Time LED is on, 300ms
           LED = 0;  // Turn LED off
           delay_ms(300); // Time LED is off, 50ms
           }

     }
     
    switch(mod)
     {
     case 1:

        TRISIO5_bit = 0;     //set RT pin to output

        if(rt == 1)
        {
          sps[0] = (1000/10)/2;
          sps[0];
        }

       break;
     
      case 2:

          TRISIO4_bit = 0;      //set LT pin to output
          TRISIO5_bit = 0;     // set RT pin to output

          if(rt == 1 || lt == 1)
          {
            sps[1] = (1000/18)/2;
            sps[1];
          }

         break;
     
      case 3:

      break;
      }


     TRISIO2_bit = 1;       
     TRISIO4_bit = 1;
     TRISIO5_bit = 1;
 }                                       
 
}                                       


--- End code ---

a big thank you to the RDC code and explanation

I am trying to see to add programming mode, hold the left stick, etc ....
next update ..  :hifive:

.hex for those that want to test :
https://drive.google.com/file/d/0B5jjXb7Hc_E-S3B0b2otMWFWZGM/edit?usp=sharing

ps moderator: I do not know if my post and always in the right section

[admin]Your fine with right setion stop double and tripple posting last warning[/admin]

RDC:
The Triggers are Analog, not Digital. So that bit of code you're using to tell if they are pressed

if (RT == 1)

will not work correctly at all. You have some reading and testing to do now as Analog is a bit different than a simple 0 or 1 Digital button.

Also, depending on what version of controller you're using there, they may go from Hi to Lo when pulled, or from Lo to Hi and everything in between, but in either case they're Analog, not just off or on like a button on the controller.

You need to setup those IO pins so they are default Inputs and Analog, then you change them 'on the fly' in code, as they need to be Analog Inputs to tell if the Trigger is pulled or not, then changed to Outputs to force the line back to a Hi or Lo state, depending on the controller version, so the controller 'thinks' the Trigger is not pulled, even though it is pulled, and then switched it back to an Input again so it can tell if it's still pulled or not.

I'm not going to code all of that out, but it needs to be done something like this..

In the INIT:

Set the IO for LT/RT as an Input and make it Analog

In Code:

Read the Analog value from that pin

If LT/RT is not pulled, do nothing and leave the pin as an Analog Input so it does not interfere with normal operation

If LT/RT is pulled, set the IO to an Output and make it Hi or Lo (depends on controller) for one cycle of your SPS timing, then set it back to an Input and Analog and check the value again. If it's still pulled do another Output cycle, if it's not pulled do nothing and leave it as an Analog Input.

cc600:
thank you for the advice!  :cool:

I see what you mean, but hard to understand how certain functions of the peak

this is what I did:  :dntknw:


--- Code: ---
/*******************************************************************************
PIC12F683 @ 8MHz
Code for simple rapid fire for xbox 360
AcidMods
*******************************************************************************/

#define LED          GP2_bit
#define SYNC         GP3_bit
#define rt           GP5_bit
#define lt           GP4_bit


void INIT()
{

   OSSCCON = 0b01110001;     //set int osc to 8MHz
   CMCON0 = 7;                             // Comparator off
   CMCON1 = 0;
   ANSEL = 0b00101000;                              // Analog On ?
   TRISIO0_bit = 0;                        //
   TRISIO1_bit = 0;                        //
   TRISIO2_bit = 0;                        // LED (set to Input or it will interfere with the controller being able to use it)
   TRISIO3_bit = 1;                      // SYNC Button
   TRISIO4_bit = 1;                      // Trigger LT
   TRISIO5_bit = 1;                        // Trigger RT
     
}


void main()
{// Start of Main

    int mode = 0, i, sps = (1000/10)/2;
    unsigned int adcValue;
   
   INIT();                                // Initialize the PIC
   
while (1)
{                              // Start of Run Forever Loop

    if (SYNC == 0)
    {//if the SYNC button is pressed
           
         mode = 1;
                   
           for(i = 0; i < mode; i++)
           {
             
               TRISIO2_bit = 0;// Set LED pin to Output (must set back to an Input when finished with the LED)
               LED = 1;// Turn LED on
               delay_ms(300);// Time LED is on, 300ms
               LED = 0;  // Turn LED off
               delay_ms(300); // Time LED is off, 300ms           
           }

     }
     

    if(mode)
      {
          adcValue = ADC_Read(5);   //read analog value pin 5 (RT) ??

          if(adcValue > 0)
          {

             Delay_Cyc(adcValue); //..... ???

                    TRISIO5_bit = 0;
                     sps;

          }
      }

     TRISIO2_bit = 1;// Turns LED off and keeps the pin TRIS so the controller can use the LED
     TRISIO5_bit = 1;
 }                                          // End of Run Forever Loop
 
}                                       // End of Main


--- End code ---


the "adc-read" function, MickroC returns a numerical value right?

it is at this level that it becomes a blur .... and datasheet for beginners is a headache ..

Navigation

[0] Message Index

[#] Next page

Go to full version