Ragnar22
Member level 1
Hi guys!! ( this is my first post here )
Before I start I have to say that I am new at programming PIC MCU and I am really annoyed with something, at multiplexing a theorically simple 4 digits 7seg display (common anode) when I simulate in ISIS PROTEUS it goes and runs perfectly but when I put it in breadboard testing the digits are all messed up like the photo demonstrates. Anyone knows wich are the common causes for this type of error?
NOTE: most important comments are in english but some are in portuguese so dont mind those
Before I start I have to say that I am new at programming PIC MCU and I am really annoyed with something, at multiplexing a theorically simple 4 digits 7seg display (common anode) when I simulate in ISIS PROTEUS it goes and runs perfectly but when I put it in breadboard testing the digits are all messed up like the photo demonstrates. Anyone knows wich are the common causes for this type of error?
NOTE: most important comments are in english but some are in portuguese so dont mind those
Code:
// --- Hardware ---
#define digito_minutos1 RA3_bit
#define digito_minutos2 RA2_bit
#define digito_horas1 RA1_bit
#define digito_horas2 RA0_bit
int display(int num); //Exibe o valor correspondente no display de catodo comum
// --- Variávei Globais ---
int tempo = 0x00; //Inicializa contador
int control = 1; //Variável de controle (para saber qual display está ativo)
int segundos, minutos1,horas1,minutos2,horas2 = 0;
// --- Rotina de Interrupção ---
void interrupt()
{
if(T0IF_bit) //Houve o estouro do TMR0?
{
T0IF_bit = 0x00; //Sim, limpa a flag
TMR0= 6;
tempo++;
if(/*digito_horas2 &&*/ control==1){
control = 2;
digito_minutos2 = 1 ;
digito_horas1 = 1 ;
digito_minutos1 = 1;
PORTB = 0b11111111; //LIMPA PORTB
digito_horas2 = 0;
PORTB = display(horas2);
}else if(/*digito_horas1 &&*/ control==2){
control = 3;
digito_minutos2 = 1;
digito_minutos1 = 1 ;
digito_horas2 = 1;
PORTB = 0b11111111; //LIMPA PORTB
digito_horas1 = 0;
PORTB = display(horas1);
}else if(/*digito_minutos2 &&*/ control==3){
control = 4;
digito_minutos1 = 1 ;
digito_horas1 = 1 ;
digito_horas2 = 1;
PORTB = 0b11111111; //LIMPA PORTB
digito_minutos2 = 0;
PORTB = display(minutos2);
}else if(/*digito_minutos1 &&*/ control == 4){
control = 1;
digito_minutos2 = 1 ;
digito_horas1 = 1 ;
digito_horas2 = 1;
PORTB = 0b11111111; //LIMPA PORTB
digito_minutos1 = 0;
PORTB = display(minutos1);
}
} //end if (teste de estouro)
} //end interrupt
// --- Função Principal ---
void main()
{
//Desabilita os resistores de pull-up internos
OPTION_REG = 0x81; // e configura o prescaler para 1:16 ou 1:4 se 11 ou 01 associado ao TMR0
GIE_bit = 0x01; //Habilita a interrupção global
PEIE_bit = 0x01; //Habilita a interrupção por periféricos
T0IE_bit = 0x01; //Habilita a interrupção por estoiro do TMR0
TMR0 = 0x06; //Inicia neste valor para dar contagem precisa (250*4*1 us cada estoiro ou seja 1 ms cada estoiro do Timer0)*/
CMCON = 0x07; // desabilita os comparadores
TRISA=0b00000000; //PORTA é configurado como saidas
TRISB=0b00000000; //PORTB configurado como saídas
digito_minutos2 = 1 ; // gate signal to pnp transistors to control the displays
digito_horas1 = 1 ;
digito_minutos1 = 1 ;
digito_horas2 = 1 ;
// -- Loop infinito --
while(1)
{
if(tempo == 1000) // ( 1us(=ciclo maquina) * 4(=PRESCALER) * 250(=256-6)) * 1000 = 1s
{
segundos++; // increments 1 second
tempo = 0x00;
}
if(segundos == 60)
{
minutos1++; // increments minute 1st digit
segundos = 0;
}
if(minutos1 == 10)
{
minutos2++; // increments minutes 2nd digit
minutos1 = 0;
}
if(minutos2 == 6)
{
horas1++; // increments hours 1st digit
minutos2 = 0;
}
if(horas1 == 10)
{
horas2++; // increments hours 2nd digit
horas1 = 0;
}
} //end while
} //end main
int display(int num)
{
int anode; //armazena código BCD
// -- Vetor para o código BCD --
int SEGMENTO[10] = {0b01000000,0b01111001,0b00100100,0b00110000,0b00011001,0b00010010,0b00000010,0b01111000,0b00000000,0b00011000} ;
anode = SEGMENTO[num];
return(anode);
} //end display
Attachments
Last edited by a moderator: