Dilshan Jayakody
Published © Apache-2.0

Run PICmicro Instructions on Arduino

A lightweight simulator to run programs compiled for PICmicro on Arduino.

IntermediateFull instructions provided3 hours2,167
Run PICmicro Instructions on Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Micro SD TF Card Adapter Module
×1
5 mm LED: Red
5 mm LED: Red
×6
Resistor 330 ohm
Resistor 330 ohm
×6
Flash Memory Card, MicroSD Card
Flash Memory Card, MicroSD Card
×1

Software apps and online services

MPLAB X IDE
Microchip MPLAB X IDE
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic related to the test application.

Code

μSim test application

C/C++
Test application to compile with Microchip XC8 compiler.
#include <xc.h>
#include <stdint.h>

// This is not an accurate frequency. The exact value may depend on the 
// specifications of the hosting platform.
#define _XTAL_FREQ 25000

void main(void) 
{    
    uint8_t position = 2;
    uint8_t direction = 1;
    
    // In Uno board PORTB[0] and PORTB[1] are used by UART.
    TRISB = 0x03;
    PORTB = 0x00;
            
    while(1)
    {                
        if(direction)
        {
            // Move LEDs in upward direction.
            position = position << 1;
        }
        else
        {
            // Move LEDs in downward direction.
            position = position >> 1;
        }
        
        PORTB = position;
        __delay_ms(250);
        
        // Direction changing.
        if(position <= 4)
        {
            direction = 1;
        }
        
        if(position >= 127)
        {
            direction = 0;
        }
    }
    
    return;
}

Credits

Dilshan Jayakody

Dilshan Jayakody

27 projects • 33 followers
Hello, I'm an embedded systems engineer, amateur radio operator and amateur astronomer.

Comments