Created
July 5, 2020 00:45
-
-
Save dilshan/34286710d0363b40d5649748c12d0681 to your computer and use it in GitHub Desktop.
XC8 source code to test on μSim simulator (with Arduino Uno).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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