Help Needed with Code Conversion

Status
Not open for further replies.

hitesh joshi

Newbie level 6
Joined
Jun 27, 2013
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Visit site
Activity points
109
Hi,
i have C language code for AVR ATTINY 85. As i dont have a AVR Studio for compiling it into hex code. Can anyone convert it into Hex and send me the conversion file.
Yours help will be appreciated.

Regards
Hitesh Joshi

heres the code


Code:
#define trigPin 4
#define echoPin 3
#define motor 0

const byte RANGE_FAR = 60, RANGE_MED = 30, RANGE_CLOSE = 15, 
SENS_HIGH = HIGH, SENS_MED = 200, SENS_LOW = 150;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motor, OUTPUT);
  //ON Indicator:
  digitalWrite(motor, HIGH);
  delay(200);
  digitalWrite(motor, LOW);
  delay(100);
  digitalWrite(motor, HIGH);
  delay(200);
  digitalWrite(motor, LOW);
  delay(100);
}

void loop() {
  //distance finding logic:
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  //"if" statement block for motor sensitivity:
  if(distance<RANGE_CLOSE&&distance>0){
    digitalWrite(motor,SENS_HIGH);
    delay(100);
    digitalWrite(motor,LOW);
  }
  else if(distance<RANGE_MED&&distance>=RANGE_CLOSE){
    analogWrite(motor,SENS_MED);
    delay(100);
    digitalWrite(motor,LOW);
  }
  else if(distance>=RANGE_MED&&distance<RANGE_FAR){
    analogWrite(motor,SENS_LOW);
    delay(100);
    digitalWrite(motor,LOW);
  }
  else
    digitalWrite(motor,LOW);
}
 
Last edited by a moderator:

The code you posted is Arduino code. Do you need the code to be ported to any other AVR micro ? If yes, mention AVR used, Crystal frequency and show circuit. I am attaching your Arduino code compiled for Arduino Uno R3.


It seems you need a code where motor of a robot is controlled based on distance measured using Ultrasonic sensor. If you are using Arduino boards then you can use NewPing library to get distance from US sensor.
 

Attachments

  • build5758471438246879203.tmp.rar
    197.2 KB · Views: 45

thanks for replying. Actually yeah the vibrating motor is controlled by the uc based on distance sensed by the Sensor.
Also i am new to AVR microcontrollers. I have always worked in PIC's. Just let me know the codes which you sent me, can they be directly burnt in AVR microcontroller using a AVR Programmer? As i dont have Arduino board.

Regards
Hitesh
 

Yes, the hex file can be flashed in a stand alone AVR chip as long as the device and clock speed matches the one used at compile time.

It is very simple to get Arduino https://arduino.cc/en/Main/Software , you can either install it or just extract the folder and use it.
Having the compiler will help you experiment with the code without having to rely on others to compile it.
 

Hi. Thanks for replying.
I am facing an issue. I am currently working on project and my partner who actually writes codes for me is unavailable due to some reasons.
i already posted a code for AVR Attiny 85. I need the same Code for PIC16f876A UC. I have never worked on AVR's but just PIC's.
If anyone can help kindly reply. i Will share the project requirements..

Regards
Hitesh Joshi
 

As mentioned earlier Arduino and its libraries are open source. You can see the codes of NewPing library and port it with little changes to PIC. You can also use MPIDE with ChipKit Uno32 boards. They have PIC32 in that board and same NewPing library can be used with MPIDE. Chipkit boards work at 3.3V not 5V like Arduino but you get 32 bit controllers with lots of Program space and RAM.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…