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.

Multiplexing 7-Digits?

Status
Not open for further replies.
Hey there!

I got the routines and the small 0-99 counter for that microcon, but I can't seem to get 2 displays working at the same time.

I tried putting the "displaying two displays" at the interrupt section, and I got stuck. Here's the code:

Code:
#include <htc.h>

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT 
& BORDIS & LVPDIS);
                //0b0gfedcba 
char numbers[] = {0b00111111, // 0
    0b00000110, // 1
    0b01011011, // 2
    0b01001111, // 3
    0b01100110, // 4
    0b01101101, // 5
    0b01111101, // 6
    0b00000111, // 7
    0b01111111, // 8
    0b01101111, // 9
};

int i, j, k;
int counter;
int ones = 0;
int tens = 0;

void interrupt tmrlint(void)
{
    if(TMR1IF)
    {
        TMR1IF = 0; //got stuck over there!
        
        
};
    
void main()
{
    TRISA = 0x00;
    TRISB = 0x00;
    
    PORTA = 0b0000010;
    PORTB = 0x00;
    
    PEIE = 1;
    GIE = 1;
    TMR1IE = 1;
    T1CON = 0b00110101;
    
    while(1)
    {
        ones++;
        if (ones > 9)
        {
            tens++;
            ones = 0;
        }            
    }    
}

what could i have been missing? :confused:
 
I dont see anywhere in your code the actual multiplexing, perhaps you do not understand. You must switch between the two faster than the eye can see (24Hz)..about 50Hz will show no blinking. You display one digit and then the other back and forth. If you want this to be visible counting your going to need to use a delay. Why are you using a timer 1 interrupt? Lastly GIE (global interrupt enable) Should be the last bit enabled.

Code:
    PEIE = 1;
    GIE = 1;
    TMR1IE = 1;
    T1CON = 0b00110101;

should be
Code:
    PEIE = 1;
    TMR1IE = 1;
    T1CON = 0b00110101  
    GIE = 1;

Please explain what you are trying to do more.

Mike
 
I dont see anywhere in your code the actual multiplexing, perhaps you do not understand. You must switch between the two faster than the eye can see (24Hz)..about 50Hz will show no blinking. You display one digit and then the other back and forth. If you want this to be visible counting your going to need to use a delay. Why are you using a timer 1 interrupt? Lastly GIE (global interrupt enable) Should be the last bit enabled.

Code:
    PEIE = 1;
    GIE = 1;
    TMR1IE = 1;
    T1CON = 0b00110101;
should be
Code:
    PEIE = 1;
    TMR1IE = 1;
    T1CON = 0b00110101  
    GIE = 1;
Please explain what you are trying to do more.

Mike

Oh sorry for the confusion - I'm attempting to multiplex, and I formed the flow-chart. I know it's these 2 displays which go back and forth very quickly, and i need to implement it into the interrupt, but I kinda got stuck here. I might crack some more head of myself first, and post the code later. :rolleyes:
 
Ah i see
well youll want to do something like

Code:
void interrupt tmrlint(void)
{
   Goto ISR      ; Interrupt service routine         
};


ISR
{
     TMR1IF = 0
     PORTB pin x = PORTB pin x ^1   ;<--- not sure how to write in C
     PORTB pin y = PORTB pin y ^1   ;<--- just invert the pins and they  
                                                 ;      will swap
     RETFIE   <--- asm instruction not sure about C

You will still need to work out a delay though, this could be a problem since you are getting an interrupt VERY often.

BTW which uC???

Hope this helps,
Mike
 
Ah i see
well youll want to do something like

Code:
void interrupt tmrlint(void)
{
   Goto ISR      ; Interrupt service routine         
};


ISR
{
     TMR1IF = 0
     PORTB pin x = PORTB pin x ^1   ;<--- not sure how to write in C
     PORTB pin y = PORTB pin y ^1   ;<--- just invert the pins and they  
                                                 ;      will swap
     RETFIE   <--- asm instruction not sure about C
You will still need to work out a delay though, this could be a problem since you are getting an interrupt VERY often.

BTW which uC???

Hope this helps,
Mike

My microcontroller is PIC 16F682A, as recommended by Nigel GoodWin. :D

How about using a task counter? Like task_count++, then wait for it to reach the max intended task count and then exit the interrupt? :)
 
I'll asume you meant 628a*

I don't see why you would want to complicate things, why use the interrupt at all?
And actually I believe that while your trying to do the "task count" the interrupt would be triggered all over again...huge mess.

Mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top