0
\$\begingroup\$

I am using a PIC16F877A and am reading its ADC value and sending it to the serial port. I am blinking an LED with it so that I can determine whether or not the program is stuck. Unfortunately, I cannot see any data on the port via Hyperterminal. However, if I test my code in Proteus, I see data on the virtual terminal. I know the hardware is designed correctly because it is a commercial testing kit.

I think there is a problem with the crystal settings.

I have also confirmed that the cable is working, because I use the same one for my programmer and this hardware. I am using the Mikro C pic compiler, with the frequency set to 4MHz. I tried to edit my project and set the oscillator to HS as well as XT, but the results are the same. What is wrong?

char text[7];

void main() {
  unsigned int adc_value =0;

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  ADCON1 = 0x80;              // Configure analog inputs and Vref
  TRISA = 0xFF;               // PORTA is input
  TRISC  = 0;                 // PORTC is output
  TRISB  = 0;                 // PORTB is output

  PORTB = 0;
  UART1_Write_Text("Start");

  Delay_ms(100);
  do
  {
  PORTB.B3 = ~PORTB.B3;

    adc_value = Adc_Read(0); // Get results of AD conversion
    IntToStr(adc_value, text);
    UART1_Write(10);
    UART1_Write(0x90);
    UART1_Write_Text(text);
    UART1_Write_Text("\r\n");
    Delay_us(200);
   // PORTB = adc_value;         // Send lower 8 bits to PORTB
    PORTC = adc_value >> 8;    // Send 2 most significant bits to RC1, RC0

    Delay_ms(100);
  } while(1);
}
\$\endgroup\$
  • \$\begingroup\$ What kind of oscillator is in use? Is it the internal oscillator, or an external crystal or what? \$\endgroup\$ – Majenko Jun 21 '11 at 20:34
  • \$\begingroup\$ I suggest you get an oscilloscope trace to check clock error, actual sending of data, logic levels, polarity, etc. Your code looks fine to a cursory reading. Also, move the PORTB.B3 = ~PORTB.B3; to the very end of the while loop so you know your code isn't merely resetting your processor to blink the LED. \$\endgroup\$ – Kevin Vermeer Jun 21 '11 at 21:05
1
\$\begingroup\$

Are you sure you have Hyperterminal set to the correct baud rate, etc? Make sure it isn't waiting for some kind of handshaking that you aren't providing.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

I've stopped using Hyperterminal years ago. It doesn't always work as expected. A good terminal program to use is Docklight Its very user friendly and has some nice features. The evaluation software will do what you want to do.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Do you believe that the problem is with Hyperterminal in this case? \$\endgroup\$ – Kevin Vermeer Jun 22 '11 at 0:35
  • \$\begingroup\$ @ Kevin Vermeer - Using a known good terminal program will eliminate the possibly of Hyperterminal errors. I have had issues with Hyperterminal years ago and stopped using it. I can't comment on how good it is now. It's an easy thing to try a new terminal and can save a lot of troubleshooting time. I agree with others that settings need to be checked and data monitored with a scope. \$\endgroup\$ – SteveR Jun 22 '11 at 11:45
0
\$\begingroup\$

If you're sure the settings in your code and Hyperterminal are right, probe the serial pins on the board to see if it is actually sending anything...

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.