PDA

View Full Version : Hyper Terminal Displaying Random Characters [PIC to PC via UART]



arson88
- 9th April 2011, 15:40
Hello everyone, this will be my first post.

I am using PIC16F77A to connect to a PC via UART but hyperterminal displays only 3 types of characters each time i push the push button: 1 unknown character, a dot and a space. My initial output should be 0 then incremented by 1 each time the push button is pressed.

Details:
The language used is PIC Basic Pro, Complier: MicroCode Studio Version 4.0, Assembler: Microchip/mpasm suite, MPLAB IDE v8.66
i used a uart to establish connection with a PC, Windows 7.

Coding:
INCLUDE “modedefs.bas” ‘ Serial communication mode definition file
DEFINE OSC 20 ‘ Oscillator speed is set to 20MHz
TRISB = %11111111
TRISC = %10000000 ‘ RC.7 => USART RX pin set to input
PortC = 0
SPBRG = 25 ‘ Baud Rate = 9600

‘ Variable definition
‘ ===================

DataOut var byte ‘ use to store TXREG content
DataIn var byte ‘ use to store RCREG content
DataIn = 0
DataOut = 0

mainloop:

TXSTA = $24 ‘ enable transmit and SPBRGH = 1
RCSTA = $90 ‘ Enable USART and continuous receive
datain = DataOut ‘ Get data

IF (PortB.7 = 1) THEN
DataOut = DataIn + 1
PAUSE 1000
DataIn = DataOut
TXREG = DataOut ‘ Transmit Data

HIGH PortD.2
PAUSE 2000
LOW PortD.2

ENDIF

GOTO mainloop
END

Dave
- 9th April 2011, 20:04
arson88 , If you want to see the characters received by the PC you should be running a terminal emulator program that will allow you to see the hex value of the received byte. I always use an old program called QMODEM which allows you to see any non printable characters like control characters. You do realize that there are more than 127 non printable characters that are possible to be sent via RS-232. I do not use Hyperterminal as the screen view is not big enough. There are a lot of other programs out there that will allow you to view the received byte value... Just look...

Dave Purola,
N8NTA

arson88
- 10th April 2011, 05:05
BTw, i am using http://www.cytron.com.my/viewProduct.php?pid=JB4nHTECFzU2KwsnABsbNvDwRDzznQ 7nn82zcVu7Ut0=
, a USB to UART Converter.

arson88
- 10th April 2011, 14:34
nvm, i got the program right..
INCLUDE “modedefs.bas” ‘ Serial communication mode definition file
DEFINE OSC 20 ‘ Oscillator speed is set to 20MHz
TRISB = %11111111
TRISC = %10000000 ‘ RC.7 => USART RX pin set to input
PortC = 0
SPBRG = 129 ‘ Baud Rate = 9600
‘ Variable definition
‘ ===================

count01 VAR BYTE ‘ variable to store TXREG content
TXSTA = %00100100 ‘ Enable transmit and asynchronous mode
RCSTA = %10010000 ‘ Enable serial port and continuous receive
mainloop:
IF (PortB.7 = 1) THEN
FOR count01 = 1 TO 30
PAUSE 2000
TXREG = count01 + $30 ‘ Transmit Data
HIGH PortD.2
PAUSE 2000
LOW PortD.2
Next
ENDIF
GOTO mainloop
END

The result displayed in Hyperterminal:
ASCII Character: 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ; < until the 30th ASCII Character
referred to page 203, PIC MCU With PICBasic [Chuck Hellebuyck]

How do i convert the ASCII characters i received via Visal Basic 2010's serial port into integers?

I used tiktakx's vb coding http://tiktakx.wordpress.com/2010/11/21/serial-port-interfacing-with-vb-net-2010/#comment-97

amgen
- 11th April 2011, 18:07
hyper-term recieves the bytes and displays them as ASCII chars. The bytes with decimal 0-31, hex 0-1F are generally considered control chars and are mostly not printed or handled except for a few chars such as CR- carrage return, LF- line feed and HT- tab ----dec#s 13,10 & 9. There are no set rules on how a PC program will handle these control chars when recieved. You have to know how the program was made or its settings.
To incriment a number to send to a PC use the # modifier on SEROUT which will send 1 char for 0 to 9, 2 chars for 10 to 99 and 3 chars for 100 to 255--- max value of 1 byte. You could write a routine to convert 1 byte to decimal digits but serout will do that with the modifiers.
1 more thing, hyper-term can send bytes in the range of 0-31 dec using copy/paste from word-pad with chars coded by 'altX' eg(typing 4 then altX changes the 4(ascii 52) to dec 4(ascii 4)) which can be copy/pasted to hyper-term to send.

don
amgen

mackrackit
- 13th April 2011, 11:24
INCLUDE “modedefs.bas” ‘ Serial communication mode definition file
Does nothing with the chip hardware serial port. Just takes up code space.


BTw, i am using http://www.cytron.com.my/viewProduct...7nn82zcVu7Ut0=
, a USB to UART Converter.
But does it invert the signal?

Archangel
- 15th April 2011, 03:09
Hyper-terminal: I don't use it.
RealTerm allows you the option of sending / receiving data either as RAW or ASCII.
as for how do I . . . are you attempting to send to PIC or send to PC ? If issue is sending to PC put numbers inside quotes like "2468" and pic will send ascii, or precede numbers with DEC2468 and it will go RAW, or HEX9A4 for hex.

As for Dave's (Mackracket) question, he is asking if the cytron thing inverts the serial data, as HSERin / out sends data TRUE with a pull up and PC likes INVERTED.

aratti
- 20th April 2011, 19:49
The OP needs to use a level converter as MAX 232 which also invert the signal.

Cheers


Al.

rmteo
- 21st April 2011, 05:03
How are you doing with LPCXpesso?