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.

Reading a LM35 using usb and 18f2550

Status
Not open for further replies.

be80be

Well-Known Member
I figure some one could use this it's in swordfish basic it reads the adc value and sends it
to A VB program that shows the temperature Celsius
The function you'll need to change 4300 to match your adc VREF+ if using Vdd take a reading and plug that in

Like say you get 4.99 volts you'll change 4300 to 4990
Code:
// device and clock...
Device = 18F2550
Clock = 48

// 20Mhz crystal, 48Mhz internal (FS USB)
Config
   PLLDIV = 5,
   CPUDIV = OSC1_PLL2,
   USBDIV = 2,
   FOSC = HSPLL_HS,
   VREGEN = ON
      
// import modules...
Include "usbcdc.bas"
Include "ADC.bas"
Include "convert.bas"
// this event will fire if the DTR line
// from the PC is set or cleared...
// read the AD port and scale for 0 - 5 volts...
Function ADC_value() As Word
    
        result = ((ADC.Read(0)*4300)/1023)/10     
End Function


Dim ADVal As Word
Dim temp As Word

// main program loop - this just simply reads a byte from a
// terminal window (for example, SerialCommunicator) and then
// echo it back...
TRISA = %00000001        // configure AN0 as an input 
ADCON1 = %00001110       // set analogue input on PORTA.0 
While true
     temp = ADC_value
    
      DelayMS(100)
      Writebyte(temp)
        DelayMS(1000)
Wend

And a look at plus the whole VB program
 

Attachments

  • Like_this_temp.JPG
    Like_this_temp.JPG
    11.6 KB · Views: 1,263
  • temp.zip
    200.4 KB · Views: 454
Last edited:
I post the whole Vb source code if some one wants it.

Bill the LM35 is real simple but you get very good readings.

I like the idea of just using one chip and plugging it in the usb. I wanted to use some 18f14k50 20 pin chips with usb but I have to change my inc files.
 
Last edited:
I post the whole Vb source code if some one wants it.

Yes please Burt.

Very cool project, never thought of bringing the temperature back through USB, always used a 232 to USB converter.

I guess with the ever growing list of PIC's with USB built in it is something that is worth considering!

Is it VB.NET? What version did you compile with? 2010, 2008, Express, std, pro, etc?

Regards

Wilksey
 
Nice works. Looks like a cool project man.

I'm getting in to the 18F's and I have some on order with USB integrated. (the 18F4550) How difficult is it to get the USB working?

What all options are there to get it interacting with the computer other than writing something a program like VISUAL BASIC? Is there a USB equivalent to the old hyperterminal program to enable easy testing?
 
Yes please Burt....I thought u were a JAL fan tho'
Mosaic I'm a broke swordfish man who started using jalv2 because it's free and has usb library. But for Xmas we had some extra money so dad got swordfish basic. I use them both.

It's visual basic 2008 express I haven't used it much just vb6 a Jalv2 friend gave me and example of how to use serial coms and I remade the program with it. Here the whole thing.
 

Attachments

  • Temp Example.zip
    322.5 KB · Views: 375
Last edited:
wannaBinventor I use this for testing Terminal v1.9b it's great but finding it is hard LOL https://sites.google.com/site/terminalbpp/

You can do a lot with it even program pic chips. I have not tried that but I would say you could do it

Bill they have Added Ethernet & SLIP. libs and samples to jalv2 now

It works with one of these ENC28J60 28j60 Ethernet LAN Module for AVR PIC ARM MCU
 
Last edited:
Thanks Burt!

I tried JAL, but never really got into it.

Does it have any real benefit over using a C compiler or something like Swordfish for example?

I have noticed that Swordfish SE doesn't have the USB library in it, where as Swordfish paid for does, unless i'm missing something?

Also they dont seem to be including the ethernet stuff, I guess it would be very time consuming to port the TCPIP Stack across.

Anyways, thanks again for the code!

As you are using a CDC I presume it would just come up as a COM port?

Could you also please post the HEX so I can run it up in Proteus?

Wilksey
 
Jalv2 has some of the best documentation and sample to learn by and it's free. The bad part is it's like on three sites jallib jalv2 and jaledit. C is maybe the best thing to learn if your going to program for living. Basic is more for hobbyist like me.

Back to the LM35 and usb It's using usb to make a com port here the hex
 

Attachments

  • CDCSerialCOM_1.HEX
    10.5 KB · Views: 195
Status
Not open for further replies.

Latest threads

Back
Top