Please help convert this ATtiny85 code to PIC

Discussion in 'Embedded Systems and Microcontrollers' started by Sal, Jan 16, 2013.

  1. Sal

    Thread Starter New Member

    Jan 16, 2013
    4
    0
    Hello to all, can someone please help me to convert the following code from ATTiny85 to Pic 12f657?

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

    void setup() {
    // initialize the digital pin as an output. We are using Pin 2 on the Attiny85 microcontroller

    pinMode(2, OUTPUT);

    digitalWrite(2, HIGH);// blink LEDs once to signal power on
    delay(2000);
    digitalWrite(2, LOW);
    delay(7200000); // Wait 2 hours
    }

    void loop() {
    digitalWrite(2, HIGH); // set the LED on
    delay(1000); // wait for a second
    digitalWrite(2, LOW); // set the LED off

    delay(600000); //Wait 10 minutes
    }
     
  2. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    It not that hard give it a try.
    pinMode(2, OUTPUT); would be TRISO = 0x0;
    digitalWrite(2, HIGH); would be GPIO = 0x3;

    so setup would look like
    Code ( (Unknown Language)):
    1.  
    2. void setup()
    3. {
    4.    CMCON = 0X7;  'turns off the comparator
    5.    ANSEL = 0x0;    ' turns off the ADC
    6.    TRISO = 0x0;    ' set's GPIO to outputs.
    7. }
    8.  
    Now you add the config and the main code ok ? if you can't try to any way and I'll show you the rest and read this to http://ww1.microchip.com/downloads/en/devicedoc/41190c.pdf

    Oh and one more thing you sure you don't have a 12f675 theres no 12f657 ?
     
    Last edited: Jan 16, 2013
  3. Sal

    Thread Starter New Member

    Jan 16, 2013
    4
    0
    Thanks! You were very helpfull!

    Now I get a different problem with error: "Argument is out of range"

    This is for:

    Delay_ms(7200000);

    It accepts only until 50000 for 4Mhz. I don't mind the timming but even i change it.. it's proportional with limits, and nothing really changes.

    Is there any solution to that? can I change limits somehow?
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    A 16-bit unsigned integer has a range of 0 to 65535.
     
  5. Sal

    Thread Starter New Member

    Jan 16, 2013
    4
    0
    That means that i have to change 12f675 to something else?
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    Not really. You can put Delay_ms( ) into a loop to get the delay you wish or you can write your own delay function using unsigned long integers.
     
  7. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    If you would tell me what compiler your using I could help you better

    Here a little more code to look at.

    Code ( (Unknown Language)):
    1.  
    2. #include <xc.h>
    3. void setup()
    4. {
    5.    CMCON = 0X7;  //turns off the comparator
    6.    ANSEL = 0x0;  //turns off the ADC
    7.    TRISIO = 0x0; //set's GPIO to outputs  
    8. }
    9.  
    10. void time_H()
    11. {
    12.     unsigned long int x;
    13.     for(x=0;x<7200000;x++)  // the numbers will need to be based on clock
    14.     {
    15.     if ( x == 7200000 )
    16.     break;
    17.     }          
    18. }
    19. void time_M()
    20. {
    21.     unsigned long int x;
    22.     for(x=0;x<100000;x++)  // the numbers will need to be based on clock
    23.     {
    24.     if ( x == 100000 )
    25.     break;
    26.     }
    27.  
    28.            
    29. }
    30. void main ()
    31. {
    32.  ; //user code here
    33. }
    34.  
     
    Last edited: Jan 18, 2013
  8. Sal

    Thread Starter New Member

    Jan 16, 2013
    4
    0
    Sure!, I use the:
    ---------------------------------------------
    mikroC, mikroElektronika C compiler
    for Microchip PIC microcontrollers
    Version: 8.1.0.0
    ---------------
    and the Easypic3 board
    ------------------------------------------------

    I drop the timing for battery saving reasons to 0.3MHz.

    The problems are the long delays,

    Delay_ms(6600000); should be 2 hours

    and

    Delay_ms(300000); should be 5 minutes



    I placed the setup above and this is the code i have so far without errors..

     
    Last edited: Jan 18, 2013
Loading...