Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

interrupt programming doubt

Status
Not open for further replies.
Code:
#include   <pic.h>



	
void main(void)
{

	int tmp;
	TRISB   = 0b00000000;
	RBPU = 0;      // Use internal pullups
	T0IE = 1;      // Enable interrupt on TMR0 overflow
	INTEDG = 1;      // falling edge trigger the interrupt
	INTE = 1;      // enable the external interrupt
   	GIE = 1;      // Global interrupt enable
	tmp=1;
   	for(;;)
{
      	CLRWDT();   // Idly kick the dog
   }
}

	static void interrupt
	isr(void)         // Here be interrupt function - the name is unimportant.
{
   if(T0IF==1) 
{
	if(tmp==1)
{  
	PORTD=map[i];
	RB3=1;
	T0IF=0;
}
else if(tmp==2)
{  
	PORTD=map[i];
	RB3=0;
	RB2=1;
	T0IF=0;
}

else if(tmp==4)
{  
	PORTD=map[i];
	RB2=0;
	RB1=1;
	T0IF=0;

}

else if(tmp==8)
{  
	PORTD=map[i];
	RB1=0;
	RB0,1;
	T0IF=0;
}
tmp=0;
tmp=1;
}
}

//*************************************************************


here i am trying do make a multiplexed display in intrpt.but while compling i am getting somany error.i dont knw to use intrpt an d i dont whethr the program is correct or not.
 
Last edited:
This will now compile without errors but it doesn't make much sense.
Code:
#include   <pic.h>

int tmp;        //was local to main
char map[4];    //wasn't defined
char i;         //ditto
	
void main(void)
{

	TRISB   = 0b00000000;
	RBPU = 0;      // Use internal pullups
	T0IE = 1;      // Enable interrupt on TMR0 overflow
	INTEDG = 1;      // falling edge trigger the interrupt
	INTE = 1;      // enable the external interrupt
   	GIE = 1;      // Global interrupt enable
	tmp=1;
   	for(;;){
      	CLRWDT();   // Idly kick the dog
    }
}

static void interrupt
isr(void)         // Here be interrupt function - the name is unimportant.
{
    if(T0IF==1) 
    {
	    if(tmp==1)
        {  
    	    PORTD=map[i];
        	RB3=1;
    	    T0IF=0;
            }
        else if(tmp==2)
        {  
    	    PORTD=map[i];
    	    RB3=0;
    	    RB2=1;
    	    T0IF=0;
            }
    
        else if(tmp==4)
        {  
         	PORTD=map[i];
          	RB2=0;
           	RB1=1;
           	T0IF=0;
            
        }
    
        else if(tmp==8)
        {  
        	PORTD=map[i];
        	RB1=0;
        	RB0,1;
        	T0IF=0;
        }
        tmp=0;
        tmp=1;
    }
}

Mike.
 
That depends on the hardware. It looks like you need to get a better understanding of how the software should work with the hardware.

Mike.
 
this is my kit manual.but i dont get u about the intialization of map[] and i.how they related to my hardware?
 

Attachments

  • arrangedMicromas&#116.pdf
    248.3 KB · Views: 252
Last edited:
I have been working with Jimmy. The map[] array maps each of the digits 0..9 to PORTD bits needed to turn on the 7 segment segments A..G. PORT RB is used to drive transistors connected to the common cathode of each digit.

He was close to having this working when he added the interrupt.

Jimmy knows ASM but has great difficulty with C.
 
I had a bit of spare time today and had a play with this. I think the following should display 1234 on the display.
Code:
#include   <pic.h>

int tmp;       
char i[4]={1,2,3,4};         

const char map[10]={
    0x3f,0x06,0x5b,0x4f,0x66,
    0x6d,0x7d,0x07,0x7f,0x67};	

void main(void)
{
    OPTION=0b01000110;  //prescaler 128
    TRISB=0b00000000;
    TRISD=0b00000000;   //port D output
    T0IE = 1;       // Enable interrupt on TMR0 overflow
    tmp=1;
    GIE = 1;        // Global interrupt enable
    while(1){       //loop forever
        CLRWDT();   // Idly kick the dog
    }
}

static void interrupt
isr(void)         // Here be interrupt function - the name is unimportant.
{
    if(T0IF==1) 
    {
        PORTB&=0xf0;        //turn off all segments
        T0IF=0;             //clear interrupt
        if(tmp==1)          //first digit
        {  
            PORTD=map[i[0]];//put segment pattern on port D
            RB0=1;          //and turn on display 1
        }
        else if(tmp==2)
        {  
            PORTD=map[i[1]];
            RB1=1;
        }
    
        else if(tmp==3)
        {  
            PORTD=map[i[2]];
            RB2=1;
        }
        else if(tmp==4)
        {  
            PORTD=map[i[3]];
            RB3,1;
        }
        tmp++;          //change to next digit
        if(tmp==5)      //done last digit
            tmp=1;      //yes so start again
    }
}

To change the digits on the display you would do i[digitnumber]=digit. So, i[2]=7; would set the third digit to 7.

Note, this is untried as I don't have the hardware but it's fairly simple to follow.

Mike.
 
Last edited:
When you change from digit to digit, turn off the common pin on the previous digit. If you do not you can get unwanted segments illuminated. I call this ghosting but it may not be the correct use of the term

turn off all common
select segments
select common
...
turn off all common
select segments
select common
....
 
If it's still flickering then reduce the prescaler even lower. I can't see any reason why the 4 wouldn't show up, check all the jumpers are correct on the board.

Mike.
 
When you change from digit to digit, turn off the common pin on the previous digit. ....

I turned of all digits at the beginning of the ISR.
Code:
static void interrupt
isr(void)         // Here be interrupt function - the name is unimportant.
{
    if(T0IF==1) 
    {
        [COLOR="red"]PORTB&=0xf0;[/COLOR]        //turn off all segments
        T0IF=0;             //clear interrupt
        if(tmp==1)          //first digit
        {
Mike.
 
When you change from digit to digit, turn off the common pin on the previous digit. If you do not you can get unwanted segments illuminated. I call this ghosting but it may not be the correct use of the term

turn off all common
select segments
select common
...
turn off all common
select segments
select common
....



Code:
#include   <pic.h>

int tmp;       
char i[4]={1,2,3,4};         

const char map[10]={
    0x3f,0x06,0x5b,0x4f,0x66,
    0x6d,0x7d,0x07,0x7f,0x67};	

void main(void)
{
    OPTION=0b01000110;  //prescaler 128
    TRISB=0b00000000;
    TRISD=0b00000000;   //port D output
	TRISC=0x00;
	RC0=0;
	
    T0IE = 1;       // Enable interrupt on TMR0 overflow
    tmp=1;
    GIE = 1;        // Global interrupt enable
    while(1){       //loop forever
        CLRWDT();   // Idly kick the dog
    }
}

static void interrupt
isr(void)         // Here be interrupt function - the name is unimportant.
{
    if(T0IF==1) 
    {
        PORTB&=0xf0;        //turn off all segments
        T0IF=0;             //clear interrupt
        if(tmp==1)          //first digit
        {  
            PORTD=map[i[0]];//put segment pattern on port D
			PORTB=0x00;
            RB0=1;          //and turn on display 1
        }
        else if(tmp==2)
        {  
            PORTD=map[i[1]];
			PORTB=0x00;
            RB1=1;
        }
    
        else if(tmp==3)
        {  
            PORTD=map[i[2]];
			PORTB=0x00;
            RB2=1;
        }
        else if(tmp==4)
        {  
            PORTD=map[i[3]];
			PORTB=0x00;
            RB3,1;

        }
        tmp++;          //change to next digit
        if(tmp==5)      //done last digit
			PORTB=0x00;
            tmp=1;      //yes so start again
    }
}



but only 1 is displaying rest all othrs are in off condition
 
Last edited:
I was not suggesting there was a problem with your code. Just trying to help Jimmy understand what needs to happen. But given that you have written the code for him I will step back and shut up. :)





#include <pic.h>

int tmp;
char i[4]={1,2,3,4};

const char map[10]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x67};

void main(void)
{
OPTION=0b01000110; //prescaler 128
TRISB=0b00000000;
TRISD=0b00000000; //port D output
TRISC=0x00;
RC0=0;

T0IE = 1; // Enable interrupt on TMR0 overflow
tmp=1;
GIE = 1; // Global interrupt enable
while(1){ //loop forever
CLRWDT(); // Idly kick the dog
}
}

static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF==1)
{
PORTB&=0xf0; //turn off all segments
T0IF=0; //clear interrupt
if(tmp==1) //first digit
{
PORTD=map[i[0]];//put segment pattern on port D
PORTB=0x00;
RB0=1; //and turn on display 1
}
else if(tmp==2)
{
PORTD=map[i[1]];
PORTB=0x00;
RB1=1;
}

else if(tmp==3)
{
PORTD=map[i[2]];
PORTB=0x00;
RB2=1;
}
else if(tmp==4)
{
PORTD=map[i[3]];
PORTB=0x00;
RB3=1;

}
tmp++; //change to next digit
if(tmp==5) //done last digit
PORTB=0x00;
tmp=1; //yes so start again
}
}




now it is working......
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top