USART interfacing with PC

Status
Not open for further replies.
Okay, here's the skinny:
I plan to use the hardware USART in the 16F876A. The software shouldn't be too hard to figure out I just need to set up the BRG and play with the registers as the datasheet dictates, I just need to get a few questions answered:

I plan to at least begin figuring out the interfacing using Hyperterminal on the PC end. The MAX232 has hookups for Tx, Rx, CTS and RTS/DTR.

I have the option to either use RTS/DTR on the RTS line, or (believe it or not) the DTR line. Which would work for Hyperterminal?

More importantly, I know to hook up Rx to Rx and Tx to Tx, but what would I hook CTS and RTS/DTR up to?
 
Unless you need them for something special, don't bother connecting them. RX and TX is all you need for most things.
 
CTS & RTS are just flow control, they were designed to pause transmission if the receiving device wasn't ready for data (buffer full)
You may not require them.
 
Code:
More importantly, I know to hook up Rx to Rx and Tx to Tx

You'll probably get on better connecting Rx to Tx both ways
 
Code:
More importantly, I know to hook up Rx to Rx and Tx to Tx

You'll probably get on better connecting Rx to Tx both ways

But Rx and Tx (which I refer to) are printed on the prototyping board, so I suppose I hook them up Tx-Tx on the board itself.
 
Last edited:
But Rx and Tx (which I refer to) are printed on the prototyping board, so I suppose I hook them up Tx-Tx on the board itself.

It would seem strange to label a receive input as Tx on the basis the Tx output from the remote device connects to it.

When I see Rx I expect it to be the receive input and Tx is the transmit output. Connecting Tx-Tx says to me output to output.

However, I don't know what your prototyping board is. I guess if it's indicating the connection between the PIC USART and the line driver IC maybe they have done it that way?
 
Looking at the schematic for the PIC-P28 board the labels on the PCB next to the MAX232 IC are the level converted signals from the 9-pin D connector so you would need to connect it as I originally suggested.

PIC TX pin to MAX232 RX
PIC RX pin to MAX232 TX
 
If you are using a PICKit 2, then you don't need voltage switching devices to communicate with your PC via USART

**broken link removed**

Ok, so I hear what you are saying - the PICKit 2 will program almost every PIC known to man kind from 12Fs/16F's/18F's/dsPIC's/24F PIC's, but how do you use it for UART/USART communication with your PC? Well start off by opening the PICKit 2 programming software, and from the Tools menu, select UART Tool...

**broken link removed**

And providing you have the PIC connected to your PICKit2 correctly, then you can now send USART data directly between the two.

**broken link removed**
**broken link removed**

I did up a small tutorial explaining the process **broken link removed**
 
Ah, the sweet scent of victory. Well, that's what I *think* that smell is.

One final, quick question: I know you can use the typing ex. '10011001'b for Binary, 0x99 for Hex and d'153' for decimal, but what can you use to input ASCII characters? Using lookup tables by hand is a pain.
 

Attachments

  • working.JPG
    220.6 KB · Views: 357
Last edited:
Your examples suggest you're using assembly language. If that's the case, an ASCII literal constant operand looks like this;

Code:
        movlw   'H'             ; it can look like this
        call    Put232          ;
        movlw   a'e'            ; or it can look like these two
        call    Put232          ;
        movlw   a'l'            ;
        call    Put232          ;
You can also use lookup tables and a loop to print strings but there are a few caveats to watch out for. Plenty of good examples in Nigel's tutorials.

Other methods allow sending strings while storing them inline with your code.

Code:
;
;  examples for PIC 18F' devices
;
;
;  hyperterminal home, clear screen, print title
;
pTitle  macro   str             ; clear screen, print title
        call    PutString       ;
        db      h'1B',"[2J"     ; <esc>[2J ANSI sequence
        db      str,0           ; inline null terminated string table
        endm

PutStr  macro   str
        rcall   PutString       ;
        db      str,0           ; inline null terminated string table
        endm
;
;  example macro usage
;
        pTitle  "Hello\r\n\n"   ; clear screen + home cursor
        PutStr  "Menu\r\n"      ;
        PutStr  "<1> Config\r\n"
        PutStr  "<2> Set AOS\r\n"
        PutStr  "<X> Exit menu"
Code:
;******************************************************************
;
;  PutString - print in-line string via Stack and TBLPTR (18F)
;
;  string must be terminated with a 00 byte and does not need
;  to be word aligned
;
PutString
        movff   TOSL,TBLPTRL    ; copy return address into TBLPTR
        movff   TOSH,TBLPTRH    ;
        clrf    TBLPTRU         ; assume PIC with < 64-KB
PutNext
        tblrd   *+              ; get in-line string character
        movf    TABLAT,W        ; last character (00)?
        bz      PutExit         ; yes, exit, else
        rcall   Put232          ; print character
        bra     PutNext         ; and do another
PutExit
        btfsc   TBLPTRL,0       ; odd address?
        tblrd   *+              ; yes, make it even (fix PC)
        movf    TBLPTRH,W       ; setup new return address
        movwf   TOSH            ; 
        movf    TBLPTRL,W       ;
        movwf   TOSL            ;
        return                  ;
You can achieve the same functionality with 16F' devices but the code is quite different.

Regards, Mike
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…