Você está na página 1de 2

source_file_PIC016.

c 19/01/2018 17:53:17

1: #define DIGIT1 PORTB.F7


2: #define DIGIT2 PORTA.F2
3: #define DIGIT3 PORTA.F3
4: #define MAIS PORTA.F1
5: #define MENOS PORTA.F0
6:
7: int Cen,Msd,Lsd,Cnt = 0;
8:
9:
10: int Display(int no);
11: void changeCount();
12:
13: void main() //inicio programa principal
14: {
15:
16: CMCON = 0x07;
17: TRISA=0b00000011; //RA0 e RA1 são configurados como entrada
18: TRISB=0b00000000; //PORTB configurado como saídas
19: DIGIT2=0; //Desabilita Digito1
20: DIGIT3=0; //Desabilita Digito2
21:
22: while(1) //loop infinito
23: {
24:
25: changeCount();
26: // 253 , 253 e 100 = 53, 0,53 ("2")
27: Cen = (Cnt/100)-((Cnt%100)/100); //Dígito das centenas
28:
29: PORTB = Display(Cen); //Envia para o PORTB
30: DIGIT1 = 1; //habilita digito1(centena)
31: delay_ms(5); //aguarda 5 milisegundos
32: DIGIT1 = 0; //desabilita digito1(centena)
33:
34: Msd = (Cnt%100); //53 , 5,3 , 3 , 0,3
35: Msd = (Msd/10) - ((Msd%10)/10); // "5"
36:
37: PORTB=Display(Msd); //Envia para PORTB
38: DIGIT2=1; //habilita digito 2(dezena)
39: delay_ms(5); //aguarda 5 milisegundos
40: DIGIT2=0; //desabilita digito 2(dezena)
41: //"3"
42: Lsd=Cnt%10; //digito menos significativo ou unidade
43:
44: PORTB=Display(Lsd); //Envia para PORTB
45: DIGIT3=1; //habilita digito 3(unidade)
46: delay_ms(5); //aguarda 5 milisegundos
47: DIGIT3=0; //desabilita digito 3(unidade)
48: } // end while
49: } //end void main
50:
51:
52: //esta função acha o bit pattern(matrix de bits) para ser enviado
53: //para o PORTB e mostrar um número no display de 7 segmentos.O número
54: //é passado como um argumento para a função.
55: int Display(int no)
56: {
57: int Pattern;

1/2 mikroC PRO for PIC by mikroElektronika


source_file_PIC016.c 19/01/2018 17:53:17

58: int SEGMENTO[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};


59: Pattern=SEGMENTO[no]; //para retornar o Pattern
60: return(Pattern);
61: } //end função
62:
63:
64: void changeCount()
65: {
66: while(MAIS == 1)
67: {
68: Cnt = Cnt + 10;
69: delay_ms(180);
70: if(Cnt > 300) Cnt = 300;
71: }
72: while(MENOS == 1)
73: {
74: Cnt = Cnt - 10;
75: delay_ms(180);
76: if(Cnt < 1) Cnt = 0;
77: }
78: }

2/2 mikroC PRO for PIC by mikroElektronika

Você também pode gostar