To start with I am writing a program which increases or decreases the number displayed on multiplexed 7segement displays. I am using real pic simulator for testing. The connections shall be seen from the attached screenshot of the real pic simulator. on the 7 segment displays only 8 or 6 is seen on successive pushes on push button connected to porta1 and port a2. Please tell me where i am going wrong. Following is the c code
int j;
unsigned char seg[10]={0x80,0xf2,0x48,0x60,0x32,0x24,0x04,0xF0,0x00,0x30}; //unsigned char *ptr[10][8],seg[10][8]={{1,0,0,0,0,0,0,0,0},{1,1,1,0,0,1,0,0},{1,0,0,1,0,0,0,0},{1,1,0,0,0,0,0,0},{0,1,1,0,0,1,0,0},{0,1,0,0,1,0,0,0},{0,0,0,0,1,0,00},{,1,1,1,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,1,1,0,0,0,0}};//array for pushing numbers into 7segment display from 0 to 1
void display(int);
void main()
{
int i=0,k=0;
TRISA = 0xE7 ; // set PORTA pins 3,4 as output and others as INPUT
TRISC = 0x01 ; // set PORTB as OUTPUT except pin0
TRISB = 0xE1 ; // set PORTB pins 1,2,3,4 as OUTPUT others input
while(1) // forever
{
display(i);
if( PORTA.f2 == 1)
{
if (i<99) i++;
else i=0;
display(i);
}
else if (PORTA.f1 == 1)
{
if (i>0) i--;
else i=99;
display(i);
}
k++;
}
}
void display(int l)
{
PORTA.f4 = 0;
PORTA.f3 = 1;
j=l%10;
PORTC = j;
delay_ms(1);
PORTA.f3 = 0;
PORTA.f4 = 1;
j=l/10;
PORTC = j;
return;
}