por mdaweb » 11 Set 2008 16:55
Fabim, voce pode dar uma olhada no codigo e ver se a logica ta correta?
#include <16f88.h>
#use delay(clock=20000000)
//#include "1_CD4094.h"
#fuses HS,NOWDT,PUT,NOLVP
//#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1)
/* Definição dos pinos de latch para endereçar para o CD4094 correto
L0 L1 Qual 4094
0 0 Nenhum
1 0 1
0 1 2
1 1 3
*/
//#define L0 PIN_B3
//#define L1 PIN_B4
//#define L2 PIN_B5
#define CLK PIN_A0
//#define Enb PIN_B5
//Define os pinos da saida serial e do clock para o CD4094
#define DSerial PIN_A1
#define DCLK PIN_A2
int8 convert_table(int decimal)
{
// 'Catodo Comum
// 'data @0,63,6,91,79,102,109,125,7,127,111
// 'Anodo Comum
// data @0,192,249,164,176,153,146,130,248,128,144 ' table to convert
// ' numbers to 7 segments
// ' pattern output when
// ' drive invert
//Esta função retorna o equivalente do código de 7 seguimentos de um número decimal.
static unsigned int table [ ] = {126, //252, // 0
48, //96, // 1
109, //218, // 2
121, //242, // 3
51, //102, // 4
91, //182, // 5
95, //125, // 6
112, //224, // 7
127, //254, // 8
123}; //230};// 9
/*static unsigned int table [ ] = {252, // 0
96, // 1
218, // 2
242, // 3
102, // 4
182, // 5
125, // 6
224, // 7
254, // 8
230};// 9
*/
return table[decimal];
}
void LatchToDisplay(int disp)
// Esta função habilita o latch para endereçar para o display desejado. )
{
output_low(CLK);
delay_ms(2);
output_high(CLK);
}
//Envia numero em bits para a porta serial do 4094
void WriteDisplay(int disp, int num)
{
int n, i, n2;
n = convert_table(num);
for (i=0; i<7; i++)
{
n2 = n%2;
n /= 2;
output_low(DCLK);
output_bit(DSerial, n2);
output_high(DCLK);
}
LatchToDisplay(disp);
}
void main()
{
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
output_toggle(CLK);
while(TRUE)
{
output_low(CLK);
WriteDisplay(1,6);
output_low(CLK);
WriteDisplay(2,5);
output_low(CLK);
WriteDisplay(3,4);
output_low(CLK);
WriteDisplay(4,3);
output_low(CLK);
WriteDisplay(5,2);
output_low(CLK);
WriteDisplay(6,1);
}
}
[]'
Mauro.