Skip to content

Instantly share code, notes, and snippets.

@dilshan
Created July 5, 2020 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dilshan/34286710d0363b40d5649748c12d0681 to your computer and use it in GitHub Desktop.
Save dilshan/34286710d0363b40d5649748c12d0681 to your computer and use it in GitHub Desktop.
XC8 source code to test on μSim simulator (with Arduino Uno).
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment