- #1
Guidestone
- 93
- 5
Hey guys. I got a project in which I'm working on right now and I got to use a microcontroller in it. The microcontroller is a PIC 18F2550 and I have to receive data whenever I send the 'a' character via the serial port(RS232). The data I'm suposed to receive is generated with the ADC from the chip. The ADC is working fine and my code is capable of sending data quickly but the point of the code is to send data only when I tell it to but that part in the code does not seem to be working at all.
My code is this:
As you can see, this is not assembler languaje for I'm using picc compiler. Both the simulations I've done in proteus and the tests I've made in real life haven't showed me any numbers coming from the chip, all I've got in the hyperterminal is a blank screen.
I would really appreciate any guide on this. I'm sorry if this is not the correct section of the forum to post this but it involves electronics and not only programming so I thought it would be better suited for this section.
My code is this:
Code:
#Include <18F2550.h> //Libreria del PIC
#Device adc = 10 //Deficicion del ADC
#Fuses HS,NOWDT,NOPROTECT,CPUDIV1
#Use delay(clock = 20000000) //Frecuencia del Oscilador
#Use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,parity=N,bits=8) //Directiva para comunicacion serial
#include <stdio.h>
#fuses NOLVP, PLL1, CPUDIV1, NOPBADEN, NOVREGEN, NOPUT, NOBROWNOUT
#use fast_io(a) //Configura los pines como entrada o salida, se necesita pines de configuracion.
#use fast_io(b) //Configura los pines como entrada o salida, se necesita pines de configuracion.
#use fast_io(c)
//!#use fast_io(d) //Configura los pines como entrada o salida, se necesita pines de configuracion.
//!#use fast_io(e) //COnfigura los pines como entrada o salida, se necesita pines de configuracion.
//!int8 z, u, c, j;
//***Variables globales***\\\
float ADC; //Variable del convertidor analogico-digital
float ADC1; //Variable OffSet
float Tension; //Devuelve un valor como tension
float Desplazamiento; //Valor de desplazamiento del LVDT
char z;
void habilitar()
{
enable_interrupts(GLOBAL);//Interrupción global
enable_interrupts(INT_RDA);//Interrupción de puerto serie
}
void Inicializar(void) //Funcion para Inicializar todas las variables
{
output_a (0x00);
output_b (0x00);
output_c (0x00);
//! output_d (0x00);
output_e (0x00);
set_tris_a(0b00000001);//Declaramos los pines menos significativos de puerto A como entradas
set_tris_b(0b00000000);//Todo el puerto B como salida
set_tris_c(0b10000000);//Una sola entrada en puerto C
//! set_tris_d(0b00000000);//todo el puerto D como salida
set_tris_e(0b00000000);//Todo el puerto E como salida
//setup_adc(ADC_ON); setup_adc_ports(AN0_TO_AN3 | VSS_VDD);
setup_adc(adc_clock_internal);
setup_adc(ADC_CLOCK_DIV_2);
//lcd_init(); //Inicializar LCD
set_adc_channel(0); //Pin analogico cero
delay_us(50);
ADC1 = read_adc(); //Coloca un OffSet de inicio
}
#INT_RDA
void INTER_RDA() //Interrupción en el buffer de datos. Permite que se ejecute una tarea una vez que se detecta un dato en el buffer.
{
//! kbhit();
z=getc();
Putc(z);
}
void main()
{
Inicializar();
habilitar();
//printf("Desplazamiento:");
while (true)
{
if(z=='a')
{
set_adc_channel(0); //Pin analogico cero
delay_us(50); //Retardo entre cada lectura
ADC = read_adc()-ADC1; //Los valores se guardan en la variable ADC, ADC1 genera un cero de partida
Tension = (ADC*5)/1023; //Conversion de Digital-analogico
Desplazamiento = -(.055*(Tension*Tension))+(6.8*Tension)-.011; //Variable de salida
printf("%F",Desplazamiento);
z='b';
}
}
}
As you can see, this is not assembler languaje for I'm using picc compiler. Both the simulations I've done in proteus and the tests I've made in real life haven't showed me any numbers coming from the chip, all I've got in the hyperterminal is a blank screen.
I would really appreciate any guide on this. I'm sorry if this is not the correct section of the forum to post this but it involves electronics and not only programming so I thought it would be better suited for this section.
Last edited by a moderator: