Need help to convert mikrobasic code to mikroc

Status
Not open for further replies.

Dinithi12

Banned
Joined
Sep 29, 2018
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
0
Code:
program LED_Blink
main:
 TRISB = 0 ' Configure pins of PORTB as
output
 eloop:
 PORTB = $FF ' Turn on diodes on PORTB
 Delay_ms(1000) ' Wait 1 second
 PORTB = 0 ' Turn off diodes on PORTB
 Delay_ms(1000) ' Wait 1 second
 goto eloop ' Stay in loop
 
Last edited by a moderator:

Code:
void main (void)
{
TRISB = 0;
while(1)
{
PORTB = 0xFF;
delay_ms(1000);
PORTB = 0;
delay_ms(1000);
}
}
 
Need help to convert microbasic into micro c

Code:
dim j as byte
dim i as integer


main:
'ANSEL = 0x00
'ADCON0 = 1
ADCON1 = %0110

  CMCON  = 0x07
     'ADCON0 = 1
     'ADCON1 = 1
    ' CMCON = 0x07
     'VRCON = 0x00
     TRISA = %01111
     TRISB = %00000000
     TRISC = %00000000
     TRISD = %00000000
     TRISE = %000
     PORTA = %00000000
     PORTB = %00000000
     PORTC = %00000000
     PORTD = %00000000
     PORTE = %000

     CCP1CON = 0x0F '// Select the PWM mode.
     CCP2CON = 0x0F '// Select the PWM mode.

    CCPR1L = 00
    CCPR2L = 00



 i = 0

  Pwm_Init(5000)        ' Initialize PWM module, freq = 5kHz.
  Pwm_Start
  
for j=0 to 5
  PORTB=%00010000
  Delay_ms(500)
  PORTB=%00100000
  Delay_ms(500)
next j

PORTB = %00000000
delay_ms(1000)

while true
    If PORTA=%01001 then  '1,2=0  forw
       PORTB=%00110110
       CCPR1L = 190
       CCPR2L = 200
       else
           if PORTA=%01100 then  'dbl right
              PORTB=%00011010
              CCPR1L = 150
              CCPR2L = 200
              i=0
              else
                  if PORTA=%00011 then 'dbl left
                     PORTB=%00100101
                     CCPR1L = 190
                     CCPR2L = 150
                     i=0
                     else
                         if PORTA=%01011 then   'right
                            PORTB=%00100100
                            CCPR1L = 210
                            CCPR2L = 0
                            i=0
                         else
                             if PORTA=%01101 then     'left
                                PORTB=%00100010
                                CCPR1L = 0
                                CCPR2L = 220
                                i=0
                                else
                                    if PORTA=%01111 then
                                       PORTB=%00001001
                                       CCPR1L = 160
                                       CCPR2L = 170
                                       delay_ms(300)
                                       PORTB=%00000000
                                       i=i+1
                                       else
                                           if PORTA=%01110 then
                                              PORTB=%00010010
                                              CCPR1L = 0
                                              CCPR2L = 220
                                              i=0
                                              else
                                                  if PORTA=%00111 then
                                                     PORTB=%00100100
                                                     CCPR1L = 210
                                                     CCPR2L = 0
                                                     i=0
                                                   end if
                                            end if
                                     end if
                               end if
                         end if
                     end if
                     
            end if
              
    end if

    if i=10 then
    while true
       PORTB=%00110000
       Delay_ms(500)
       PORTB=%00000000
       Delay_ms(500)
     wend
    end if
wend
end.
 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…