Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

16F688 USART and Hyperterminal data

Status
Not open for further replies.

newx2c

Newbie level 2
Joined
May 7, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
Hi,

I am using a 16f688 mc to read a temperature sensor and send the data to the HyperTerminal on a PC. So far I was successful in setting up the ADC and the UART to cmmunicate with the with the PC but not suuccessful with my lookup table yet. I can send characters to the PC with no problems but only one character at the time.
My question is how to send my data to the PC after reading the ADC value
For example 23•C or -10•C like a string I am using assambler, any ideas or suggestions?


Thanks,
 

U want to send the ascii of 2 and then the ascii of 3 etc etc to display it on the hyperterminal.
so, if u have an unsigned int say 'temperature', then u want to convert it to a string and send it to PC via uart.
in C what i will do is,

void temp_to_usrt(unsigned int q)
{
send_uart(48+(q/1000));q%=1000; //48 is the ascii of 0
send_uart(48+(q/100));q%=100;
send_uart(48+(q/10));q%=10;
send_uart(48+(q));
send_uart(248); //ascii of degree
send_uart(67); //ascii of letter C
}

the above function will convert the int to ascii of corresponding digits and will send one by one to PC ,msb first. After sending digits, it will send • and then C.
 
Last edited:
  • Like
Reactions: newx2c

    newx2c

    Points: 2
    Helpful Answer Positive Rating
Thanks vinodstanur ,
I will try this, so far no luck with my lookup table

]/thanks,

---------- Post added at 21:10 ---------- Previous post was at 20:19 ----------

Here is my code, ADC and USART are working properly the only problem is the lookup table i need to test my output for 0-255 (0.5 increments) since it is an 8 bits register. i do need some negative readings but for now I like to solve the positive first.
Any ideas or suggestions

Thanks,

;*******************************************************************************
Lookup MACRO table,off_var
movlw HIGH (table+1) ; load PCLATH with base of table
movwf PCLATH
movlw LOW (table+1) ; add offset to base
addwf off_var,w
btfsc STATUS,C ; if overflow
incf PCLATH,f ; increment PCLATH
call table ; perform table lookup
ENDM
;********************************************************************************

MESSAGE:
; sample analog input
Delay10us ; wait 10 us for acquisition time
banksel ADCON0 ; start conversion
bsf ADCON0,GO
waitadc btfsc ADCON0,NOT_DONE ; wait until done
goto waitadc
banksel ADRESH ; copy high bits of result
swapf ADRESH,w
banksel digit
movwf digit
;copy results to LEDs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;banksel PORTC ; to low nybble of output port
;movwf PORTC
;copy results to USART;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;call delay10

banksel TXSTA
BTFSS TXSTA, TRMT
GOTO $-1

;call delay10
Lookup temp_value, digit ; lookup pattern for port A
banksel TXREG
MOVWF TXREG

GOTO MESSAGE
;lookup table;;;;;;;;;;;;;;;;;;;;;;;;;;;
temp_value addwf PCL,f
retlw '0'
retlw '1'
retlw '2'
retlw '3'
retlw '4'
retlw '5'
retlw '6'
retlw '7'
retlw '8'
retlw '9'



end
 

which is the temperature sensor you used. Lm35 or any other sensor? If you are using lm35 you need to convert the hex value to its original voltage value. You can use this equation. V = adc value * 5/255. From the datasheet of your sensor you can easly calculate the exact temperature
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top