Hi
To start with I have written a program using mikroC, for pic16f882 using 4 MHz external crystal oscillator, to increase and decrease a number based on input from RA1/RA2 and display on multiplexed 7 segment display. 1s position is controlled by RA3 and 10s position is controlled by RA4. It is a common cathode. I am usin real pic simulator for simulation. The sequence is not followed while increase or decrease operations and both the digits are showing the same value. Following is the program. Shall someone help me on this.
unsigned char seg[10]={0x80,0xf2,0x48,0x60,0x32,0x24,0x04,0xF0,0x00,0x30};
unsigned short i, DD0=0x80,DD1=0x80;
unsigned int tc,k=0,t1c;
void display_temp(short DD0, short DD1)
{
for (i=0;i<1;i++)
{
TMR1IE_bit=1;
while(!TMR1IF_bit )
{
PORTC = seg[DD0];
PORTA.f3= 1; // Select Ones Digit
PORTA.f4= 0;
delay_ms(1);
PORTC = seg[DD1];
PORTA.f3= 0;
PORTA.f4= 1; // Select Tens Digit
delay_ms(1);
if(PORTA.f0==1 || PORTA.f1 == 1 || PORTA.f2 == 1)
{
TMR1IE_bit=0;
TMR1IF_bit=0;
break;
}
}
TMR1H=0x9E; //begin with 0
TMR1L=0x58;
TMR1IE_bit=0;
TMR1IF_bit=0;
if(PORTA.f0==1 || PORTA.f1 == 1 || PORTA.f2 == 1)
break;
}
return;
}
void main()
{
int tc=0,count=0,set=0, t1,t1c=0;
GIE_bit=1;
TRISA=0xE7; // Set PORTA
TRISC=0x01; // set PORTC as OUTPUT except pin0
PORTA=0x00;
PORTC=0x80;
ANSEL=0x00;
ANSELH=0x00;
T1CON=0x01; //tmr1on bit is set
TMR1H=0x9E; //begin with 0
TMR1L=0x58;
while(1)
{
if(PORTA.f2==1)
{
if(tc==0) tc=67;
else tc--;
}
if(PORTA.f1==1)
{
if(tc==67) tc=0;
else tc++;
}
DD0 = tc%10;
DD1 = tc/10;
display_temp(DD0,DD1);
TMR1IE_bit=0;
TMR1IF_bit=0;
}
}