Examples - Compiler Quick Start Guide

From MikroElektonika Documentation
Jump to: navigation, search
Quick Start Guide
Mikroelektronika compilers.png
Quick Start Guide
Guide Sections

Examples

To get you acquainted with our compilers we have prepared code examples for LED blinking for each of the 21 compilers we have on offer.

We suggest that you read the documentation on the MCU you are using, before you start programming.

LED blinking is the simplest example, and once you understand how it works you will be able to move on to more complex examples.

LEDs can be used for visual indication of the logic state on PORT pins. An active LED indicates that a logic high (1) is present on the pin. In order to enable PORT LEDs, it is necessary to enable the corresponding switches on the board you are using.

LED blinking for mikroC

mikroC PRO for PIC

For this example we have used the EasyPIC7 development board

  • MCU: PIC18F45K22 from Microchip.
  • Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal.
  • Board settings: Turn ON the PORT LEDs at SW3.
 1  */
 2 
 3 void main() {
 4 
 5   TRISA = 0;           // set direction to be output
 6   TRISB = 0;           // set direction to be output
 7   TRISC = 0;           // set direction to be output
 8   TRISD = 0;           // set direction to be output
 9   TRISE = 0;           // set direction to be output
10 
11   do {
12     LATA = 0x00;       // Turn OFF LEDs on PORTA
13     LATB = 0x00;       // Turn OFF LEDs on PORTB
14     LATC = 0x00;       // Turn OFF LEDs on PORTC
15     LATD = 0x00;       // Turn OFF LEDs on PORTD
16     LATE = 0x00;       // Turn OFF LEDs on PORTE
17     Delay_ms(1000);    // 1 second delay
18 
19     LATA = 0xFF;       // Turn ON LEDs on PORTA
20     LATB = 0xFF;       // Turn ON LEDs on PORTB
21     LATC = 0xFF;       // Turn ON LEDs on PORTC
22     LATD = 0xFF;       // Turn ON LEDs on PORTD
23     LATE = 0xFF;       // Turn ON LEDs on PORTE
24     Delay_ms(1000);    // 1 second delay
25   } while(1);          // Endless loop
26 }

mikroC PRO for dsPIC

For this example we have used the EasyPIC7 development board

  • MCU: dsPIC30F4013 from Microchip;
  • Oscillator: XT-PLL8, 80.000MHz.
 1 void main() {
 2 
 3   ADPCFG = 0xFFFF;       // Configure AN pins as digital I/O
 4   TRISB = 0;             // Initialize PORTB as output
 5   TRISC = 0;             // Initialize PORTC as output
 6   TRISD = 0;             // Initialize PORTD as output
 7   TRISF = 0;             // Initialize PORTF as output
 8 
 9   LATB = 0;              // Set PORTB to zero
10   LATC = 0;              // Set PORTC to zero
11   LATD = 0;              // Set PORTD to zero
12   LATF = 0;              // Set PORTF to zero
13 
14   while(1) {
15     LATB = ~LATB;        // Invert PORTB value
16     LATC = ~LATC;        // Invert PORTC value
17     LATD = ~LATD;        // Invert PORTD value
18     LATF = ~LATF;        // Invert PORTF value
19     Delay_ms(1000);
20   }
21 }

mikroC PRO for PIC32

For this example we have used the EasyPIC Fusion v7 development board.

  • MCU: P32MX795F512L from Microchip;
  • Oscillator: XT-PLL, 80.0000MHz.
  • Board settings: Turn ON PORTA, B, C, D, F & G LEDS at SW15.
 1  void main() {
 2   AD1PCFG = 0xFFFF;      // Configure AN pins as digital I/O
 3   JTAGEN_bit = 0;        // Disable JTAG
 4 
 5   TRISA = 0;             // Initialize PORTA as output
 6   TRISB = 0;             // Initialize PORTB as output
 7   TRISC = 0;             // Initialize PORTC as output
 8   TRISD = 0;             // Initialize PORTD as output
 9   TRISF = 0;             // Initialize PORTE as output
10   TRISG = 0;             // Initialize PORTG as output
11 
12   LATA = 0;              // Set PORTA to zero
13   LATB = 0;              // Set PORTB to zero
14   LATC = 0;              // Set PORTC to zero
15   LATD = 0;              // Set PORTD to zero
16   LATF = 0;              // Set PORTE to zero
17   LATG = 0;              // Set PORTG to zero
18 
19   while(1) {
20     LATA = ~PORTA;       // Invert PORTA value
21     LATB = ~PORTB;       // Invert PORTB value
22     LATC = ~PORTC;       // Invert PORTC value
23     LATD = ~PORTD;       // Invert PORTD value
24     LATF = ~PORTF;       // Invert PORTE value
25     LATG = ~PORTG;       // Invert PORTG value
26     Delay_ms(1000);
27   }
28 }

mikroC PRO for ARM

For this example we have used the EasyMx v7 for STM(R) ARM(R) development board.

  • MCU: STM32F107VC;
  • Oscillator: HSE-PLL, 72.000MHz.
  • Board settings: Turn ON PORTA, PORTB, PORTC, PORTD, PORTE at SW15.
 1 void main() {
 2   GPIO_Digital_Output(&GPIOA_BASE, _GPIO_PINMASK_ALL); // Set PORTA as digital output
 3   GPIO_Digital_Output(&GPIOB_BASE, _GPIO_PINMASK_ALL); // Set PORTB as digital output
 4   GPIO_Digital_Output(&GPIOC_BASE, _GPIO_PINMASK_ALL); // Set PORTC as digital output
 5   GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_ALL); // Set PORTD as digital output
 6   GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_ALL); // Set PORTE as digital output
 7 
 8   GPIOA_ODR = 0;
 9   GPIOB_ODR = 0;
10   GPIOC_ODR = 0;
11   GPIOD_ODR = 0;
12   GPIOE_ODR = 0;
13 
14   while(1) {
15     GPIOA_ODR = ~GPIOA_ODR; // Toggle PORTA
16     GPIOB_ODR = ~GPIOB_ODR; // Toggle PORTB
17     GPIOC_ODR = ~GPIOC_ODR; // Toggle PORTC
18     GPIOD_ODR = ~GPIOD_ODR; // Toggle PORTD
19     GPIOE_ODR = ~GPIOE_ODR; // Toggle PORTE
20     Delay_ms(1000);
21   }
22 }

mikroC PRO for AVR

For this example we have used the EasyAVR v7 development board.

  • MCU: ATMEGA32;
  • Oscillator: External Clock 08.0000 MHz.
  • Board settings: Make sure you turn ON the PORTA, PORTB, PORTC and PORTD LEDs (SW10.5, SW10.6, SW10.7 and SW10.8).
 1 void main() {
 2   DDRA = 0xFF;           // Set direction to be output
 3   DDRB = 0xFF;           // Set direction to be output
 4   DDRC = 0xFF;           // Set direction to be output
 5   DDRD = 0xFF;           // Set direction to be output
 6   
 7   do {
 8     PORTA = 0x00;        // Turn OFF diodes on PORTA
 9     PORTB = 0x00;        // Turn OFF diodes on PORTB
10     PORTC = 0x00;        // Turn OFF diodes on PORTC
11     PORTD = 0x00;        // Turn OFF diodes on PORTD
12     Delay_ms(1000);      // 1 second delay
13     
14     PORTA = 0xFF;        // Turn ON diodes on PORTA
15     PORTB = 0xFF;        // Turn ON diodes on PORTB
16     PORTC = 0xFF;        // Turn ON diodes on PORTC
17     PORTD = 0xFF;        // Turn ON diodes on PORTD
18     Delay_ms(1000);      // 1 second delay
19   } while(1);            // Endless loop
20 }

mikroC PRO for 8051

For this example we have used the Easy8051v6 development board.

  • MCU: AT89S8253 MCU;
  • Oscillator: External Clock 10.0000 MHz.
  • Board settings: Turn ON the PORT LEDs (SW7). On Easy8051v6 LEDs are activated by logical zero.
 1 void main() {
 2   do {
 3     P0 = 0x00;        // Turn ON diodes on PORT0
 4     P1 = 0x00;        // Turn ON diodes on PORT1
 5     P2 = 0x00;        // Turn ON diodes on PORT2
 6     P3 = 0x00;        // Turn ON diodes on PORT3
 7     Delay_ms(1000);   // 1 second delay
 8     
 9     P0 = 0xFF;        // Turn OFF diodes on PORT0
10     P1 = 0xFF;        // Turn OFF diodes on PORT1
11     P2 = 0xFF;        // Turn OFF diodes on PORT2
12     P3 = 0xFF;        // Turn OFF diodes on PORT3
13     Delay_ms(1000);   // 1 second delay
14 
15   } while(1);         // Endless loop
16 }

mikroC PRO for FT90x

For this example we have used the EasyFT90x v7 development board.

  • MCU: FT900;
  • Oscillator: CPU at full system clock, 100.000MHz.
  • Board settings: Turn ON ports GPIO 00-07, GPIO 08-15, GPIO 16-23, GPIO 24-31, GPIO 32-39, GPIO 40-47, GPIO 48-55 and GPIO 56-66 at SW8.
 1 void main() {
 2   GPIO_Digital_Output(&GPIO_PORT_00_07, _GPIO_PINMASK_ALL); // Set GPIO 00-07 port as digital output
 3   GPIO_Digital_Output(&GPIO_PORT_08_15, _GPIO_PINMASK_ALL); // Set GPIO 08-15 port as digital output
 4   GPIO_Digital_Output(&GPIO_PORT_16_23, _GPIO_PINMASK_ALL); // Set GPIO 16-23 port as digital output
 5   GPIO_Digital_Output(&GPIO_PORT_24_31, _GPIO_PINMASK_ALL); // Set GPIO 24-31 port as digital output
 6   GPIO_Digital_Output(&GPIO_PORT_32_39, _GPIO_PINMASK_ALL); // Set GPIO 32-39 port as digital output
 7   GPIO_Digital_Output(&GPIO_PORT_40_47, _GPIO_PINMASK_ALL); // Set GPIO 40-47 port as digital output
 8   GPIO_Digital_Output(&GPIO_PORT_48_55, _GPIO_PINMASK_ALL); // Set GPIO 48-55 port as digital output
 9   GPIO_Digital_Output(&GPIO_PORT_56_63, _GPIO_PINMASK_ALL); // Set GPIO 56-63 port as digital output
10   GPIO_Digital_Output(&GPIO_PORT_64_66, _GPIO_PINMASK_ALL); // Set GPIO 64-66 port as digital output
11 
12   GPIO_PORT_00_07 = 0;
13   GPIO_PORT_08_15 = 0;
14   GPIO_PORT_16_23 = 0;
15   GPIO_PORT_24_31 = 0;
16   GPIO_PORT_32_39 = 0;
17   GPIO_PORT_40_47 = 0;
18   GPIO_PORT_48_55 = 0;
19   GPIO_PORT_56_63 = 0;
20   GPIO_PORT_64_66 = 0;
21 
22   while (1)
23   {
24     GPIO_PORT_00_07 = ~GPIO_PORT_00_07; // togle PORT 00-07
25     GPIO_PORT_08_15 = ~GPIO_PORT_08_15; // togle PORT 08-15
26     GPIO_PORT_16_23 = ~GPIO_PORT_16_23; // togle PORT 16-23
27     GPIO_PORT_24_31 = ~GPIO_PORT_24_31; // togle PORT 24-31
28     GPIO_PORT_32_39 = ~GPIO_PORT_32_39; // togle PORT 32-39
29     GPIO_PORT_40_47 = ~GPIO_PORT_40_47; // togle PORT 40-47
30     GPIO_PORT_48_55 = ~GPIO_PORT_48_55; // togle PORT 48-55
31     GPIO_PORT_56_63 = ~GPIO_PORT_56_63; // togle PORT 56-63
32     GPIO_PORT_64_66 = ~GPIO_PORT_64_66; // togle PORT 64-66
33 
34     Delay_ms(1000);
35   }
36 }

LED blinking for mikroBacis

mikroBasic PRO for PIC

For this example we have used the EasyPIC7 development board.

  • MCU:PIC18F45K22 from Microchip;
  • Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal.
  • Board settings: Turn ON the PORT LEDs at SW3.
 1 program LED_Blinking
 2 
 3 main:
 4   TRISA = 0         ' set direction to be output
 5   TRISB = 0         ' set direction to be output
 6   TRISC = 0         ' set direction to be output
 7   TRISD = 0         ' set direction to be output
 8   TRISE = 0         ' set direction to be output
 9 
10   while TRUE
11     LATA = 0x00     ' Turn OFF LEDs on PORTA
12     LATB = 0x00     ' Turn OFF LEDs on PORTB
13     LATC = 0x00     ' Turn OFF LEDs on PORTC
14     LATD = 0x00     ' Turn OFF LEDs on PORTD
15     LATE = 0x00     ' Turn OFF LEDs on PORTE
16     Delay_ms(1000)  ' 1 second delay
17 
18     LATA = 0xFF     ' Turn ON LEDs on PORTA
19     LATB = 0xFF     ' Turn ON LEDs on PORTB
20     LATC = 0xFF     ' Turn ON LEDs on PORTC
21     LATD = 0xFF     ' Turn ON LEDs on PORTD
22     LATE = 0xFF     ' Turn ON LEDs on PORTE
23     Delay_ms(1000)  ' 1 second delay
24   wend              ' Endless loop
25 end.

mikroBasic PRO for dsPIC

For this example we have used the EASYPIC v7 for dsPIC30 development board.

  • MCU: dsPIC30F4013 from Microchip;
  • Oscillator: XT-PLL8, 80.000MHz.
  • Board settings: Turn ON port LEDs at SW10.
 1 program LED_Blinking
 2 
 3 main:
 4   ADPCFG = 0xFFFF      ' Configure AN pins as digital I/O
 5   TRISB = 0            ' Initialize PORTB as output
 6   TRISC = 0            ' Initialize PORTC as output
 7   TRISD = 0            ' Initialize PORTD as output
 8   TRISF = 0            ' Initialize PORTF as output
 9 
10   LATB = 0             ' Set PORTB to zero
11   LATC = 0             ' Set PORTC to zero
12   LATD = 0             ' Set PORTD to zero
13   LATF = 0             ' Set PORTF to zero
14 
15   while TRUE
16     LATB = not LATB    ' Invert PORTB value
17     LATC = not LATC    ' Invert PORTC value
18     LATD = not LATD    ' Invert PORTD value
19     LATF = not LATF    ' Invert PORTF value
20     Delay_ms(1000)
21   wend
22 end.

mikroBasic PRO for PIC32

For this example we have used the EasyPIC Fusion v7 development board.

  • MCU: P32MX795F512L from Microchip;
  • Oscillator: XT-PLL, 80.0000MHz.
  • Board settings: Turn ON PORTA, B, C, D, F & G LEDS at SW15.
 1  program Led_Blinking
 2 
 3 main:
 4   AD1PCFG = 0xFFFF      ' Configure AN pins as digital I/O
 5   JTAGEN_bit = 0        ' Disable JTAG
 6 
 7   TRISA = 0             ' Initialize PORTA as output
 8   TRISB = 0             ' Initialize PORTB as output
 9   TRISC = 0             ' Initialize PORTC as output
10   TRISD = 0             ' Initialize PORTD as output
11   TRISF = 0             ' Initialize PORTE as output
12   TRISG = 0             ' Initialize PORTG as output
13 
14   LATA = 0              ' Set PORTA to zero
15   LATB = 0              ' Set PORTB to zero
16   LATC = 0              ' Set PORTC to zero
17   LATD = 0              ' Set PORTD to zero
18   LATF = 0              ' Set PORTE to zero
19   LATG = 0              ' Set PORTG to zero
20 
21   while TRUE
22     LATA = not PORTA    ' Invert PORTA value
23     LATB = not PORTB    ' Invert PORTB value
24     LATC = not PORTC    ' Invert PORTC value
25     LATD = not PORTD    ' Invert PORTD value
26     LATF = not PORTF    ' Invert PORTE value
27     LATG = not PORTG    ' Invert PORTG value
28     Delay_ms(1000)
29   wend
30 end.

mikroBasic PRO for ARM

For this example we have used the EasyMx v7 for STM(R) ARM(R) development board.

  • MCU: STM32F107VC;
  • Oscillator: HSE-PLL, 72.000MHz.
  • Board settings: Turn ON PORTA, PORTB, PORTC, PORTD, PORTE at SW15.
 1  program LedBlinking
 2 main:
 3   GPIO_Digital_Output(@GPIOA_BASE, _GPIO_PINMASK_ALL) ' Set PORTA as digital output
 4   GPIO_Digital_Output(@GPIOB_BASE, _GPIO_PINMASK_ALL) ' Set PORTB as digital output
 5   GPIO_Digital_Output(@GPIOC_BASE, _GPIO_PINMASK_ALL) ' Set PORTC as digital output
 6   GPIO_Digital_Output(@GPIOD_BASE, _GPIO_PINMASK_ALL) ' Set PORTD as digital output
 7   GPIO_Digital_Output(@GPIOE_BASE, _GPIO_PINMASK_ALL) ' Set PORTE as digital output
 8 
 9   GPIOA_ODR = 0
10   GPIOB_ODR = 0
11   GPIOC_ODR = 0
12   GPIOD_ODR = 0
13   GPIOE_ODR = 0
14 
15   while TRUE
16     GPIOA_ODR = not GPIOA_ODR ' Toggle PORTA
17     GPIOB_ODR = not GPIOB_ODR ' Toggle PORTB
18     GPIOC_ODR = not GPIOC_ODR ' Toggle PORTC
19     GPIOD_ODR = not GPIOD_ODR ' Toggle PORTD
20     GPIOE_ODR = not GPIOE_ODR ' Toggle PORTE
21     Delay_ms(1000)
22   wend
23 end.

mikroBasic PRO for AVR

For this example we have used the EasyAVR v7 development board.

  • MCU: ATMEGA32;
  • Oscillator: External Clock 08.0000 MHz.
  • Board settings: Make sure you turn ON the PORTA, PORTB, PORTC and PORTD LEDs (SW10.5, SW10.6, SW10.7 and SW10.8).
 1  program LED_Blinking
 2   main:
 3     DDRA = 0xFF           ' Set direction to be output
 4     DDRB = 0xFF           ' Set direction to be output
 5     DDRC = 0xFF           ' Sset direction to be output
 6     DDRD = 0xFF           ' Set direction to be output
 7 
 8     while TRUE
 9       PORTA = 0x00        ' Turn ON diodes on PORTA
10       PORTB = 0x00        ' Turn ON diodes on PORTB
11       PORTC = 0x00        ' Turn ON diodes on PORTC
12       PORTD = 0x00        ' Turn ON diodes on PORTD
13       Delay_ms(1000)      ' 1 second delay
14 
15       PORTA = 0xFF        ' Turn OFF diodes on PORTA
16       PORTB = 0xFF        ' Turn OFF diodes on PORTB
17       PORTC = 0xFF        ' Turn OFF diodes on PORTC
18       PORTD = 0xFF        ' Turn OFF diodes on PORTD
19       Delay_ms(1000)      ' 1 second delay
20     wend                  ' Endless loop}
21   end.

mikroBasic PRO for 8051

For this example we have used the Easy8051v6 development board.

  • MCU: AT89S8253;
  • Oscillator: External Clock 10.0000 MHz;
  • Board settings: Turn ON the PORT LEDs (SW7). On Easy8051v6 LEDs are activated by logical zero.
 1  program LED_Blinking
 2 
 3 main:
 4   while TRUE
 5     P0 = 0x00        ' Turn ON diodes on PORT0
 6     P1 = 0x00        ' Turn ON diodes on PORT1
 7     P2 = 0x00        ' Turn ON diodes on PORT2
 8     P3 = 0x00        ' Turn ON diodes on PORT3
 9         
10     Delay_ms(1000)   ' 1 second delay
11         
12     P0 = 0xFF        ' Turn OFF diodes on PORT0
13     P1 = 0xFF        ' Turn OFF diodes on PORT1
14     P2 = 0xFF        ' Turn OFF diodes on PORT2
15     P3 = 0xFF        ' Turn OFF diodes on PORT3
16     Delay_ms(1000)   ' 1 second delay
17   wend               ' Endless loop
18 end.

mikroBasic PRO for FT90x

For this example we have used the EasyFT90x v7 development board.

  • MCU: FT900;
  • Oscillator: CPU at full system clock, 100.000MHz.
  • Board settings: Turn ON ports GPIO 00-07, GPIO 08-15, GPIO 16-23, GPIO 24-31, GPIO 32-39, GPIO 40-47, GPIO 48-55 and GPIO 56-66 at SW8.
 1  program LedBlinking
 2 
 3 main:
 4   GPIO_Digital_Output(@GPIO_PORT_00_07, _GPIO_PINMASK_ALL) ' Set GPIO 00-07 port as digital output
 5   GPIO_Digital_Output(@GPIO_PORT_08_15, _GPIO_PINMASK_ALL) ' Set GPIO 08-15 port as digital output
 6   GPIO_Digital_Output(@GPIO_PORT_16_23, _GPIO_PINMASK_ALL) ' Set GPIO 16-23 port as digital output
 7   GPIO_Digital_Output(@GPIO_PORT_24_31, _GPIO_PINMASK_ALL) ' Set GPIO 24-31 port as digital output
 8   GPIO_Digital_Output(@GPIO_PORT_32_39, _GPIO_PINMASK_ALL) ' Set GPIO 32-39 port as digital output
 9   GPIO_Digital_Output(@GPIO_PORT_40_47, _GPIO_PINMASK_ALL) ' Set GPIO 40-47 port as digital output
10   GPIO_Digital_Output(@GPIO_PORT_48_55, _GPIO_PINMASK_ALL) ' Set GPIO 48-55 port as digital output
11   GPIO_Digital_Output(@GPIO_PORT_56_63, _GPIO_PINMASK_ALL) ' Set GPIO 56-63 port as digital output
12   GPIO_Digital_Output(@GPIO_PORT_64_66, _GPIO_PINMASK_ALL) ' Set GPIO 64-66 port as digital output
13 
14   GPIO_PORT_00_07 = 0
15   GPIO_PORT_08_15 = 0
16   GPIO_PORT_16_23 = 0
17   GPIO_PORT_24_31 = 0
18   GPIO_PORT_32_39 = 0
19   GPIO_PORT_40_47 = 0

LED blinking for mikroPascal

mikroPascal PRO for PIC

For this description we have used the EasyPIC7 development board.

  • MCU: PIC18F45K22 from Microchip;
  • Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal.
  • Board settings: Turn ON the PORT LEDs at SW3.
 1  program LED_Blinking;
 2 
 3 begin
 4   TRISA := 0;           // set direction to be output
 5   TRISB := 0;           // set direction to be output
 6   TRISC := 0;           // set direction to be output
 7   TRISD := 0;           // set direction to be output
 8   TRISE := 0;           // set direction to be output
 9 
10   while TRUE do
11     begin
12       LATA := 0x00;     // Turn OFF LEDs on PORTA
13       LATB := 0x00;     // Turn OFF LEDs on PORTB
14       LATC := 0x00;     // Turn OFF LEDs on PORTC
15       LATD := 0x00;     // Turn OFF LEDs on PORTD
16       LATE := 0x00;     // Turn OFF LEDs on PORTE
17       Delay_ms(1000);   // 1 second delay
18 
19       LATA := 0xFF;     // Turn ON LEDs on PORTA
20       LATB := 0xFF;     // Turn ON LEDs on PORTB
21       LATC := 0xFF;     // Turn ON LEDs on PORTC
22       LATD := 0xFF;     // Turn ON LEDs on PORTD
23       LATE := 0xFF;     // Turn ON LEDs on PORTE
24       Delay_ms(1000);   // 1 second delay
25     end;                // Endless loop
26 end.

mikroPascal PRO for dsPIC

For this example we have used the EASYPIC v7 for dsPIC30 development board.

  • MCU: dsPIC30F4013 from Microchip;
  • Oscillator: XT-PLL8, 80.000MHz.
  • Board settings: Turn ON port LEDs at SW10.
 1 program LED_Blinking;
 2 
 3 begin
 4 
 5   ADPCFG := 0xFFFF;       // Configure AN pins as digital I/O
 6   TRISB := 0;             // Initialize PORTB as output
 7   TRISC := 0;             // Initialize PORTC as output
 8   TRISD := 0;             // Initialize PORTD as output
 9   TRISF := 0;             // Initialize PORTF as output
10 
11   LATB := 0;              // Set PORTB to zero
12   LATC := 0;              // Set PORTC to zero
13   LATD := 0;              // Set PORTD to zero
14   LATF := 0;              // Set PORTF to zero
15 
16   while TRUE do
17     begin
18       LATB := not LATB;   // Invert PORTB value
19       LATC := not LATC;   // Invert PORTC value
20       LATD := not LATD;   // Invert PORTD value
21       LATF := not LATF;   // Invert PORTF value
22       Delay_ms(1000);
23     end;
24 end.

mikroPascal PRO for PIC32

For this example we have used the EasyPIC Fusion v7 development board.

  • MCU: P32MX795F512L from Microchip;
  • Oscillator: XT-PLL, 80.0000MHz.
  • Board settings: Turn ON PORTA, B, C, D, F & G LEDS at SW15.
 1 program Led_Blinking;
 2 
 3 begin
 4   AD1PCFG := 0xFFFF;      // Configure AN pins as digital I/O
 5   JTAGEN_bit := 0;        // Disable JTAG
 6 
 7   TRISA := 0;             // Initialize PORTA as output
 8   TRISB := 0;             // Initialize PORTB as output
 9   TRISC := 0;             // Initialize PORTC as output
10   TRISD := 0;             // Initialize PORTD as output
11   TRISF := 0;             // Initialize PORTE as output
12   TRISG := 0;             // Initialize PORTG as output
13 
14   LATA := 0;              // Set PORTA to zero
15   LATB := 0;              // Set PORTB to zero
16   LATC := 0;              // Set PORTC to zero
17   LATD := 0;              // Set PORTD to zero
18   LATF := 0;              // Set PORTE to zero
19   LATG := 0;              // Set PORTG to zero
20 
21   while TRUE do
22   begin
23     LATA := not PORTA;    // Invert PORTA value
24     LATB := not PORTB;    // Invert PORTB value
25     LATC := not PORTC;    // Invert PORTC value
26     LATD := not PORTD;    // Invert PORTD value
27     LATF := not PORTF;    // Invert PORTE value
28     LATG := not PORTG;    // Invert PORTG value
29     Delay_ms(1000);

mikroPascal PRO for ARM

For this example we have used the EasyMx v7 for STM(R) ARM(R) development board.

  • MCU: STM32F107VC;
  • Oscillator: HSE-PLL, 72.000MHz.
  • Board settings: Turn ON PORTA, PORTB, PORTC, PORTD, PORTE at SW15.
 1 program LedBlinking;
 2 { Declarations section }
 3 begin
 4    { Main program }
 5   GPIO_Digital_Output(@GPIOA_BASE, _GPIO_PINMASK_ALL); // Set PORTA as digital output
 6   GPIO_Digital_Output(@GPIOB_BASE, _GPIO_PINMASK_ALL); // Set PORTB as digital output
 7   GPIO_Digital_Output(@GPIOC_BASE, _GPIO_PINMASK_ALL); // Set PORTC as digital output
 8   GPIO_Digital_Output(@GPIOD_BASE, _GPIO_PINMASK_ALL); // Set PORTD as digital output
 9   GPIO_Digital_Output(@GPIOE_BASE, _GPIO_PINMASK_ALL); // Set PORTE as digital output
10 
11   GPIOA_ODR := 0;
12   GPIOB_ODR := 0;
13   GPIOC_ODR := 0;
14   GPIOD_ODR := 0;
15   GPIOE_ODR := 0;
16 
17   while TRUE do
18     begin
19       GPIOA_ODR := not GPIOA_ODR; // Toggle PORTA
20       GPIOB_ODR := not GPIOB_ODR; // Toggle PORTB
21       GPIOC_ODR := not GPIOC_ODR; // Toggle PORTC
22       GPIOD_ODR := not GPIOD_ODR; // Toggle PORTD
23       GPIOE_ODR := not GPIOE_ODR; // Toggle PORTE
24       Delay_ms(1000);
25    end;
26 end.

mikroPascal PRO for AVR

For this example we have used the EasyAVR v7 development board.

  • MCU: ATMEGA32;
  • Oscillator: External Clock 08.0000 MHz.
  • Board settings: Make sure you turn ON the PORTA, PORTB, PORTC and PORTD LEDs (SW10.5, SW10.6, SW10.7 and SW10.8).
 1 program LED_Blinking;
 2   begin
 3     DDRA := 0xFF;             // Set direction to be output
 4     DDRB := 0xFF;             // Set direction to be output
 5     DDRC := 0xFF;             // Set direction to be output
 6     DDRD := 0xFF;             // Set direction to be output
 7 
 8     while TRUE do
 9       begin
10         PORTA := 0x00;        // Turn ON diodes on PORTA
11         PORTB := 0x00;        // Turn ON diodes on PORTB
12         PORTC := 0x00;        // Turn ON diodes on PORTC
13         PORTD := 0x00;        // Turn ON diodes on PORTD
14         Delay_ms(1000);       // 1 second delay
15 
16         PORTA := 0xFF;        // Turn OFF diodes on PORTA
17         PORTB := 0xFF;        // Turn OFF diodes on PORTB
18         PORTC := 0xFF;        // Turn OFF diodes on PORTC
19         PORTD := 0xFF;        // Turn OFF diodes on PORTD
20         Delay_ms(1000);       // 1 second delay
21       end;                    // Endless loop}
22   end.

mikroPascal PRO for 8051

For this example we have used the Easy8051v6 development board.

  • MCU: AT89S8253;
  • Oscillator: External Clock 10.0000 MHz.
  • Board settings: Turn ON the PORT LEDs (SW7). On Easy8051v6 LEDs are activated by logical zero.
 1 program LED_Blinking;
 2   begin
 3     while TRUE do
 4       begin
 5         P0 := 0x00;        // Turn ON diodes on PORT0
 6         P1 := 0x00;        // Turn ON diodes on PORT1
 7         P2 := 0x00;        // Turn ON diodes on PORT2
 8         P3 := 0x00;        // Turn ON diodes on PORT3
 9         
10         Delay_ms(1000);    // 1 second delay
11         
12         P0 := 0xFF;        // Turn OFF diodes on PORT0
13         P1 := 0xFF;        // Turn OFF diodes on PORT1
14         P2 := 0xFF;        // Turn OFF diodes on PORT2
15         P3 := 0xFF;        // Turn OFF diodes on PORT3
16         Delay_ms(1000);    // 1 second delay
17       end;                 // Endless loop
18   end.

mikroPascal PRO for FT90x

For this example we have used the EasyFT90x development board.

  • MCU: FT900 MCU;
  • Oscillator: CPU at full system clock, 100.000MHz.
  • Board settings: Turn ON ports GPIO 00-07, GPIO 08-15, GPIO 16-23, GPIO 24-31, GPIO 32-39, GPIO 40-47, GPIO 48-55 and GPIO 56-66 at SW8.
 1 program LedBlinking;
 2 
 3 begin
 4   GPIO_Digital_Output(@GPIO_PORT_00_07, _GPIO_PINMASK_ALL); // Set GPIO 00-07 port as digital output
 5   GPIO_Digital_Output(@GPIO_PORT_08_15, _GPIO_PINMASK_ALL); // Set GPIO 08-15 port as digital output
 6   GPIO_Digital_Output(@GPIO_PORT_16_23, _GPIO_PINMASK_ALL); // Set GPIO 16-23 port as digital output
 7   GPIO_Digital_Output(@GPIO_PORT_24_31, _GPIO_PINMASK_ALL); // Set GPIO 24-31 port as digital output
 8   GPIO_Digital_Output(@GPIO_PORT_32_39, _GPIO_PINMASK_ALL); // Set GPIO 32-39 port as digital output
 9   GPIO_Digital_Output(@GPIO_PORT_40_47, _GPIO_PINMASK_ALL); // Set GPIO 40-47 port as digital output
10   GPIO_Digital_Output(@GPIO_PORT_48_55, _GPIO_PINMASK_ALL); // Set GPIO 48-55 port as digital output
11   GPIO_Digital_Output(@GPIO_PORT_56_63, _GPIO_PINMASK_ALL); // Set GPIO 56-63 port as digital output
12   GPIO_Digital_Output(@GPIO_PORT_64_66, _GPIO_PINMASK_ALL); // Set GPIO 64-66 port as digital output
13 
14   GPIO_PORT_00_07 := 0;
15   GPIO_PORT_08_15 := 0;
16   GPIO_PORT_16_23 := 0;
17   GPIO_PORT_24_31 := 0;
18   GPIO_PORT_32_39 := 0;
19   GPIO_PORT_40_47 := 0;
20   GPIO_PORT_48_55 := 0;
21   GPIO_PORT_56_63 := 0;
22   GPIO_PORT_64_66 := 0;
23 
24   while (TRUE) do
25   begin
26     GPIO_PORT_00_07 := not(GPIO_PORT_00_07); // togle PORT 00-07
27     GPIO_PORT_08_15 := not(GPIO_PORT_08_15); // togle PORT 08-15
28     GPIO_PORT_16_23 := not(GPIO_PORT_16_23); // togle PORT 16-23
29     GPIO_PORT_24_31 := not(GPIO_PORT_24_31); // togle PORT 24-31
30     GPIO_PORT_32_39 := not(GPIO_PORT_32_39); // togle PORT 32-39
31     GPIO_PORT_40_47 := not(GPIO_PORT_40_47); // togle PORT 40-47
32     GPIO_PORT_48_55 := not(GPIO_PORT_48_55); // togle PORT 48-55
33     GPIO_PORT_56_63 := not(GPIO_PORT_56_63); // togle PORT 56-63
34     GPIO_PORT_64_66 := not(GPIO_PORT_64_66); // togle PORT 64-66
35     Delay_ms(1000);
36   end;
37 end.


Previous page: Creating Your First Project

Resources