Please help convert this ATtiny85 code to PIC

Thread Starter

Sal

Joined Jan 16, 2013
4
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
}
 

be80be

Joined Jul 5, 2008
2,072
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
Rich (BB code):
void setup()
{
   CMCON = 0X7;  'turns off the comparator
   ANSEL = 0x0;    ' turns off the ADC
   TRISO = 0x0;    ' set's GPIO to outputs.
}
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:

Thread Starter

Sal

Joined Jan 16, 2013
4
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
Rich (BB code):
void setup()
{
   CMCON = 0X7;  'turns off the comparator
   ANSEL = 0x0;    ' turns off the ADC
   TRISO = 0x0;    ' set's GPIO to outputs.
}
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 ?
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?
 

MrChips

Joined Oct 2, 2009
30,707
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.
 

be80be

Joined Jul 5, 2008
2,072
If you would tell me what compiler your using I could help you better

Here a little more code to look at.

Rich (BB code):
#include <xc.h>
void setup()
{
   CMCON = 0X7;  //turns off the comparator
   ANSEL = 0x0;  //turns off the ADC 
   TRISIO = 0x0; //set's GPIO to outputs   
}

void time_H()
{
	unsigned long int x;
	for(x=0;x<7200000;x++)  // the numbers will need to be based on clock
    {
	if ( x == 7200000 )
	break;
	}           
} 
void time_M()
{
	unsigned long int x;
	for(x=0;x<100000;x++)  // the numbers will need to be based on clock
    {
	if ( x == 100000 )
	break;
	}

           
} 
void main ()
{
 ; //user code here
}
 
Last edited:

Thread Starter

Sal

Joined Jan 16, 2013
4
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..

void setup()
{
CMCON = 0X7; //turns off the comparator
ANSEL = 0x0; //turns off the ADC
TRISIO = 0x0; //set's GPIO to outputs
}

void time_H()
{
unsigned long int x;
for(x=0;x<7200000;x++) // the numders will need to be based on clock
{
if ( x == 7200000 )
break;
}
}
void time_M()
{
unsigned long int x;
for(x=0;x<100000;x++) // the numders will need to be based on clock
{
if ( x == 100000 )
break;
}


}

void main() {

GPIO = 0xFF;
Delay_ms(100000);
GPIO = 0;
Delay_ms(50000);
GPIO = 0xFF;
Delay_ms(200000);
GPIO = 0;


Delay_ms(6600000);


do {
GPIO = 0xFF;
Delay_ms(20000);
GPIO = 0;
Delay_ms(100000);
GPIO = 0xFF;
Delay_ms(20000);
GPIO = 0;



Delay_ms(300000);

} while(1);
}
 
Last edited:
Top