I am doing this simple project to display some message on 2x 7 segment LED. But before I did that I decided to use a pic16f88 to display some counting values from 00 to FF in Hex. Once that works I'd continue to modify it to display text.
The schematic looks as follows:
The software is attached below
The problem is that the contents of both digits are the same all the time. It was supposed to display HEX from "00" to "FF"
Any idea what's wrong with the program?
Allen
The schematic looks as follows:
The software is attached below
C:
#include <pic.h>
/* c2x7seg.c
roll through 16 digit on a dual 7 segment LED display
Display HEX 16 digits on 2x CA LED display.
RB6 - seg a
RB5 - seg b
RB4 - seg c
RB3 - seg d
RB2 - seg e
RB1 - seg f
RB0 - seg g
RA0 - Right 7 seg disp
RA1 - Left 7 seg disp
*/
__CONFIG (WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & CCPRB3 & LVPDIS);
//LVPDIS is needed so that RB3 will not be used by Low voltage programming to use it as I/O
//pin and also be used by CCP1 control.**
//see CONFIG word on datasheet.
unsigned int i,j;
unsigned int disp_value, disp_LED;
const char LEDdigit []=
{
//abcdefg - LED segments
0b0000001, //0
0b1001111, //1
0b0010010, //2
0b0000110, //3
0b1001100, //4
0b0100100, //5
0b0100000, //6
0b0001111, //7
0b0000000, //8
0b0000100, //9
0b0001000, //"A"
0b1100000, //"b"
0b0110001, //"C"
0b1000010, //"d"
0b0110000, //"E"
0b0111000}; //"F"
void main()
{
PORTA=0;
PORTB=0;
CMCON=7; //TURN OFF COMPARATOR
CCP1CON=0; //disable CCP1 functions ON RB0 & RB3
ANSEL=0; //TURN OFF ADC
TRISA=0b111110;
TRISB=0b00000000;
disp_value = 0x00; //start disp at 0x00
disp_LED = 0; //disp the first digit
while (1==1)
{
if (disp_LED == 0)
{
PORTB=LEDdigit[disp_value & 0x0F] & 0x7F;
}
else
{
PORTB=LEDdigit[(disp_value >> 4) & 0x0F] & 0x7F;
} //fi
TRISA = TRISA ^ 0b000011; //XOR RA0 and RA1
PORTA = PORTA & 0b111100;
disp_LED = disp_LED ^ 1; //alternate btw first and second digit
NOP(); // subroutine for 10 ms delay
for (i=0; i<660; i++); //10ms delay
NOP();
j=j+1;
if (25 == j) //display for 25 times
{
disp_value++; //increment display value
j = 0;
} //fi
} //end while
} //end c2x7seg
Any idea what's wrong with the program?
Allen