1. riad_00

    Thread Starter Member

    Feb 9, 2008

    I am trying to send data over RS232. The analouge signal is coming from a temperature sensor (LM-35) and is being dizitised by PICC18F4520. Then it should send the data via RS232 port to Hyper Terminal. But I can't see any thing. Is any thing wrong with my codes.

    Thanks in advance

    P:S: I am using a seven segment as well, for the privious effort - so the codes remained.

  2. beenthere

    Retired Moderator

    Apr 20, 2004
    Think about the absolute output of the LM35 in the range of temperature being measured and the sensitivity of your A to D conversion. Is the output enough to change even one bit? You probably need an amplifier to give the A to D enough voltage to distinguish a change in temperature.
  3. riad_00

    Thread Starter Member

    Feb 9, 2008
    Thanks for the reply.

    It works fine with 7-segment. I still can manage to put an op-amp if required. But I am getting digits and I want to send them to RS232.

    P:S: I am an entry level PIC programmer.:)
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    If you are trying to send RS232 data to a PC running Hyperterminal you must first convert your data to an ASCII string, then use the USART library routines (assuming they are present in your compiler) or write your own routine to send out the string of ASCII characters over the usart port.
    You will also have to use a MAX232 or similar chip to convert the logic level signal from the PIC to RS232 signal levels.
  5. riad_00

    Thread Starter Member

    Feb 9, 2008

    I changed the codes a bit. I am using 'usart.h' and because 'temp' is char type I guess putcUSART() is good enough. I have got MAX202ecpe chip to make RS232 level. I have checked TX pin (25) with a scope, there is serial data there and output of the MAX chip, there is also serial output there. Doesn't make sence - why I don't see anything in hyperterminal! grrrr:mad:

    Plz help me - I am pulling my hair off.

    Code ( (Unknown Language)):
    2. void main (void)
    3. {
    4.     unsigned short result = 0;
    5.     unsigned char temp;
    6.     unsigned char units;
    7.     unsigned char tens;
    8.     unsigned char nunits;
    9.     unsigned char ntens;
    10.     TRISC = 0b11000000;
    11.                TRISD = 0b00000000;
    12.     ADCON0 = 0b00000000;
    13.     ADCON1 = 0b00001110;
    14.     ADCON2 = 0b10001100;
    15.     ADCON0bits.ADON = 1;
    17.     //TXSTA = 0b00100100; //8bit-trsnmit disable-high baud rt-asynchronous
    19.     //RCSTAbits.CREN = 0; //Disable Reciever.
    20.     //BAUDCON = 0b00000000; //8bit
    25.     while (1)
    26.     {
    27.         //RCSTAbits.SPEN = 1; //Serial Port Enable - TX/DT
    28.         ADCON0bits.GO = 1;
    29.         while(ADCON0bits.GO);
    30.                    result = ADRESH;
    31.         result = result <<  8;
    32.         result = result + ADRESL;
    33.                                temp = (result*0.4882815 + 2);
    34.         units = temp%10;
    35.         tens = (temp/10)%10;
    36.         PORTC = ~LED[units];
    37.         PORTD = ~LED[tens];
    39.         //TXREG = temp;
    40.         //PORTCbits.RC6 = TXREG;
    41.         putcUSART(temp);   
    42.     }
    44. }
  6. wannaBinventor

    Active Member

    Apr 8, 2010
    I've never used it but I've read that you have to make sure the baud rate in hyperterminal matches the baud rate of your PIC's UART.
  7. Markd77

    Senior Member

    Sep 7, 2009
    Have you got pin 5 on the serial cable connected to your circuit ground and the output of the max232 to pin 2?
    If there are any hardware handshaking settings on hyperterminal they need turning off.
    I use realterm software - it's free - it has indicators that show the status of the serial pins so you can tell if anything at all is getting in, even if it isn't valid data.
  8. nhenri

    New Member

    Oct 18, 2010
    simple code for pic18f26j50

    void Init_Console(void)
    TRISCbits.TRISC7=1; //input rx

    TRISCbits.TRISC6=0; //output TX

    TXSTA1bits.SYNC=0; //asynchrone
    TXSTA1bits.TXEN=1; //tx enable
    TXSTA1bits.BRGH=1; //high speed

    RCSTA1bits.SPEN=1; //uart on
    RCSTA1bits.CREN=0; //Receive on
    RCSTA1bits.CREN=1; //Receive on !!

    SPBRG1=103; //115200 @ 48mhz

    BAUDCON1bits.BRG16=1; //16bits
    BAUDCON1bits.ABDEN=0; //dont auto-detect baud rate


    void Console_SendROM(const rom char *str)
    while(!PIR1bits.TX1IF );
  9. eblc1388

    AAC Fanatic!

    Nov 28, 2008
    Reminded me of an incident years ago, where I forgot to connect the ground connection to the RS232 DB9 socket on the project board. I only connected the Rx and Tx.

    With my ICSP programmer connected, the serial port on the project works faultlessly in communication with the PC, where I done all my testing and troubleshooting.

    After everything checked out, I powered down and pack up the project into its own case.

    Then the communication does not work anymore.

    I then dumped the flash content of the MCU and it match with the source.

    Now the communication suddenly works again(because I have the ICSP connected).

    Ultimately after repeating the same three times and a lot of swearing, the culprit was found. :):):)
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    The hyperterm program is not optimal in many ways. I like to use this http://realterm.sourceforge.net/ It do things better than hyperterm. Just remember to get the endian format correct;)
  11. riad_00

    Thread Starter Member

    Feb 9, 2008

    I had a usb to serial converter and for the extension from the board - I was using a null modem (stupid me) all day without realising. And I had to change the codes a bit at the end
    Code ( (Unknown Language)):
    1.     printf("%u \r\n" , temp);
    using 'stdlib.h' instead 'putcUSART()'. Works like a dream.

    Next one would be drawing a nice analouge meter in .NET and connect it through serial.

    Tanks a lot.