Thread: Hyperterminal and MPLAB in C

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    30

    Hyperterminal and MPLAB in C

    Hi im sorry I am extremely new, I just started using C at my internship and am stuck on doing the basic code below and being able to communicate with the microcontroller p33FJ256GP710. I want to simply be prompted and then give it an integer for it to evaluate just to show my bosses that I can communicate with the microcontroller via hyperterminal prior to the full programming process. heres my code:

    Code:
    #include <stdio.h>
    int main()
    {
    int number;
    printf("you are being prompted for either a one or a zero");
    scanf("%d",&number);
    
    if (number==1)
    {
    printf("You put a 1!");
    }
    else if (number==0)
    {
    printf("You put a 0!");
    }
    else
    {
    printf("You put something besides a 1 or 0");
    }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Is this the code that is running on your embedded processor board? If it is how did you configure the serial port parameters? Are you sure that the printf() and scanf() routines are actually set to use the serial port for input and output?

    Jim

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    I am not sure. sorry I am literally brand new to programming yesterday. How would I change those to output in say an open hyperterminal file? Or is this completely wrong?

    Thank you for the very quick response!

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    More information: I am connected to the development board and am tyring to program a microncontroller. I am also connected via usb to my computer through a COM port which I am connected to hyperterminal with. Any other questions please feel free to ask me, sorry again I am not quite in with what exactly occurs during programming but hey i'm hoping to learn.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Have you looked through your documentation for MPLAB? There are instructions in the "C Compiler Getting Started Guide" that may help.

    Jim

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Ah I see I will take a look here. I am using C-30 I will look the starter guide for that. Thank you Jim.

  7. #7
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Hey if anyone else has any pointers I really need them. NOne of those had any information about Serial Ports except using MPLAB SIM which I've already done. I need to use hyperterminal, if theres anything anyone thinks might work that would help a lot. I have two days to do this and am not sure at all how to do this at all.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Do you have a link to the board you're using?

    For a newbie programmer, I'd be looking at getting these things working first
    - light a LED
    - flash a LED
    - Output a constant stream of 'A' to the serial port (which you should then see on hyperterminal)
    - The "echo" program which reads from the serial port, and sends it back out to the serial port (you see what you type on hyperterminal)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    Its a pumpkin CUBESat development board. I cannot find any of these kinds of files, how would I get text to be printed in hyperterminal in the first place? Like does printf automatically print out in the hypertermnial or do i have to switch the output somehow? Thank you.

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    First find a schematic or at least a pin out for the development board connectors!
    You NEED to figure out which pins/ports on the MCU are able to be used for serial communications.

    Second find serial code examples for this MCU or a closely related MCU.

    NOTE: I am guessing you all ready have the MCU manual from MicroChip; if NOT please get that before doing any other thing.

    NOTE: Looking for development manuals from board manufactor is also a good thing to do.

    NOTE: In 10 minutes, I found this link http://www.pumpkininc.com/forums/viewforum.php?f=12

    And this one to the pdf of the User Manual: http://www.pumpkininc.com/cubesat/do...tkitmanual.pdf

    Tim S.
    Last edited by stahta01; 02-12-2013 at 01:43 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about asking here -> Pumpkin, Inc. &bull; Index page
    Your issue seems to be largely one of "how do I code, compile, test and download" to the target board.
    For one thing, you're sure to find people who have a detailed knowledge of that particular DB (which we don't have).

    I've looked on CubeSat Kit Home, read the specs for your DB and it seems there isn't a single LED to provide any kind of feedback
    Yes, it would be possible to wire a LED to one of the I/O lines, but describing how to do that seems to be inviting disaster at the moment.

    > how would I get text to be printed in hyperterminal in the first place?
    Well that really depends on the run-time library you link your code with.
    If that library maps stdin and stdout to the serial port, then it should just work.
    On the other hand, maybe stdio is non-existent on the DB and you're on your own, and you have to roll the code yourself to talk to the serial port.
    These are questions that the people on the support forum will be able to answer instantly.

    All we can do is read the same info you're reading and maybe make slightly better informed guesses. Fun that may be, but it won't move you forward.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Feb 2013
    Posts
    30
    OK thank you guys! I will try that forum, and yes I have both of those manuals. So it does have to do with some pin connections, I firgured it wouldn't be all that simple. OK well thank you very much!

  13. #13
    Registered User
    Join Date
    Dec 2012
    Posts
    307
    my question is, your showing your boss that you can do this, using hyper to talk to a pic, when you have no idea how to do it?
    how did you get the internship, that seems to be microcontroller programming, and control, if you have no background in this?

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    usually with a pic there isn't standard input/output. instead there are low level calls to read and write characters to the serial port. printf almost certainly does not work. if you want formatted I/O, use sprintf then output to the serial port using the low level calls.
    Initialization is dependent on what your board supports, but the PIC chip has the uart built in so their library calls are usually all
    you need.
    like everyone said, use the documentation that came with your board.
    Code:
    // example non-interrupt initialization code called once at startup
    // if you want polled mode
        UARTConfigure     (UART1, UART_ENABLE_PINS_TX_RX_ONLY | UART_ENABLE_HIGH_SPEED | UART_INVERT_TRANSMIT_POLARITY | UART_INVERT_RECEIVE_POLARITY);
        UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
        UARTSetDataRate   (UART1, GetPeripheralClock(), baud);
        UARTEnable        (UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
    
    
    // transmit a byte
    if (UARTTransmitterIsReady(UART1)) UARTSendDataByte(UART1,(BYTE)b);
    
    // receive a byte
    if (UARTReceivedDataIsAvailable(UART1))  b = UARTGetDataByte(UART1);

  15. #15
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by dmh2000 View Post
    usually with a pic there isn't standard input/output. instead there are low level calls to read and write characters to the serial port. printf almost certainly does not work.
    Yes there is, if you include <stdio.h> -> As long as you have manually set up USART1/UART1, you can most definitely use functions like printf, puts, fgetc, ... - If you are not using the standard library's, you are not making portable code.

    If you would like to change the output (say to I2C, SPI, ...), you define your own output destination in the file \src\traditional\stdclib\_user_putc.c and use the stream _H_USER

    I'm currently using MPLAB with the C18 Compiler with stdio.h
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 08-02-2012, 06:15 PM
  2. how its done(hyperterminal)?
    By stefan63 in forum Windows Programming
    Replies: 17
    Last Post: 03-25-2011, 04:24 AM
  3. mplab ide
    By russ4789 in forum C Programming
    Replies: 0
    Last Post: 03-29-2009, 09:05 AM
  4. C30 Compiler for MPLAB
    By Dukefrukem in forum C Programming
    Replies: 1
    Last Post: 11-08-2007, 07:40 PM
  5. Hyperterminal????
    By gvector1 in forum C# Programming
    Replies: 3
    Last Post: 01-22-2004, 08:54 PM

Tags for this Thread