+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2011
    Posts
    4

    Default can you help me with my project (PIC & temperature sensor & LCD)?

    Hi everyone. I'm doing this hobby PIC project, basically it's a thermometer with LCD. I found both a schematics and code (hex file) in some well-known electronics related magazine and i decided to give it a shot. I should add I've never had any experience with uc, especially not PICs. The project didn't seem too difficult and it consists of only 3 IC (a pic, a sensor and DC-DC voltage regulator) , LCD display and a few other usual components. The schematic is attached below.

    So i bought all the electronic components, PIC 16f786a and PIC Kit 3 (for programming my PIC). What i've done so far: I programmed my PIC (downloaded the 'hex' file and wrote it into the chip with pickit3) and set the project on a breadboard (protoboard) so that i could test it first. The problem is that it doesn't work. The LCD display doesn't seem to be turned on at all. Now, if i assume that all components are connected correctly (on the breadboard), then I guess the problem might only be in one (or more) of those three parts: PIC (and the code), LCD or the sensor. Like i said, i didn't write the code, but i believe it's written correctly (as i got it from the original author of that project (it was written in MikroBasic)). So checking the code would be the last thing for me to do. I want to check "hardware" parts first. So i decided to test those parts of the circuit, starting with LCD display.

    My questions are:

    1.) LCD: Any idea where to get a code or hex file for testing my LCD? I basically just want to see if it's working and i need some easy and quick test. Like "hello world" written on display or something. My LCD is 20 x 4 using standard 4-bit interface interface (HD44780 or KS066). Power supply (Vdd) is 5V.

    2.) PIC & sensor: The temperature sensor I'm using is a very good one. It has internal ADC, RAM, DSP and it can work in two possible modes. The output temperature is already in digital form (15 bit word). Communicating between PIC and my sensor is via SMBus (very similar to I2C). As you can see on the schematic, the temperature sensor is connected to PIC via 2 pins: SCL (RC3) and SDA (RC4). If i understand correctly, PIC is Master (who provides clock signal) and the sensor is Slave. I checked SCL pin, which is supposed to be 'clock', but on oscilloscope it DOESN'T look like it at all. It's rather a DC signal (around 4,5V; power supply for the sensor, PIC and LCD is 5V) with some noise. So this is surely one of the problems. Any ideas what should I do next?

    Any other advices or help would really be appreciated!
    Attached Images Attached Images  

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,819

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    hERE IS A HEX WHICH SHOULD WORK AS YOUR SCHEMATIC IS WIRED
    sorry about the all caps

    :020000040000FA
    :04000000B401EC2833
    :08000800F000030E8301BC00AF
    :100010000A08B70000308A00FD2898181812181630
    :1000200064008C1E10281A080314E728A501A400F8
    :10003000B6172730A300103029200330A300E83082
    :100040002920A30164302920A3010A302920240893
    :100050003428A2002508A1002408A000C6202008FA
    :10006000031DB613B61B0800303E37280408A7004E
    :1000700006130710071083160613071007100F301A
    :10008000870583122708B41862283A30A100FC3093
    :100090009B203330A60076201030A10068309B20D2
    :1000A000762064309A202230A60076202830612005
    :1000B0000C3061200130612006306120B414270823
    :1000C00062283414A600341C70280710033C031C5B
    :1000D000752875200730A100D0309B20031408003C
    :1000E0003414FE3C0319E7280714341C3410061797
    :1000F0000F3087052608F03987040613A60E34183A
    :10010000762832309A2003140800A400A9080319A5
    :10011000E7282408E220A9038728A301A200FF30D2
    :10012000A207031CA307031CE7280330A100E63045
    :100130009B208F28A101FC3EA000A109031CA6283A
    :10014000FF300000A0070318A128A0076400A10F3A
    :10015000A0280800B3200319B1282308A100220811
    :10016000A00020080800A2000130B628A80023083B
    :100170002102031DBD28220820020430031801308B
    :10018000031902302805031DFF30E728A501A4014B
    :100190001030A600210DA40DA50D2208A4022308ED
    :1001A000031C230FA5020318DC282208A407230838
    :1001B0000318230FA5070310A00DA10DA60BCA2835
    :1001C0002008E728840031088A0030088200831361
    :1001D00003138312640008008316813099002030D5
    :1001E0009800831290309800831602308600FF300A
    :1001F00085003730950083121C290408B500531080
    :10020000640083168C1E0F2983128C1E0F29531431
    :100210000E30B2000130B3008A11082B8301830134
    :100220005318FF2883013508840037088A003C0EE4
    :100230008300F00E700E09000B178B178C128316BB
    :100240008C1683129F0183169F01831203179E0150
    :100250009F0199019A0103130508CF004F08083C3C
    :100260008A11031C402901308A004F0882074D2B58
    :100270005C2B6C2B7A2B8A2B9A2BA92BB82BC72B98
    :100280003D0898003F0883169800831241088316A2
    :1002900099008312D101D201D0010130CB00053089
    :1002A000A300DC308A018E20FE308A013720013025
    :1002B0008A013720FE308A01372002308A01372038
    :1002C00020308A01372020308A01372043308A01CC
    :1002D00037206F308A01372070308A01372079301B
    :1002E0008A01372072308A01372069308A0137202D
    :1002F00067308A01372068308A01372074308A01DC
    :10030000372020308A01372032308A0137203030C0
    :100310008A01372030308A01372036308A01372071
    :1003200020308A01372020308A01372020308A018E
    :10033000372020308A013720FE308A013720C03034
    :100340008A01372053308A01372054308A01372000
    :100350004F308A0137204B308A01372045308A01DF
    :10036000372053308A01372020308A0137204D3022
    :100370008A01372041308A0137204E308A013720E8
    :1003800055308A01372046308A01372041308A01B2
    :10039000372043308A01372054308A0137205530C6
    :1003A0008A01372052308A01372049308A013720AC
    :1003B0004E308A01372047308A013720FE308A01CB
    :1003C000372094308A0137204408A50043088A0169
    :1003D00017204D088A01162020308A01372042302C
    :1003E0008A01372041308A01372055308A01372071
    :1003F00044308A01372020308A01372038308A0182
    :10040000372020308A0137204E308A0137202030B3
    :100410008A01372031308A01372020308A01372085
    :1004200020308A0137200B30A300B8308A018E209B
    :10043000FE308A01372001308A01372002308A01DC
    :100440008D2064004E088A11031D642A640051083F
    :1004500052028A1103191E2A8A114F224A088A0160
    :100460003720640015304B028A11031C4D2A0130DD
    :10047000CB00FE308A013720C0308A01372014308B
    :10048000A9003630B000B10120308A018520FE304D
    :100490008A01372002308A0137208A01212A8316F7
    :1004A0008C128312D20A6400403052028A11031C5B
    :1004B0005A2AD2015208A03E84000008CA008C12B9
    :1004C00083168C168312080064008A11CE1CBE2A83
    :1004D000FE308A013720C0308A01372043308A013C
    :1004E00037206C308A01372065308A01372061302F
    :1004F0008A01372072308A01372069308A0137201B
    :100500006E308A01372067308A01372020308A0117
    :10051000372044308A01372069308A013720733010
    :100520008A01372070308A0137206C308A013720E9
    :1005300061308A01372079308A01372020308A01E2
    :10054000372020308A01372020308A0137202030A0
    :100550008A01372042308A01372075308A013720DE
    :1005600066308A01372066308A01372065308A017B
    :10057000372072308A0137208A11EB2AFE308A0137
    :100580003720D4308A01372055308A013720533044
    :100590008A01372041308A01372052308A013720C2
    :1005A00054308A01372020308A0137204F308A01A9
    :1005B000372076308A01372065308A013720723043
    :1005C0008A01372072308A01372075308A0137203E
    :1005D0006E308A013720FE308A01372001308A01CF
    :1005E00037200230D000640050084B028A11031CEF
    :1005F000032BFE308A01372014308A013720D00ABD
    :100600008A11031DF32ACE01181218168A01212A15
    :1006100064008A119818452BD10A640040305102B9
    :100620008A11031C142BD1016400510852028A1153
    :1006300003192B2B8A010D20C500C6015108A03ECD
    :1006400084004508800064008A118C1A082B330846
    :100650008A0032088200CE14FF305107C500FF30F7
    :100660000318013EC6003F30A000A1014608A300C8
    :1006700045088A01AA20D1008A010D20C500C601C3
    :100680005108A03E8400450880004E1433088A00BB
    :100690003208820063008A014A2B9030BD00BE01FF
    :1006A0002430BF00C0010A30C100C201C3012D3097
    :1006B000C400CD018A0140299030BD00BE01243024
    :1006C000BF00C0011530C100C2018030C300163028
    :1006D000C400CD018A0140299030BD00BE01243004
    :1006E000BF00C0012030C100C201C3010F30C400EF
    :1006F000CD0108009030BD00BE012430BF00C00114
    :100700004030C100C2018030C3000730C400CD01B9
    :100710008A0140299030BD00BE012430BF00C001D5
    :100720008130C100C201C030C3000330C400CD011C
    :100730008A0140299030BD00BE012030BF00C001B9
    :100740004030C100C201E030C3000130C400CD011F
    :1007500008009030BD00BE012030BF00C0018130D4
    :10076000C100C201F030C300C401CD018A0140299B
    :100770009030BD00BE012030BF00C001FF30C1007D
    :10078000C2017830C300C401CD018A014029FE3086
    :100790008A01372080308A01372020308A013720B3
    :1007A00045308A01372072308A01372072308A0141
    :1007B00037206F308A01372072308A0137202C3081
    :1007C0008A01372020308A01372063308A013720A0
    :1007D00068308A01372065308A01372063308A010A
    :1007E00037206B308A01372020308A013720623071
    :1007F0008A01372061308A01372075308A0137201D
    :1008000064308A013720FE308A013720C0308A01E7
    :10081000372020308A01372073308A013720653035
    :100820008A01372074308A01372074308A013720DA
    :1008300069308A0137206E308A01372067308A019B
    :0A08400037208A0140298A0140296F
    :02400E00CA3FA7
    :00000001FF
    Last edited by Archangel; - 25th May 2011 at 09:42. Reason: recompiled
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    Tyranny is defined when law enforcement is allowed to make the law.
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    May 2011
    Posts
    4

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    Quote Originally Posted by Archangel View Post
    hERE IS A HEX WHICH SHOULD WORK AS YOUR SCHEMATIC IS WIRED
    sorry about the all caps
    Sorry for asking stupid questions, but... what is this actually? Where did you get it? And how can I use (program) it? Like I said, I'm a total newbie when it comes to PICs and so far I've only ran a few programs (files) from pickit tutorial and played a bit with LEDs on a testing board i got by my pickit3. I also know how to use 'hex' file, but I i have no idea how to use your hex code. Thanks for your answer.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,819

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    Intel Hex file is the format which you load into the programmer and gets sent to your pic.
    You write your code in P basic and compile it, the compiler translates it into assembly language, then the assembler translates it into Intel hex, which your programmer loads into the PIC.

    Where did I get it ? I wrote it last night before bed, I used your LCD defines according to the way your schematic is showing the wiring. It is written for a PIC16F876A operating at 20 mhz, since I could not find any data about a 16F786A I assumed you simply transposed the numbers.

    What does it do ?
    It simply sends some text to each of 4 lines available to a 4 line LCD
    It does not scroll, it puts the text in the same place each time it cycles.

    How to use my hex file . . . select all of it by mouse clicking and dragging across it, click copy and then paste into notepad. Save the file with the suffix .hex and the name of your choice, load that into your programmer, I hope it works as I had no time or chip to test it.
    I would offer the source code but it would have no value, as it is written in PBasic Pro, and P Basic does not support LCDOUT command (Or so I have been led to believe).

    EDIT: And you may already know all I have posted, but the next person coming in and seeing this may not.
    Last edited by Archangel; - 26th May 2011 at 00:21.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    Tyranny is defined when law enforcement is allowed to make the law.
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    May 2011
    Posts
    4

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    Quote Originally Posted by Archangel View Post
    Intel Hex file is the format which you load into the programmer and gets sent to your pic.
    You write your code in P basic and compile it, the compiler translates it into assembly language, then the assembler translates it into Intel hex, which your programmer loads into the PIC.

    Where did I get it ? I wrote it last night before bed, I used your LCD defines according to the way your schematic is showing the wiring. It is written for a PIC16F876A operating at 20 mhz, since I could not find any data about a 16F786A I assumed you simply transposed the numbers.

    What does it do ?
    It simply sends some text to each of 4 lines available to a 4 line LCD
    It does not scroll, it puts the text in the same place each time it cycles.

    How to use my hex file . . . select all of it by mouse clicking and dragging across it, click copy and then paste into notepad. Save the file with the suffix .hex and the name of your choice, load that into your programmer, I hope it works as I had no time or chip to test it.
    I would offer the source code but it would have no value, as it is written in PBasic Pro, and P Basic does not support LCDOUT command (Or so I have been led to believe).

    EDIT: And you may already know all I have posted, but the next person coming in and seeing this may not.
    Oh, thank you very much! Makes more sense now. Seems like i can test my LCD with this code. I'll try it as soon as i can and i'll get back with the results.

    And yes, it is PIC16F876A (i accidently wrote it wrong in my first post) and my crystal is 20Mhz. Btw, mentioning the oscillator (crystal), i heard it can cause some trouble when used on a breadboard (because of all that additional capacitance), so i'll need to test it as well. Without the external oscillator working as it should, the pic won't work and this could be a possible source of my problem too.

  6. #6
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    Quote Originally Posted by voyage View Post
    Like i said, i didn't write the code, but i believe it's written correctly (as i got it from the original author of that project (it was written in MikroBasic)). So checking the code would be the last thing for me to do.
    I don't quite understand how you expect to use a PicKit3 to program your PIC when the source code is written in Mikrobasic. How are you going to compile the code? A PicKit3 won't compile for you....all it does is program the PIC from a hex file that has to be produced by a compiler. If you are using PicBasic, you need a PBP compiler from MeLabs.

  7. #7
    Join Date
    May 2011
    Posts
    4

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    Quote Originally Posted by jellis00 View Post
    I don't quite understand how you expect to use a PicKit3 to program your PIC when the source code is written in Mikrobasic. How are you going to compile the code? A PicKit3 won't compile for you....all it does is program the PIC from a hex file that has to be produced by a compiler. If you are using PicBasic, you need a PBP compiler from MeLabs.
    Yes, the source code is in Mikrobasic, but I also have the hex file so all I needed to do was to download it to my PIC and I've done it successfully. It works ok.

    Yeah I forgot to tell my project started to work soon after the testing of my LCD and crystal. Still not totally sure what was wrong earlier, but when I replaced my crystal osc with the new one (and move it closer to PIC pins) and played a bit with LCD display contrast, it suddenly started to work. Thanks for your help and suggestions everyone.

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,541

    Default Re: can you help me with my project (PIC & temperature sensor & LCD)?

    Surely it would have been simpler to tell us ...

    http://www.elektor.com/magazines/201....1673686.lynkx

    Code:
    ELEKTOR Project IR Thermometer ...
    program IR_Thermometer
    ' * IR_Thermometer
    ' * Copyright C.TAVERNIER- 2010
    ' * for Elektor Magazine
    ' * www.tavernier-c.com
    ' *
    ' * Microchip PIC16F876A and
    ' * Melexis MLX90614 IR Thermometer
    ' LCD module connections
    ' LCD used in 4 bits mode on Port B
    dim LCD_RS as sbit  at RB2_bit
        LCD_EN as sbit  at RB3_bit
        LCD_D4 as sbit  at RB4_bit
        LCD_D5 as sbit  at RB5_bit
        LCD_D6 as sbit  at RB6_bit
        LCD_D7 as sbit  at RB7_bit
        LCD_RS_Direction as sbit at TRISB2_bit
        LCD_EN_Direction as sbit at TRISB3_bit
        LCD_D4_Direction as sbit at TRISB4_bit
        LCD_D5_Direction as sbit at TRISB5_bit
        LCD_D6_Direction as sbit at TRISB6_bit
        LCD_D7_Direction as sbit at TRISB7_bit
    ' End LCD module connections
    ' Variable definitions
    dim SensorLow as byte       ' Raw temp. low byte
        SensorHigh as byte      ' Raw temp. high byte
        SensorRaw as word       ' Raw temp. word
        SensorRawCur as word    ' Current raw temp.
        SensorRawMax as word    ' Max. raw temp.
        SensorRawMin as word    ' Min. raw temp.
        Sensor as float         ' Real temp (floating point)
        SensorString as string[9]
        DisplayString as string[9]
        PEC as byte             ' Control byte (read but not used)
        com as byte             ' MLX90614 command
        PosDecPoint as byte     ' Decimal point position
        i as byte
    ' Procedure definition
    ' Read Temperature From MLX90614
    ' Input : com specify temp. to read
    ' Output : raw temp as a word
      Sub procedure Read_temp(dim com as byte)
      I2C1_Start()           ' issue I2C start signal
      I2C1_Wr(0x00)          ' send address (device address + W)
      I2C1_Wr(com)           ' send command
      I2C1_Repeated_Start()  ' issue I2C signal repeated start
      I2C1_Wr(0x01)          ' send address (device address + R)
      SensorLow = I2C1_Rd(1) ' Read temp. low byte (acknowledge)
      SensorHigh = I2C1_Rd(1)' Read temp. high byte (acknowledge)
      PEC = I2C1_Rd(1)       ' Read PEC (not used) (acknowledge)
      I2C1_Stop()            ' issue I2C stop signal
      SensorRaw = SensorLow + (SensorHigh << 8)     ' Build temp. word
      End sub
    ' Convert raw data in SensorRaw
    ' to displayable string in DisplayString
      Sub procedure Convert_raw
      Sensor = SensorRaw * 0.02 - 273.15            ' Raw temp to Celsius
      FloatToStr (Sensor, SensorString)             ' Float to string
      PosDecPoint = Strchr (SensorString,".")       ' Search for dec. point
      For i = 0 to PosDecPoint+2                    ' Limit display to two digits
          DisplayString[i] = SensorString[i]        ' after decimal point
      Next i
      DisplayString[PosDecPoint+3]= ""
      DisplayString = DisplayString + " C"
      
      End sub
    ' Main Program
    main:
    ' Initialize I/O
      PORTB = 0
      TRISB = 0                      ' All PORTB lines as output
      ADCON1  = 0x0F                 ' Configure AN pins as digital I/O
    ' Initialize LCD display
      Lcd_Init()                     ' Initialize Lcd
      Lcd_Cmd(_LCD_CLEAR)            ' Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF)       ' Cursor off
    ' Initialize Min and Max object temp.
      SensorRawMax = 0
      SensorRawMin = 0xFFFF
    ' Initialize SMBus
      I2C1_Init(100000)              ' I2C/SMBus Clock speed 100 kHz
      SETBIT (SSPSTAT,6)             ' Force MSSP in SMBus mode
    while true
        Read_temp (0x06)             ' Read ambiant temp.
        Convert_raw
        Lcd_Out(1,1,"T Amb. : ")     ' Write ambiant temp in first row
        Lcd_Out(1,10,DisplayString)
        Read_temp (0x07)             ' Read object temp.
        SensorRawCur = SensorRaw     ' Make obj. temp. current temp.
        
        If SensorRawCur > SensorRawMax Then ' Is current temp. higher than max. temp.
           SensorRawMax = SensorRawCur      ' Make max. temp. equal current temp.
        End if
        If SensorRawCur < SensorRawMin Then ' Is current temp. lower than min. temp.
           SensorRawMin = SensorRawCur      ' Make min. temp. equal current temp.
        End if
        Convert_raw
        Lcd_Out(2,1,"T Obj. : ")     ' Write object temp in second row
        Lcd_Out(2,10,DisplayString)
        
        SensorRaw = SensorRawMax
        Convert_raw
        Lcd_Out(3,1,"T Max. : ")     ' Write Max object temp in third row
        Lcd_Out(3,10,DisplayString)
        SensorRaw = SensorRawMin
        Convert_raw
        Lcd_Out(4,1,"T Min. : ")     ' Write Min object temp in fourth row
        Lcd_Out(4,10,DisplayString)
        Delay_ms (1000)
    wend
    end.
    Code:
    IR_Thermometer Fuses for a PIC 16F876A
    --------------------------------------
    Oscillator : HS
    Watchdog Timer : Disabled
    Power Up Timer : Disabled
    Brown Out Detect : Enabled
    Low Voltage Program : Disabled
    Data EE Protect : Disabled
    In-Circuit Debugger : Disabled
    Code Protect : None
    FLASH Write Enable : Write Protection Off
    Last edited by Acetronics2; - 23rd November 2011 at 16:29.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts