#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, BITS=8)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
unsigned char datos [16];
int j;
void diagnostico (void)
{
datos [0]=0;
delay_us(0.4);
datos [1]=1;
delay_us(0.4);
datos [2]=0;
delay_us(0.4);
datos [3]=1;
delay_us(0.4);
datos [4]=0;
delay_us(0.4);
datos [5]=1;
delay_us(0.4);
datos [6]=0;
delay_us(0.4);
datos [7]=1;
delay_us(0.4);
datos [8]=0;
delay_us(0.4);
datos [9]=1;
delay_us(0.4);
datos [10]=1;
delay_us(0.4);
datos [11]=0;
delay_us(0.4);
datos [12]=1;
delay_us(0.4);
datos [13]=0;
delay_us(0.4);
datos [14]=1;
delay_us(0.4);
datos [15]=1;
delay_us(0.4);
for (j=0;j<15;j++ )
{
putc(datos[j]);
}
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
diagnostico();
}
}
datos [0]=0;
delay_us(0.4);
datos [1]=1;
delay_us(0.4);
datos [2]=0;
delay_us(0.4);
datos [3]=1;
delay_us(0.4);
datos [4]=0;
delay_us(0.4);
datos [5]=1;
delay_us(0.4);
datos [6]=0;
delay_us(0.4);
datos [7]=1;
delay_us(0.4);
datos [8]=0;
delay_us(0.4);
datos [9]=1;
delay_us(0.4);
datos [10]=1;
delay_us(0.4);
datos [11]=0;
delay_us(0.4);
datos [12]=1;
delay_us(0.4);
datos [13]=0;
delay_us(0.4);
datos [14]=1;
delay_us(0.4);
datos [15]=1;
delay_us(0.4);Parameters: time - a variable 0-65535(int16) or a constant 0-65535
lo que pasa es que en esa señal es una cuadrada aleatoria y le pongo retardos para se demore un poco en cada dato y mande un float porque necesitaba 400 nanosegundos pero como no se puede los converti a 0.4 microsegundos o como hago para hacer 400 nanosegundos, killer entonces pongo esa parte que me pusiste y quito lo de la uart pero entonces porque pin puedo enviar esa señal
killer y si tengo una entrada que si sea una señal cuadrada que varia entre 0 y 1 y lo que necesito es que por el pin que entra hacer un while que dure un tiempo determinado preguntando si la señal esta en 1 o en cero y dependiendo de si se repite mas 1 o 0 en ese intervalo de tiempo prenda o apague los leds como hago eso
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, BITS=8)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
unsigned char datos [16]={0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,1};
void diagnostico (void)
{
int j;
delay_us(1);
for (j=0;j<16;j++ )
{
putc(datos[j]);
}
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
diagnostico();
}
}
y como es eso del spi por software
porque dices que SDO es entrada ahi dice que ese es el de salida
y se ve la señal de error por ese pin pero hasta ahora yo no he notado la diferencia de esa señal cuando toda la matriz de leds funciona
y como es eso de darle masd e un ciclo al CLKhttps://www.rcscomponents.kiev.ua/datasheets/mbi5039gf.pdf
entonces para mejorar el programa me puedes ayudar con la iniciacion de esas funciones
gracias, pero entonces para hacer ese cambio en le y oe los pongo en algun pin del micro pero, hay una señal que debo enviar por el pin CLK asi que no se como hacerle ese cambio de 1 a 0 al CLK
entonces si por ejemplo necesito enviar la siguiente señal por spi 0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,1
no entendi bien cual señal deberia enviar por clk
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, BITS=8)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
unsigned char datos [8]={0,1,0,1,0,1,0,1};
unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
int j;
int k;
delay_us(1);
for (j=0;j<8;j++ )
{
putc(datos[j]);
}
for (k=0;k<8;k++ )
{
putc(datos2[k]);
}
}
void init(){
setup_spi(SPI_MASTER |SPI_L_TO_H| SPI_XMIT_L_TO_H | SPI_CLK_DIV_64);
SET_TRIS_C(0x00);
spi_write(0x31); //send the write instruction
//spi_write(0x01); //address of a register to test reading and writing //
spi_write(0x2D); //send the write instruction//
spi_write(0x08); //address of a register to test reading and writing
}
int x0;
int x1;
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
init();
printf( "datos[j]");
printf( "datos2[k]");
OUTPUT_LOW(PIN_C3);
delay_us(5);
x0= spi_read(0x32);
x1= spi_read(0x32);
OUTPUT_HIGH(PIN_C3);
printf( "valor %c\r\n", x0);
printf( "valor %c\r\n", x1);
delay_ms(1000);
diagnostico();
}
}
#use SPI(
DO = PIN_C5,
DI = PIN_C4,
CLK = PIN_C3,
baud =9600 ,
BITS = 8,
LSB_FIRST,
SAMPLE_RISE,
stream = SPI_PORT0
)no me sirve me vota muchos errores no importa donde lo ponga y cuando lo cambio por esto void spi_ini(void){
DO = PIN_C5,
DI = PIN_C4,
CLK = PIN_C3,
baud =9600 ,
BITS = 8,
LSB_FIRST,
SAMPLE_RISE,
stream = SPI_PORT0
}me salen dos errores y no se como quitarlos #use SPI(MASTER,DI=PIN_B1, DO=PIN_B0, CLK=PIN_B2,baud=9600, BITS=8,MODE=0)me salen estos errores
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use SPI(MASTER,DI=PIN_B1, DO=PIN_B0, CLK=PIN_B2,baud=9600, BITS=8,MODE=0)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
unsigned char datos [8]={0,1,0,1,0,1,0,1};
unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
int j;
int k;
delay_us(1);
for (j=0;j<8;j++)
{
putc(datos[j]);
putc(datos2[k]);
}
for (k=0;k<8;k++ )
{
putc(datos2[k]);
}
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
}
}
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use SPI(MASTER,MODE=1,DO = PIN_C5,DI = PIN_C4,CLK = PIN_C3,baud =9600,BITS = 8,LSB_FIRST,SAMPLE_RISE,stream = SPI_PORT0)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
unsigned char datos [8]={0,1,0,1,0,1,0,1};
unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
int j;
int k;
delay_us(1);
for (j=0;j<8;j++)
{
putc(datos[j]);
}
for (k=0;k<8;k++ )
{
putc(datos2[k]);
}
}
int j,k;
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
datos2[k]=spi_xfer(0);
}
}
este codigo funciona alguien lo puede probar en proteus haber si envia la señal por spi
Compañero yair_xiox veo el código muy desorganizado no entiendo para que creas una función diagnostico() si no la utilizas, segundo utilizas la directivas #use fast_io(puerto) pero luego utilizas las funciones tris_puerto(xx) se asume que al definir la directiva no resulta necesario configurar los puertos del micro.
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
unsigned char datos [8]={0,1,0,1,0,1,0,1};
unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
int j;
int k;
set_tris_c(0x08); // Configuración del puerto C para trabajar el spi
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
delay_us(1);
for (k=0;k<8;k++)
{
for (j=0;j<8;j++)
{
spi_write(datos[j]);
spi_write(datos2[k]);
delay_ms(200);
}
}
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
diagnostico();
}
}
for (k=0;k<8;k++)
{
for (j=0;j<8;j++)
{
spi_write(datos[j]);
spi_write(datos2[k]);
delay_ms(200);
}
}
si pero eso ya lo hice ya leí ambos datasheets y por spi solo se pueden enviar 8 bits pero yo necesito enviar 16 bits
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
//unsigned char datos [8]={0,1,0,1,0,1,0,1};
//unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
int j;
//int k;
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
delay_us(1);
for (j=0;j<8;j++)
{
spi_write(0x6B);
spi_write(0X55);
delay_ms(200);
output_high(PIN_C2);
output_low(PIN_C2);
}
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
diagnostico();
}
}
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
//unsigned char datos [8]={0,1,0,1,0,1,0,1};
//unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
//int j;
//int k;
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
delay_us(1);
spi_write(0x6B);
spi_write(0X55);
delay_ms(200);
output_high(PIN_C2);
output_low(PIN_C2);
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
diagnostico();
}
}
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#define PIN_OE PIN_C1
#define PIN_LE PIN_C2
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int8 j,k;
//unsigned char datos [8]={0,1,0,1,0,1,0,1};
//unsigned char datos2 [8]={0,1,1,0,1,0,1,1};
void diagnostico (void)
{
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
delay_us(1);
spi_write(0x6B);
spi_write(0X55);
output_low(PIN_OE);
delay_us(1);
output_high(PIN_OE);
j = spi_read(0);
k = spi_read(0);
delay_ms(200);
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
output_high(PIN_A0);
while(true)
{
if(input(PIN_A4)==0)
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
else
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
diagnostico();
}
}
y faltarían conectar y probar pero lo que no he podido hacer y no se como es que cuando detecte error prenday faltarían conectar y probar pero lo que no he podido hacer y no se como es que cuando detecte error prenda
los leds y cuando no los apague esa parte es muy difícil ya que el MBI solo manda una señal cuadrada como salida y esto es difícil de detectar para los leds
ya que los leds solo se prenden cuando hay uno o cero pero constantes no una señal que cambia entre ambos estados
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#define PIN_OE PIN_C1
#define PIN_LE PIN_C2
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
int16 errores;
void diagnostico (void)
{
int8 j,k;
output_low(PIN_OE);
output_high(PIN_OE);
j = spi_read(0);
k = spi_read(0);
errores = make16(j,k);
}
void programarMBI (void)
{
spi_write(0x6B);
spi_write(0X55);
output_high(PIN_LE);
output_low(PIN_LE);
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
output_high(PIN_A0);
programarMBI();
diagnostico();
while(true)
{
if(errores)
{
output_b(0x0F);
}
else
{
output_b(0x0);
}
}
}
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#define PIN_OE PIN_C1
#define PIN_LE PIN_C2
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
int16 errores;
void diagnostico (void)
{
int8 j,k;
output_low(PIN_OE);
output_high(PIN_OE);
j = spi_read(0);
k = spi_read(0);
errores = make16(j,k);
}
void programarMBI (void)
{
output_low(PIN_A5);
spi_write(0x6B);
spi_write(0X55);
output_high(PIN_LE);
output_low(PIN_LE);
output_high(PIN_A5);
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
output_low(PIN_A5);
output_high(PIN_A5);
output_high(PIN_A0);
programarMBI();
diagnostico();
while(true)
{
if(errores)
{
output_b(0x0F);
}
else
{
output_b(0x0);
}
}
}
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#define PIN_OE PIN_C1
#define PIN_LE PIN_C2
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
int16 errores;
void diagnostico (void)
{
int8 j,k;
output_low(PIN_OE);
output_high(PIN_OE);
j = spi_read(0);
k = spi_read(0);
errores = make16(j,k);
}
char new_data;
void programarMBI (void)
{
output_low(PIN_A5);
spi_write(0x6B);
spi_write(0X55);
output_high(PIN_LE);
output_low(PIN_LE);
output_high(PIN_A5);
if ( spi_data_is_in() )
new_data = spi_read();
}
void main(){
set_tris_b(0x00);
set_tris_a(0x10);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64);
output_low(PIN_A5);
output_high(PIN_A5);
output_high(PIN_A0);
programarMBI();
diagnostico();
while(true)
{
if(errores)
{
output_b(0x0F);
}
else
{
output_b(0x0);
}
}
}
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#define PIN_OE PIN_C1
#define PIN_LE PIN_C2
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, BITS=8)
int16 errores;
void diagnostico (void)
{
int8 j,k;
output_low(PIN_OE);
output_high(PIN_OE);
j = spi_read(0);
k = spi_read(0);
errores = make16(j,k);
}
void programarMBI (void)
{
set_tris_c(0x10);
output_high(PIN_LE);
output_low(PIN_LE);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
spi_write(0x6B);
spi_write(0X55);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
output_low(PIN_C3);
}
void main(){
set_tris_b(0x00);
set_tris_a(0x00);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
setup_spi(spi_master | spi_l_to_h | spi_clk_div_16);
output_high(PIN_A0);
programarMBI();
diagnostico();
while(true)
{
if(errores)
{
output_b(0x00);
}
else
{
output_b(0x0F);
}
}
}
#if defined(__PCM__)
#include <16f73.h>
#fuses XT,NOWDT,PUT, NOPROTECT
#use delay (clock =4000000)
#define PIN_OE PIN_C1
#define PIN_LE PIN_C2
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
int16 errores;
void diagnostico (void)
{
int8 j,k;
output_low(PIN_OE);
output_high(PIN_OE);
j = spi_read(0);
k = spi_read(0);
errores = make16(j,k);
}
void programarMBI (void)
{
set_tris_c(0x10);
output_high(PIN_LE);
output_low(PIN_LE);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
spi_write(0x6B);
spi_write(0X55);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
output_high(PIN_C3);
output_low(PIN_C3);
}
void main(){
set_tris_b(0x00);
set_tris_a(0x00);
set_tris_c(0x80);
setup_adc_ports(NO_ANALOGS);
setup_spi(spi_master | spi_l_to_h | spi_clk_div_64 |SPI_SS_DISABLED);
*0x94 |= 0x40; // set CKE = 1 - clock idle low
*0x14 &= 0xEF; // set CKP = 0 - data valid on rising edge
output_high(PIN_A0);
programarMBI();
diagnostico();
while(true)
{
if(errores==0)
{
output_b(0x00);
}
else
{
output_b(0x0F);
}
}
}
hola aqui ya con este codigo en el circuito hace unos pequeños intentos de funcionar pero la mayoria de las veces no funciona no se porque