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.
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.
Code:
unsigned char seg[10]={0x80,0xf2,0x48,0x60,0x32,0x24,0x04,0xF0,0x00,0x30}; // this is a common anode display and pins 1-7 of PORTC are connected to A-G of 7 segment display
unsigned short i, DD0=0x80,DD1=0x80;
unsigned int tc,k=0,t1c;
void display_temp() //displaying number in tc for 100 ms
{
for (i=0;i<1;i++)
{
TMR1IE_bit=1; //enabling timer 1 interrupt
while(!TMR1IF_bit )
{
PORTC = seg[DD0];
PORTA.f3= 1; // Select Ones Digit. RA3 is connected to seven segement display on the right
PORTA.f4= 0; // RA4 is connected to seven segement display on the left
delay_ms(1); // wait for 1 ms
PORTC = seg[DD1];
PORTA.f3= 0;
PORTA.f4= 1; // Select Tens Digit
delay_ms(1); // wait for 1 ms
if(PORTA.f1 == 1 || PORTA.f2 == 1) //if there is any input from RA1 or RA2 break from loop
{
TMR1IE_bit=0; // timer 1 interrupt is disabled
TMR1IF_bit=0; // timer 1 interrupt flag is cleared
break;
}
}
TMR1H=0x9E; // initialization of timer1 for 100 ms count
TMR1L=0x58;
TMR1IE_bit=0; // timer 1 interrupt is disabled
TMR1IF_bit=0; // timer 1 interrupt flag is cleared
if(PORTA.f1 == 1 || PORTA.f2 == 1) //if there is any input from RA1 or RA2 break from loop
break;
}
return;
}
void main()
{
int tc=0,count=0,set=0, t1,t1c=0;
GIE_bit=1;
TRISA=0xE7; // Set PORTA pins 3 and 4 as output and others as input
TRISC=0x01; // set PORTC as OUTPUT except pin0
PORTA=0x00; // initialize port A
PORTC=0x80; // initialize port C
ANSEL=0x00; // set all ports digital
ANSELH=0x00;
T1CON=0x01; // tmr1on bit is set
TMR1H=0x9E; // initialization of timer1 for 100 ms count
TMR1L=0x58;
display_temp(); // calling display_temp function to display DD0 and DD1 on segment on right and left respectively
while(1) // man program starts here
{
if(PORTA.f2==1) // checking if decrease push to on button connected to portA pin 2 is pressed
{
if(tc==0) tc=67;
else tc--;
}
if(PORTA.f1==1) // checking if increase push to on button connected to portA pin 1 is pressed
{
if(tc==67) tc=0;
else tc++;
}
DD0 = tc%10; // digit in 1's position of tc is read to DD0
DD1 = tc/10; // digit in 10's position of tc is read to DD1
display_temp();
TMR1IE_bit=0; // timer 1 interrupt is disabled
TMR1IF_bit=0; // timer 1 interrupt flag is cleared
}
}
Last edited: