Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RE:From Basic PIC Pro to Mikro C

Status
Not open for further replies.

rylmv

New Member
Dear Sir,
I need help from converting coding from Basic PIC Pro to MikroC language. I've tried to read the coding samples of Basic PIC Pro but i couldnt follow up. Please help me out.
The coding are:

DEFINE OSC 8

DEFINE LCD_DREG PORTD;
DEFINE LCD_DBIT 4;
DEFINE LCD_RSREG PORTC;
DEFINE LCD_RSBIT 4;
DEFINE LCD_EREG PORTD;
DEFINE LCD_EBIT 3;
DEFINE LCD_RWREG PORTD;
DEFINE LCD_RWBIT 2;

//Define ADCIN Parameters
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
ADCON1=%10000010
TEMP1 VAR WORD

TRISB=%00000000
TRISD=%00000011
TRISC=%11101100
ADCON1=%10000010

SET1=300
SET1 VAR WORD
ADCVA1 VAR WORD
LEFT_FWD VAR PORTB.3
LEFT_REV VAR PORTB.4
RIGHT_FWD VAR PORTB.2
RIGHT_REV VAR PORTB.5
PAUSE 1000
LCDOUT $fe, 1

MAIN:
GOSUB READ_SENSOR
GOSUB DISPLAY
GOSUB COMPARE
GOTO MAIN
END

DISPLAY:
LCDOUT $FE, 2
LCDOUT "SENSOR = ",DEC TEMP1," "
LCDOUT $FE, $CO
LCDOUT "SETTING = ",DEC SET1," "
PAUSE 100
RETURN

COMPARE:
IF TEMP1 <= SET1 THEN
GOSUB MOTOR_FWD
GOSUB MOTOR_STOP
ENDIF

IF TEMP > SET1 THEN
GOSUB TURN_RIGHT
GOSUB MOTOR_STOP
ENDIF
RETURN

READ_SENSOR:
ADCIN 0, adcval
TEMP1 = adcval
PAUSE 5
RETURN

MOTOR_FWD:
HIGH RIGHT_FWD
HIGH LEFT_FWD
LOW RIGHT_REV
LOW LEFT_REV
PAUSE 100
RETURN

MOTOR_REV:
LOW RIGHT_FWD
LOW LEFT_FWD
HIGH RIGHT_REV
HIGH LEFT_REV
PAUSE 200
RETURN

TURN_RIGHT:
LOW RIGHT_FWD
HIGH LEFT_FWD
HIGH RIGHT_REV
LOW LEFT_REV
PAUSE 200
RETURN

MOTOR_STOP:
LOW RIGHT_FWD
LOW LEFT_FWD
LOW RIGHT_REV
LOW LEFT_REV
PAUSE 10
RETURN
 
Hi,
Why don't you compile the program and use the ASM code. I am not sure but I think MPLAB can change the ASM or HEX to C .
 
Status
Not open for further replies.

Latest threads

Back
Top