Hola a todos! :P :P
Inicio este hilo para consultar como podria encarara la recepcion y transmision de datos Serie entre un PIC18f452 y la PC...
Comando del Equipo
(http://img155.imagevenue.com/loc915/th_80976_Finish_122_915lo.jpg) (http://img155.imagevenue.com/img.php?image=80976_Finish_122_915lo.jpg)
Comando de la PC
(http://img181.imagevenue.com/loc493/th_09044_Sin_t92tulo-2_122_493lo.jpg) (http://img181.imagevenue.com/img.php?image=09044_Sin_t92tulo-2_122_493lo.jpg)
Mis intentos se basaron en codigos como el siguiente q no permiten la implementacion de la libreria CRC de CCS por no utilizar punteros :(
#define START1 0x78
#define START2 0x46
#int_RDA
RDA_isr()
{
int dato;
int i, Max_Ensayos;
//################################### START 1 ##################################
if (getc () != START1)
return;
//################################### START 2 ##################################
if (getc () != START2)
return;
//################################### HEADER ###################################
dato = getc ();
switch (dato)
{
case 0x42: // Interrogacion de presencia (primer comando de la hoja adjunta)
{
Envios de datos en respuesta....
.....
.....
break;
}
case 0xD3:
{ .......
He observado que el CCS incluye el archivo EX_CRC.C el cual mediante la funcion get_packet carga los datos recibidos en un arreglo y le aplica la correccion CRC... Mis intentos por adapatarla a mis comandos ha sido inutiles... :?
A continuacion les adjunto la funcion mencionada
// GET_BUFF_INT
// function to extract bytes from the buffer
int get_buff_int()
{
int retval;
while(!DATA_IN); // wait until data available
retval = ext_buffer[ext_buffer_next_out]; // get the byte
if(++ext_buffer_next_out == BUFFER_SIZE) // increment counter
ext_buffer_next_out = 0;
return retval;
}
// SEND_PACKET
// function to send a packet of data to another PIC
void send_packet(int* packet_ptr, int16 packet_length)
{
int *ptr;
int16 CRC,i;
ptr = packet_ptr; // set pointer
CRC = generate_16bit_crc(ptr, packet_length, CRC_CCITT);
// make CRC
for(i=0; i<packet_length; i++) // send packet
putc(packet_ptr[i]);
putc((int)(CRC>>8)); // send CRC
putc((int)(CRC));
}
short get_packet(int* packet_ptr)
{
short retval;
int16 length;
int16 CRC;
int16 i;
retval = TRUE;
packet_ptr[0] = get_buff_int(); // get the address of send to
packet_ptr[1] = get_buff_int(); // get the address of send from
if(packet_ptr[0] != MACHINE_ADDRESS)
retval = FALSE;
packet_ptr[2] = get_buff_int(); // get the control byte
if(packet_ptr[2] == NACK)
retval = FALSE;
packet_ptr[3] = get_buff_int(); // get the length of the data
packet_ptr[4] = get_buff_int();
length = (int16)(packet_ptr[3])<<8;
length += packet_ptr[4];
for(i=5; i<(length+5); i++) // get the data
packet_ptr[i] = get_buff_int();
packet_ptr[length+5] = get_buff_int(); // get the CRC
packet_ptr[length+6] = get_buff_int();
CRC = (int16)(packet_ptr[length+5])<<8;
CRC += packet_ptr[length+6];
if(CRC != generate_16bit_crc(packet_ptr, length+5, CRC_CCITT))
retval = FALSE;
return retval;
}
Agradezco todo comenteario, sugerencia, ayuda sobre la trama utilizada y la programacion q tendre q realizar...
Un saludo grande! :P :P