I'm trying to control a 7 segment display using PIC16F877A. I'm programming my PIC with a replica PICKIT 3.
I'm uploading my hex code using PICKIT 3 software and MPLABX IDE. I have no problem while I'm uploading my code, only when I set up my circuit.
I noticed only B1 pin is working. I did a blink LED circuit and I still get B1 pin high when I set D0 pin to high. I'm using 4 MHz crystal and 0.1 uF capacitors. I uploaded hex files from internet too, but I'm always getting high from B1.
I'm using 4MHZ Crystal with 0.1 uF capacitors. Should I change capacitors with 15 pF?
My Code:
#include <16F887.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4m,oscillator)
#define Dig1 PIN_D0
#define Dig2 PIN_D1
#define rfid PIN_D2
#define reset PIN_A1
#use fast_io(b)
#use fast_io(d)
static const int digit[10]= { 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };
void display(unsigned char value)
{
static char tens = 0;
char dig = (tens) ? (value / 10) : (value % 10);
dig = digit[dig];
output_high((tens) ? Dig2 : Dig1);
output_b(dig);
output_low((tens) ? Dig1 : Dig2);
tens = !tens;
}
void main()
{
char sayi = 0;
output_b(1);
output_d(0b11111100);
output_b(0b11111100);
set_tris_b(0x00);
set_tris_d(0b11111100);
while(1)
{
display(sayi);
if(input(rfid) == 0)
{
sayi++;
if(sayi == 100)
{
sayi = 0;
}
}
delay_ms(30);
}
}
My Schematic:
PIC16F877A Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf
Real Life Circuit: