unsigned char mode;
char select = 0, Digitt1, Digitt2, Digitt3, Digitt4;
unsigned char common_cathode_mask[21] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x73, 0x50, 0x5C, 0x37, 0x40};
// 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,A ,b ,C ,d ,E ,F ,P ,r ,o ,N ,-
//char digit[2];
char digit[4];
//Timer1
//Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 2 ms
//Place/Copy this part in declaration section
void InitTimer1() {
//T1CON = 0x01;
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xF8;
TMR1L = 0x30;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void machoff() {
Digitt1 = 20;
Digitt2 = 20;
Digitt3 = 20;
Digitt4 = 20;
}
void dispFunction() {
digit[0] = common_cathode_mask[Digitt1];
digit[1] = common_cathode_mask[Digitt2];
digit[2] = common_cathode_mask[Digitt3];
digit[3] = common_cathode_mask[Digitt4];
switch(select) {
case 0:
PORTC = digit[0];
PORTD = 0x01;
break;
case 1:
PORTC = digit[1];
PORTD = 0x02;
break;
case 2:
PORTC = digit[2];
PORTD = 0x04;
break;
case 3:
PORTC = digit[3];
PORTD = 0x08;
break;
};
}
void Dopen() {
Digitt1 = 0;
Digitt2 = 16;
Digitt3 = 14;
Digitt4 = 19;
PORTB.RB5 = 1;
dispFunction();
}
void Pro1() {
mode = 1;
Digitt1 = 16;
Digitt2 = 17;
Digitt3 = 18;
Digitt4 = 1;
dispFunction();
}
void Pro2() {
mode = 2;
Digitt1 = 16;
Digitt2 = 17;
Digitt3 = 18;
Digitt4 = 2;
dispFunction();
}
void Pro3() {
mode = 3;
Digitt1 = 16;
Digitt2 = 17;
Digitt3 = 18;
Digitt4 = 3;
dispFunction();
}
void Pro4() {
mode = 4;
Digitt1 = 16;
Digitt2 = 17;
Digitt3 = 18;
Digitt4 = 4;
dispFunction();
}
void ProSelect() {
if(mode == 1) {
Pro1();
}
if(mode == 2) {
Pro2();
}
if(mode == 3) {
Pro3();
}
if(mode == 4) {
Pro4();
}
}
void Interrupt(){
if(TMR1IF_bit) {
TMR1H = 0xF8;
TMR1L = 0x30;
PORTD = 0x00;
}
// dispFunction();
if(PORTB.B0 == 1) Dopen();
else if(PORTB.B0 == 0){
mode = 3; //
ProSelect();
}
TMR1IF_bit = 0;
if(++select == 4)select = 0;
}
void main() {
CMCON = 0x07;
ADCON1 = 0x87;
TRISA = 0x00;
TRISB = 0xFF;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
// mode = 3;
InitTimer1();
}
FvM wrote:did i understand it right all of my work must be in the interrupt routine ?
Avoid any unnecessary, particularly time consuming code in the interrupt
thx Klaus i'll try to move the display function to main loopHi,
FvM wrote:
My recommendation:
The ISR must be short in time.
Therefore just update all necessary variables and set a flag..to show that new data is available.
But the processing of the data (display) should be done in main loop.
Klaus
how do i change between functions with push button?
You aren't incrementing variable "mode" anywhere.
When an interrupt takes place, the microprocessor automatically goes to a isr.
in your case, the interrupt is caused timer counter over/underflow and you set a flag within the isr (service routine) timer_interrupt=1 if timer_interrupt=0 else timer_interrupt=2;
you return from the isr and process outside, if timer_interrupt==1, the work to be done you wanted on this interrupt. And you also reset the timer_interrupt=0;
If you find timer_interrupt==2, it means that another interrupt has taken place before you could process the first one. It should not happen.
void Interrupt(){
if(TMR1IF_bit) {
TMR1H = 0xF8;
TMR1L = 0x30;
PORTD = 0x00;
}
if(PORTB.B0 == 1) Dopen();
if(PORTB.B4 == 0){
mode = 3; //
ProSelect();
}
TMR1IF_bit = 0;
if(++select == 4)select = 0;
}
void Pro3() {
do {
mode = 3;
Digitt1 = 16;
Digitt2 = 17;
Digitt3 = 18;
Digitt4 = 3;
dispFunction();
}while(1);
}
The setup of the interrupt function is not correct. (the function starting with void interrupt...) I have not done much work with PIC and I have to read...
Your codes are not having any comments. What you are trying to do?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?