Skip to content

Instantly share code, notes, and snippets.

@mattrude
Last active February 6, 2022 18:28
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 mattrude/0c8cc85a6b8ddbf96005cfd3637b33fb to your computer and use it in GitHub Desktop.
Save mattrude/0c8cc85a6b8ddbf96005cfd3637b33fb to your computer and use it in GitHub Desktop.
PIC16F877A - Knight Rider scanner bar
/*
* File: KnightRider.c
* Author: Matt Rude <matt@mattrude.com>
*
* Created on February 4, 2022, 6:33 PM
*/
#define _XTAL_FREQ 4000000
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = ON
#pragma config LVP = ON
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
TRISD0 = 0; // RB0 as Output PIN
TRISD1 = 0; // RB1 as Output PIN
TRISD2 = 0; // RB2 as Output PIN
TRISD3 = 0; // RB3 as Output PIN
TRISD4 = 0; // RB4 as Output PIN
TRISD5 = 0; // RB5 as Output PIN
TRISD6 = 0; // RB6 as Output PIN
TRISD7 = 0; // RB7 as Output PIN
RD0 = 1; // LED OFF
RD1 = 1; // LED OFF
RD2 = 1; // LED OFF
RD3 = 1; // LED OFF
RD4 = 1; // LED OFF
RD5 = 1; // LED OFF
RD6 = 1; // LED OFF
RD7 = 1; // LED OFF
while(1){
RD0 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD0 = 1; // LED OFF
RD1 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD1 = 1; // LED OFF
RD2 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD2 = 1; // LED OFF
RD3 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD3 = 1; // LED OFF
RD4 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD4 = 1; // LED OFF
RD5 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD5 = 1; // LED OFF
RD6 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD6 = 1; // LED OFF
RD7 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD7 = 1; // LED OFF
RD6 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD6 = 1; // LED OFF
RD5 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD5 = 1; // LED OFF
RD4 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD4 = 1; // LED OFF
RD3 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD3 = 1; // LED OFF
RD2 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD2 = 1; // LED OFF
RD1 = 0; // LED ON
__delay_ms(500); // 1 Second Delay
RD1 = 1; // LED OFF
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment