Why is my PIC 18F2550 not sending data when I tell it to?

Click For Summary

Discussion Overview

The discussion revolves around a user experiencing issues with a PIC 18F2550 microcontroller not sending data via the serial port when a specific character ('a') is received. The scope includes programming, hardware troubleshooting, and potential issues with the code and circuit setup.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Experimental/applied

Main Points Raised

  • The user describes their project and shares code intended to send data from the ADC when the 'a' character is received.
  • Some participants suggest testing smaller parts of the code to verify functionality, such as using LEDs instead of serial output to check if interrupts are working.
  • One participant points out that C is case-sensitive, highlighting that '#Include' and '#include' are treated differently by the preprocessor.
  • The user later reports that the code works in simulation but suspects a hardware issue with the physical circuit, which is currently unavailable for testing.
  • Another participant reiterates the importance of case sensitivity in preprocessor commands and provides a resource for reference.
  • Further discussion includes the mention of pragmas and their distinction from standard preprocessor commands, with a warning about case sensitivity again noted.

Areas of Agreement / Disagreement

Participants generally agree on the importance of case sensitivity in C programming and the need to verify both software and hardware components. However, the discussion reflects uncertainty regarding the hardware setup, as the user has not yet confirmed the physical circuit's functionality.

Contextual Notes

The user has not fully resolved the hardware issue, and there may be additional dependencies on the physical circuit's integrity that are not addressed in the code alone.

Who May Find This Useful

Individuals working with PIC microcontrollers, those troubleshooting serial communication issues, and programmers interested in case sensitivity in C language may find this discussion relevant.

Guidestone
Messages
93
Reaction score
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:

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:
Engineering news on Phys.org
Did you test smaller parts of it? Having the input and output in the main function to check that part? Instead of sending a char back, activating some LED to see if the interrupt works at all?
 
  • Like
Likes   Reactions: cnh1995
You code in C - and C is case sensitive. So #Include and #include are essentially different commands to the preprocessor.
 
mfb said:
Did you test smaller parts of it? Having the input and output in the main function to check that part? Instead of sending a char back, activating some LED to see if the interrupt works at all?
Hi mfb thank you for your aswer. Yesterdy a few hours after I posted my code I found out it is actually working fine, I am getting the values immediately after I send the character. However, I was testing in a simulating software and the physical circuit was still not working. I guess it's a hardware problem and the friend of mine who soldered the whole thing took it home. I'll have to wait till monday to see what's going on.
Svein said:
You code in C - and C is case sensitive. So #Include and #include are essentially different commands to the preprocessor.
Thank you for your answer svein. Should it start with a lowercase letter?
 
There are also what appear to be pragmas ex:
Code:
#use fast_io(a)
pragmas are not going to be in the list @Svein gave you.

And the same warning about capital letters: there are lines that start #Use
 
Thank you Svein and Jim, I'll check those out in a while :)
 

Similar threads

Replies
14
Views
26K