---
title: Basic Setup
slug: basic-setup
docTags: 
createdAt: 2023-07-21T13:30:12.290Z
---

For more information about the PIC16F18875 | PIC16F18877

In the code sample below, the device is set up to use PORTB and PORTE to flash an LED. This is a simple project and is often used as a "heartbeat" to ensure that the device is working.

:::hint{type="info"}
The code sample below is written in Mikro C, available from Mikroe.
:::

## main ()

The code is initiated by first setting up the device and then going into a continual loop flashing the designated pin.

## setup\_Device()

The device setup does the following:

- The analogs for each port are disabled, as we will be using them as digital I/O.
- All the pins are set to input&#x20;
- Ony the designated pins are set for outputs
- Comparators are also disabled&#x20;

## flash\_Pin()

The pin on PORT# Bit 0 is toggled once every 500ms

## Code Sample

The sample described above is listed below. Use the copy function to extract the code for use.

```c
/*
        Test code for PIC16F18877
*/

void setup_Device();
void flash_Pin();

void flash_Pin(){

     LATB.B0 = ~LATB.B0;
     Delay_MS(500);
     
     LATE.B0 = ~LATE.B0;
     Delay_MS(500);

}

void setup_Device(){

     // Switch Off Analogs
     ANSELA = 0x00;
     ANSELB = 0x00;
     ANSELC = 0x00;
     ANSELD = 0x00;
     ANSELE = 0X00;
     
     //
     TRISB = 0b11111110;
     TRISE = 0b11111110;

    // Comparators
    C1ON_bit = 0;               // Disable comparators
    C2ON_bit = 0;

}

void main() {

     setup_Device();

     while(1){

              flash_Pin(); // flash the LED

     }
}
```

## Parts List

To complete this project the following is needed:

- Radix Duo (with PIC16F18875 | PIC16F18877) + Radix Shield

Alternatively, you may use the following

- Radix Duo (with PIC16F18875 | PIC16F18877)
- 820 Ohm Resistor
- 3  or 5 mm LED

\[END]

