PDA

View Full Version : serial communication problem



kindaichi
- 5th March 2010, 08:09
hi.. i'm doing a project which use mcp9700 to measure temperature interfacing with pic18f46k20, then display on LCD and hyper terminal..here's my code PICBasic below:


INCLUDE "modedefs.bas"
define osc 4
define LCD_DREG PORTD
define LCD_DBIT 4
define LCD_RSREG PORTD
DEFINE LCD_RSBIT 2
define LCD_EREG PORTD
define LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
'HIGH PORTD.1
C VAR WORD



DEFINE HSER_BAUD 9600 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
DEFINE HSER_SPBRG 25 'Hser spbrg init
DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 20h 'Hser transmit status init
DEFINE HSER_EVEN 1 'Use only if even parity desired
DEFINE HSER_ODD 1 'Use only if odd parity desired
DEFINE HSER_BITS 9 'Use 9th bit for parity



define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50

lmtemp var word
temp var word
quanta con 1250
TRISE = %111
ADCON1 = 0


MAIN:
ADCIN 6, lmtemp
temp = ((lmtemp/100)/2)+8-50

LCDOUT $FE,1
LCDOUT " Programmed by"
LCDOUT $FE,$C0
lcdout "YAN^S TEMP="
LCDOUT #temp
LCDOUT " C"
'HIGH PORTD.1


HSEROUT [dec temp,10]
'HSerout ["The Temp Are Now ",#temp,"C",13]


pause 100
GOTO MAIN
end

is it correct my code??
LCD is working fine but i have a problem to display at hyper terminal

i hope somebody can help me...

mackrackit
- 5th March 2010, 12:27
These sorta conflict...


DEFINE HSER_EVEN 1 'Use only if even parity desired
DEFINE HSER_ODD 1 'Use only if odd parity desired

Is the PC set for 8,N,1 at 9600?
What speed is the PIC running at?

kindaichi
- 7th March 2010, 13:38
hii..thanx for replying..

yup, i set the PC for 8,N,1 at 9600 and the speed is 4Mhz

mackrackit
- 7th March 2010, 14:42
Try these settings


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 9600 Baud @ 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

aratti
- 7th March 2010, 16:04
Since your temperature will never be higher then 255 °C (I assume) then set your variable "temp" as a byte not word.

temp var byte

because serially you cannot Tx word but only byte.

Al.

Archangel
- 7th March 2010, 17:56
Since your temperature will never be higher then 255 °C (I assume) then set your variable "temp" as a byte not word.

temp var byte

because serially you cannot Tx word but only byte.

Al.
Hi Al, Can he not send a word out as 2 bytes, like so . . .
Hserout [Temp.HighByte, Temp.LowByte,10] ?

aratti
- 7th March 2010, 22:52
Hi Joe, Yes he can. But he would not be able to recombine them back to a word, using hyperterminal.

Al.

Archangel
- 7th March 2010, 22:58
Hi Joe, Yes he can. But he would not be able to recombine them back to a word, using hyperterminal.

Al.
OK I buy that, I really asked the question so as to get your answer, so when someone wanders into this thread looking for answers, they understand it this way.
Thanks Al

kindaichi
- 8th March 2010, 17:23
hi guys.. i still hv a problem..i just change my code..here's below

INCLUDE "modedefs.bas"
define FOSC 4
define LCD_DREG PORTD
define LCD_DBIT 4
define LCD_RSREG PORTD
DEFINE LCD_RSBIT 2
define LCD_EREG PORTD
define LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
'HIGH PORTD.1
C VAR WORD


TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 9600 Baud @ 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50

lmtemp var word
temp var byte
quanta con 1250
TRISE = %111
ADCON1 = 0


MAIN:
ADCIN 6, lmtemp
temp = ((lmtemp/100)/2)+8-50
'PORTD.1=1
'C=PORTD.1
'LOW PORTD.1
LCDOUT $FE,1
LCDOUT " Programmed by"
LCDOUT $FE,$C0
lcdout "YAN^S TEMP="
LCDOUT #temp
LCDOUT " C"
'HIGH PORTD.1


HSEROUT [dec temp,10]
HSerout ["The Temp Are Now ",#temp,"C",13]


pause 100
GOTO MAIN
end

it will display something like this... xøxøxxxxø€øøøxxx€x€€ø€€øxøxxxxø€øøøxxx€

is it correct my temperature equation??i think it is not..when i measured voltage, i get 0.81V and it's display 36 C..it suppose display 30 C..how analog voltage convert to digital and what exactly temperature equation to be write into my code??

mcp9700 sensors is an analog signal that is directly proportional (linear) to the temperature and the output voltage is a direct indication of the temperature in 10mV/°C.

plz help me..it's urgent..the due date is next week 15 march..
thanx..

aratti
- 8th March 2010, 18:11
You should first scale lmtemp to volts

Volts = Imtemp/205 [ 205 = 1/(5/1023))]

Than since your sensor Vout = (Tci * Ta) + V0°C

where: Tci = 10 milliVolts and V0°C = 0.5 Volts

Ta= (Vout-0.5)/0.01

Ta = (Vout - 0.5) * 100

Ta = (Vout*100)-50

Al.

mackrackit
- 8th March 2010, 18:12
Sounds like you need to invert the signal.
You can use a MAX232 or a transistor with a couple resistors.

kindaichi
- 9th March 2010, 15:36
hi aratti...i hv tried to change my temp equation from your information but the temperature still not showing correctly..can you plz check my code..

INCLUDE "modedefs.bas"
define FOSC 4
define LCD_DREG PORTD
define LCD_DBIT 4
define LCD_RSREG PORTD
DEFINE LCD_RSBIT 2
define LCD_EREG PORTD
define LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
'HIGH PORTD.1
C VAR WORD


TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 9600 Baud @ 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50

lmtemp var word
temp var byte
vout var byte
quanta con 1250
TRISE = %111
ADCON1 = 0


MAIN:

ADCIN 6, lmtemp
vout = lmtemp/205
temp = (Vout*100)-50

LCDOUT $FE,1
LCDOUT " Programmed by"
LCDOUT $FE,$C0
lcdout "YAN^S TEMP="
LCDOUT #temp
LCDOUT " C"
'HIGH PORTD.1


HSEROUT [dec temp,10]
HSerout ["The Temp Are Now ",#temp,"C",13]


pause 100
GOTO MAIN
end

tq very much...

aratti
- 9th March 2010, 17:07
Try this way:



ADCIN 6, lmtemp
vout =(lmtemp*100)/205
temp = Vout-50


Or if you need decimals



ADCIN 6, lmtemp
vout =(lmtemp*49)-5000
Integer_Byte = Vout/100
Decimal_Byte = Vout//100
Hserout ["Temp = ",Dec Integer_Byte,".",Dec2 Decimal_Byte," °C",13,10]


Make Vout a word variable ; Interger_Byte and Decimal_Byte byte variables

Al.

kindaichi
- 11th March 2010, 16:37
hi guys..my project is working now..thanks a lot because helping me...
i love this forum n i really appreciate that..:D