need help in this code in mplab to mikroc

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
amel samuel
Posts: 3
Joined: 23 Apr 2012 17:56

need help in this code in mplab to mikroc

#1 Post by amel samuel » 27 Apr 2012 20:06

i makesome change to convert to mikroc is there is any eeror tell me
what mean //__CONFIG ( 0x3F32 ); //Configuration bits
can eefect if i dont make in mikroc i make it as comment what effect m code
// include
//======================================================================================================
//#include <pic.h>

// configuration
//======================================================================================================
//__CONFIG ( 0x3F32 ); //Configuration bits

// define
//=======================================================================================================
//#define _XTAL_FREQ 20000000

//#define sw1 Rc0
//#define signal RC3
//#define echo RC2
//#define led RC1


// main function
//===========================================================================================================
void main()
{
unsigned char i; //declare variables
unsigned int signal_int[5];
unsigned int ave_int=0;
unsigned int exact_mm=0;

// ADCON1 = 0b00000110; //set all portA as digital I/O
// TRISA = 0b00100000; //set all PORTA pin as OUTPUT
// TRISB = 0b00000000; //set all PORTB pin as output
TRISC = 0b0000101; //set all PORTC pin as output

T1CON=0b00010000; //setting timer1. The prescale is 1:2.
TMR1H=0;
TMR1L=0;

PORTC=0;


while(1)
{
if(RC0_bit==0) //if sw1 is pressed
{
while(RC0_bit==0); //Waiting sw1 to be released

for(i=0;i<5;i++) //Repeat 5 times to take 5 reading from ultrasonic sensor
{
TMR1H=0; //clear counter MS Byte
TMR1L=0; //clear counter LS Byte
// TRISC=0b00010000; //change signal pin to output
RC3_bit=0; //clear signal pin
delay_us(5); //Delay 2 us
RC3_bit=1; //Set the signal pin
delay_us(10); //Delay 5 us
RC3_bit=0; //clear signal pin

//TRISC=0b00011000; //change signal pin to input
while(RC3_bit==0); //wait the signal pin to be high
T1CON=0b00010001; //once the signal pin is read as high, on the counter
while(RC2_bit==0); //wait the sinal pin to be low
T1CON=0b00010000; //once the signal pin is read as low, off the counter

signal_int=TMR1H; //combine two byte of counter value to become an integer(16 bits)
signal_int=signal_int<<8;
signal_int=signal_int|TMR1L;
delay_ms(10); //delay 10 ms
}

//calculate the average value of the 5 reading
ave_int=(unsigned int)(((long)signal_int[0]+(long)signal_int[1]+(long)signal_int[2]+(long)signal_int[3]+(long)signal_int[4])/5);


// According to Parallax's datasheet for the PING, there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per second).
// This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// The speed of sound is 2.9033858 microseconds per millimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
exact_mm=(unsigned int)((double)ave_int/2.0/2.9033858); //Convert the counter value to readable value in mm unit (5---->2)


}
}
if( exact_mm <200 )
{

RC2_bit = 1;
delay_us(30000000);
}
}

jtemples
Posts: 258
Joined: 22 Jan 2012 05:46

Re: need help in this code in mplab to mikroc

#2 Post by jtemples » 28 Apr 2012 18:11

i makesome change to convert to mikroc is there is any eeror tell me
First thing you do in porting code is to understand both compilers extremely well.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: need help in this code in mplab to mikroc

#3 Post by filip » 30 Apr 2012 09:08

Hi,

Your code compiles fine, but as for the functionality I cannot be sure.

Regards,
Filip.

amel samuel
Posts: 3
Joined: 23 Apr 2012 17:56

Re: need help in this code in mplab to mikroc

#4 Post by amel samuel » 03 May 2012 20:27

filip wrote:Hi,

Your code compiles fine, but as for the functionality I cannot be sure.

Regards,
Filip.
thanks for all but i try to understand with make some project i am Beginner so Dear Filip if you see thing is false please tell me :D

Post Reply

Return to “mikroC PRO for PIC General”