Codigo para leer palabra por USART y visualizar en Displays 7 seg con 16F877A

He realizado este código que deseo compartir, en el cual se lee una trama serial recibida por el puerto serial del PIC y este interpreta un código inicial y luego toma los valores siguientes a este código para visualizarlos en display de 7 seg, la idea es de realizar un panel de simulador de vuelo en formato real con displays 7 Segmentos. El dato que envía el PC por ejemplo contiene "a01200b128e128,500f124,500". Cada letra corresponde a un instrumento del panel virtual del avión y en el caso de la letra "e" corresponde a la frecuencia activa de radio, y el código toma el valor en string y lo envía a 5 displays de 7 seg.

Ahora bien, deseo migrar este código a un 18F2550 pero no logro hacerlo funcionar por mas que programo los fuses.

Código:
#INCLUDE <16F877A.H>
#USE DELAY (CLOCK=20000000)
#fuses HS,NOWDT, NOPROTECT
#use rs232(baud=57600,xmit=pin_C6,rcv=pin_C7) /// librería para el manejo del 
#include <stdlib.h>
#include <lcd.c>


char dato_recibido[10];                /// aqui va a ir los datos recibidos por rs232
byte valor[10];

#byte PORTA=0x05           // Direccion del PortA
#byte PORTB=0x06           // Dirección del PortB
#byte PORTC=0x07           // Dirección del PortC
#byte PORTD=0x08

#bit  Unidad = PORTA.2     // Bit asignada a identificador Unidad
#bit  Decena = PORTA.1     // Bit asignada a identificador Decena
#bit  Centena = PORTA.0     // Bit asignada a identificador Centena
#bit  Decima = PORTA.3     // Bit asignada a identificador Décima
#bit  Centesima = PORTA.4     // Bit asignada a identificador Centésima

#int_rda                                     //// interrupción por escritura en buffer del puerto
void rda_isr()
 {
  gets(dato_recibido);                  //// esta instrucción almacena en la variable los
                                                 //// datos que se estén enviando hasta que llega 
                                                 //// la tecla enter
  }
  

void main() {

   enable_interrupts(int_rda);                    //// se habilita la interrupción por 
                                                             ////  escritura del puerto serial
   enable_interrupts(global);

setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
SETUP_ADC(NO_ANALOGS);
   set_tris_a(0x00);                   // Definimos el Puerto A como salida
   set_tris_b(0x00);                   // Definimos el Puerto B como entrada
   set_tris_c(0b10000000);                   // Definimos el Puerto C como salida
   set_tris_d(0x00);  

  
while (TRUE){
/*lcd_init();
delay_ms(500);
if (dato_recibido[0]=='D'){
   if (dato_recibido[1]=='0') {valor[1]=0;}
   if (dato_recibido[1]=='1') {valor[1]=1;}
   if (dato_recibido[1]=='2') {valor[1]=2;}
   if (dato_recibido[1]=='3') {valor[1]=3;}
   if (dato_recibido[1]=='4') {valor[1]=4;}
   if (dato_recibido[1]=='5') {valor[1]=5;}
   if (dato_recibido[1]=='6') {valor[1]=6;}
   if (dato_recibido[1]=='7') {valor[1]=7;}
   if (dato_recibido[1]=='8') {valor[1]=8;}
   if (dato_recibido[1]=='9') {valor[1]=9;}
}
lcd_gotoxy(1,1);
printf(lcd_putc,"hola");
delay_ms(2000);
*/

//printf(lcd_putc,"%u",valor[1]);
//delay_ms(500);

if (dato_recibido[0]=='O'){

igual:
if (dato_recibido[1]=='9'){
   porta=0b011110;
   portb=0b01100111;
   valor[1]=9;}
if (dato_recibido[1]=='8'){
   porta=0b011110;
   portb=0b01111111;
   valor[1]=8;}
if (dato_recibido[1]=='7'){
   porta=0b011110;
   portb=0b00000111;
   valor[1]=7;}
if (dato_recibido[1]=='6'){
   porta=0b011110;
   portb=0b01111100;
   valor[1]=6;}
if (dato_recibido[1]=='5'){
   porta=0b011110;
   portb=0b01101101;
   valor[1]=5;}
if (dato_recibido[1]=='4'){
   porta=0b011110;
   portb=0b01100110;
   valor[1]=4;}
if (dato_recibido[1]=='3'){
   porta=0b011110;
   portb=0b01001111;
   valor[1]=3;}
if (dato_recibido[1]=='2'){
   porta=0b011110;
   portb=0b01011011;
   valor[1]=2;}
if (dato_recibido[1]=='1'){
   porta=0b011110;
   portb=0b00000110;
   valor[1]=1;}
if (dato_recibido[1]=='0'){
   porta=0b011110;
   portb=0b00111111;
   valor[1]=0;
   }
delay_ms(60);

if (dato_recibido[2]=='9'){
   porta=0b011101;
   portb=0b01100111;}
if (dato_recibido[2]=='8'){
   porta=0b011101;
   portb=0b01111111;}
if (dato_recibido[2]=='7'){
   porta=0b011101;
   portb=0b00000111;}
if (dato_recibido[2]=='6'){
   porta=0b011101;
   portb=0b01111100;}
if (dato_recibido[2]=='5'){
   porta=0b011101;
   portb=0b01101101;}
if (dato_recibido[2]=='4'){
   porta=0b011101;
   portb=0b01100110;}
if (dato_recibido[2]=='3'){
   porta=0b011101;
   portb=0b01001111;}
if (dato_recibido[2]=='2'){
   porta=0b011101;
   portb=0b01011011;}
if (dato_recibido[2]=='1'){
   porta=0b011101;
   portb=0b00000110;}
if (dato_recibido[2]=='0'){
   porta=0b011101;
   portb=0b00111111;
   }
delay_ms(60);

if (dato_recibido[3]=='9'){
   porta=0b011011;
   portb=0b01100111;}
if (dato_recibido[3]=='8'){
   porta=0b011011;
   portb=0b01111111;}
if (dato_recibido[3]=='7'){
   porta=0b011011;
   portb=0b00000111;}
if (dato_recibido[3]=='6'){
   porta=0b011011;
   portb=0b01111100;}
if (dato_recibido[3]=='5'){
   porta=0b011011;
   portb=0b01101101;}
if (dato_recibido[3]=='4'){
   porta=0b011011;
   portb=0b01100110;}
if (dato_recibido[3]=='3'){
   porta=0b011011;
   portb=0b01001111;}
if (dato_recibido[3]=='2'){
   porta=0b011011;
   portb=0b01011011;}
if (dato_recibido[3]=='1'){
   porta=0b011011;
   portb=0b00000110;}
if (dato_recibido[3]=='0'){
   porta=0b011011;
   portb=0b00111111;
   }
delay_ms(60);

if (dato_recibido[5]=='9'){
   porta=0b010111;
   portb=0b01100111;}
if (dato_recibido[5]=='8'){
   porta=0b010111;
   portb=0b01111111;}
if (dato_recibido[5]=='7'){
   porta=0b010111;
   portb=0b00000111;}
if (dato_recibido[5]=='6'){
   porta=0b010111;
   portb=0b01111100;}
if (dato_recibido[5]=='5'){
   porta=0b010111;
   portb=0b01101101;}
if (dato_recibido[5]=='4'){
   porta=0b010111;
   portb=0b01100110;}
if (dato_recibido[5]=='3'){
   porta=0b010111;
   portb=0b01001111;}
if (dato_recibido[5]=='2'){
   porta=0b010111;
   portb=0b01011011;}
if (dato_recibido[5]=='1'){
   porta=0b010111;
   portb=0b00000110;}
if (dato_recibido[5]=='0'){
   porta=0b010111;
   portb=0b00111111;
   }
delay_ms(60);

if (dato_recibido[6]=='9'){
   porta=0b001111;
   portb=0b01100111;}
if (dato_recibido[6]=='8'){
   porta=0b001111;
   portb=0b01111111;}
if (dato_recibido[6]=='7'){
   porta=0b001111;
   portb=0b00000111;}
if (dato_recibido[6]=='6'){
   porta=0b001111;
   portb=0b01111100;}
if (dato_recibido[6]=='5'){
   porta=0b001111;
   portb=0b01101101;}
if (dato_recibido[6]=='4'){
   porta=0b001111;
   portb=0b01100110;}
if (dato_recibido[6]=='3'){
   porta=0b001111;
   portb=0b01001111;}
if (dato_recibido[6]=='2'){
   porta=0b001111;
   portb=0b01011011;}
if (dato_recibido[6]=='1'){
   porta=0b001111;
   portb=0b00000110;}
if (dato_recibido[6]=='0'){
   porta=0b001111;
   portb=0b00111111;
   }
delay_ms(60);

//dato_recibido=0;
//porta=0b111111;

}else{
   //goto igual;
}

}
}


Busco una ayuda en orientación, debido a que deseo leer una trama mayor con este pic por tener mayor cantidad de memoria y luego de tomados todos los valores necesarios del panel redirigirlos a otros pics que se encargaran de manejar los diversos displays de 7 seg y solo recibir la data particular que envie este pic 18F.
 
Última edición por un moderador:
Atrás
Arriba