Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F88 serial com. with hyper terminal

Status
Not open for further replies.

SuperveS

New Member
Hi guys,

need some help with a school assignment.

I need to type two numbers between 1-7 in the hyperterminal,
and the PIC should recive them send back the sum of those numbers and display it on the screen.

For some reason i dont even see the figures i type in the H-terminal,
and i get no feedback from the PIC,

I attached the code i wrote,

I need your help and comments,
It doesnt work at all....

THANKS!
 

Attachments

  • Untitled.asm
    939 bytes · Views: 123
Here is the code again:

#INCLUDE "p16F88.inc"

inA equ 0x24 ;reception of first number
inB equ 0x25 ; reception of second number
sumAB equ 0x26 ; reception the sum of the two numbers

;================= Start of Code =================
org 0
goto Start

org 5
Start




banksel TXSTA
movlw B'00100100'
movwf TXSTA

movlw D'25' ;sets band to 9600 b/s
movwf SPBRG

movlw 00
movwf TRISB ;set port B as Output

banksel RCSTA
movlw B'10010000'
movwf RCSTA

loop

banksel PIR1
firstReadingLoop
btfss PIR1,RCIF ;RCIF is set when reception is complete
goto firstReadingLoop
movf RCREG,0 ; aquired data is stored in RCREG
movwf inA

secondReadingLoop
btfss PIR1,RCIF
goto secondReadingLoop
movf RCREG,0
movwf inB

addwf inA,0
movwf TXREG ;w holds the sum of 2 inputs A,B.


transmit
btfss PIR1, TXIF
goto transmit
movwf TXREG


goto loop


end
 
Problem 1: RX needs to be an input on portB, so change the tris accordingly. Secondly, you send the byte then check the interupt flag
transmit
btfss PIR1, TXIF
goto transmit
movwf TXREG

This does the opposite, also you should clear the flag prior to sending the byte, like this:

transmit
bcf PIR1,TXIF ; clear flag
movwf TXREG ; send out data
btfss PIR1, TXIF ; check if done sending
goto $-1 ; nope not done yet, go to previous instruction and check again
 
hi
Look at this, it now works in the Oshonsoft simulator.
I have removed the 2nd character RX for my tests.

Note from your PC keyboard you send ASCII characters, so '1' = 0x31
So when you send say '3' and '7' the added result will not be 10.

OK.?


Code:
    list      p=16f88           ; list directive to define processor
    #include <p16F88.inc>        ; processor specific variable definitions
    errorlevel  -302 , -207             ; suppress messages 302 [Bank] and 207 [label in column 1]

inA    equ    0x24        ;reception of first number
inB    equ    0x25        ; reception of second number
sumAB    equ    0x26        ; reception the sum of the two numbers

;================= Start of Code =================  
    org    0
    goto    Start

    org    4

Start
    banksel    TXSTA
    movlw    B'00100100'
    movwf    TXSTA

    movlw    D'25'        ;sets band to 9600 b/s
    movwf    SPBRG

    movlw    00
    movwf    TRISB        ;set port B as Output

    banksel    RCSTA
    movlw    B'10010000'
    movwf    RCSTA

loop

    banksel    PIR1
        
firstReadingLoop 
    btfss    PIR1,RCIF    ;RCIF is set when reception is complete
    goto    firstReadingLoop
    
    movf    RCREG,W    ; aquired data is stored in RCREG
    movwf    inA

transmit 
    btfss    PIR1, TXIF 
    goto    transmit  
    
    movwf    TXREG        ;w holds the sum of 2 inputs A,B.
             
    goto    loop


    end
 
Hi guys,

Thanks for your help.
I am still stuck at the same problem.

I am just trying to write data on the H-terminal.
I connected the output to an oscilloscope and im sending 0x55 (01010101) and i can see that
it is transmitting fine.

also checked the other end of the COM Cable, that goes into the computer.
the problem is that nothing comes out on the H-terminal screen.

here is the short code:

movlw 0x55
banksel TXREG
movwf TXREG

banksel PIR1
transmit
btfss PIR1, TXIF
goto transmit


Thanks !
 
hi,
Do you have a MAX232 IC between the PC and the PIC.????
 
Dont know what it is... but i have nothing connected between the PC in the PIC...Just the Com. cable.

hi,
The voltage levels from the PIC on the UART are +5V and 0V which are not compatible with the PC's UART.

You need a MAX232 or similar on the output of the PIC before the cable. RS232 UART levels on a PC are approx +9/-9V
 
Last edited:
Thanks Eric,

I asked my instructor,
Turns out the MAX232 is in place.

the problem was that i was transmiting 0x55 which has no output char in Ascii,
so i just changed it into a different number and it works.
Transmitting problem is over.

Now for receiveing and adding the two numbers i use the following code:
banksel PIR1
firstReadingLoop
btfss PIR1,RCIF ;RCIF is set when reception is complete
goto firstReadingLoop
movf RCREG,0 ; aquired data is stored in RCREG
movwf inA

secondReadingLoop
btfss PIR1,RCIF
goto secondReadingLoop
movf RCREG,0
movwf inB

addwf inA,0 ;w holds the sum of 2 inputs A,B.

doesnt really work...

any suggestions?
 
Why doesn't it work?
Dont forget that if you type 2 numbers, 3 and 4 for example, that will be transmitted as 0x33 and 0x34.
Which would make 0x67 which would be 'C'. Could this be the problem?

If you know you are only receiving numbers you could read in the number subtract 48 (decimal of 0x30) then add the 2 together then add 48 to print the acscii.

EXAMPLE:
A = 3, B = 2
Read in A
subtract 48 (Decimal) / 30 (Hex) from A, 0x33 = 51 (Decimal) - 48 = 3
Read in B
subtract 48 (Decimal) / 30 (Hex) from B, 0x32 = 50 (Decimal) - 48 = 2

Add A + B = 3 + 2 = 5
Add 48 (Decimal) / 0x30 (Hex) to 5 = 53 (Decimal) = 0x35 (Hex) = ASCII 5.

Hope this helps?
Wilksey
 
hi S,
When you say you are transmitting 0x55, which keys on the PC are you pressing to send that to the PIC.??

If you are added two RXD characters together, what are the characters you are adding.??
 
Last edited:
Hi guys,

When i transmitted 0x55 i did it as a part of the program - "hard coded", this was just to see that the transmition section works.
When i saw its working ok i deleted the hard coded 0x55 and now i am trying to transmit the sum of the inputs ranging 1-4.
I dond really mind about ascii values caus i know for sure that the input is in that range, and for starters i would accpet any output...

the problem now is, that i cant get the PIC to store the two inputs and post the sum of them on the H-terminal

this the the code i wrote:

banksel PIR1
firstReadingLoop
btfss PIR1,RCIF ;RCIF is set when reception is complete
goto firstReadingLoop

movf RCREG,0 ; aquired data is stored in RCREG
movwf inA

secondReadingLoop
btfss PIR1,RCIF
goto secondReadingLoop
movf RCREG,0
movwf inB

addwf inA,0 ;w holds the sum of 2 inputs A,B.

Thanks Again!
 
hi,
This program works OK in Oshonsoft.

If I transmit the first character as '1' [ascii] and the second character also '1' [ascii], after adding I get 0x62 , in Wreg which when sent back to the PC as a transmitted character, I see 'b' [ 0x62 ,, decimal 98] which is correct.


Code:
    list      p=16f88           ; list directive to define processor
    #include <p16F88.inc>        ; processor specific variable definitions
    errorlevel  -302 , -207             ; suppress messages 302 [Bank] and 207 [label in column 1]

inA    equ    0x24        ;reception of first number
inB    equ    0x25        ; reception of second number
sumAB    equ    0x26        ; reception the sum of the two numbers

;================= Start of Code =================  
    org    0
    goto    Start

    org    4

Start
    banksel    TXSTA
    movlw    B'00100100'
    movwf    TXSTA

    movlw    D'25'        ;sets band to 9600 b/s
    movwf    SPBRG

    movlw    00
    movwf    TRISB        ;set port B as Output

    banksel    RCSTA
    movlw    B'10010000'
    movwf    RCSTA

loop
    banksel PIR1
firstReadingLoop
    btfss PIR1,RCIF ;RCIF is set when reception is complete
    goto firstReadingLoop

    movf RCREG,W ; aquired data is stored in RCREG
    movwf inA
    
secondReadingLoop
    btfss PIR1,RCIF
    goto secondReadingLoop
    movf RCREG,W
    movwf inB

    addwf inA,W ;w holds the sum of 2 inputs A,B.

 dw 1
    banksel    PIR1
        
transmit 
    btfss    PIR1, TXIF 
    goto    transmit  
    
    movwf    TXREG        ;w holds the sum of 2 inputs A,B.
             
    goto    loop


    end
 
Eric you ignored what I said! 1 + 1 will work but 1 + 2 will not for example, it would give you 1 + 1 (repeat of the first character) It's important to clear the RXIF, it's not done in hardware!
 
Eric you ignored what I said! 1 + 1 will work but 1 + 2 will not for example, it would give you 1 + 1 (repeat of the first character) It's important to clear the RXIF, it's not done in hardware!

hi Boo,
Reading movf RCREG,W clears the RXD register, try running the program.

The TX/RX intr have not been enabled.

EDIT:
Modified the program just to echo the PC to PIC characters and the summed response.

000esp03.gif
 

Attachments

  • 000esp01.gif
    000esp01.gif
    10.5 KB · Views: 151
  • 000esp02.gif
    000esp02.gif
    16.4 KB · Views: 160
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top