Quantcast
Channel: Project Ryu Blog » Digital Electronics
Viewing all articles
Browse latest Browse all 3

Digital Thermometer monitoring up to 10 different areas

$
0
0
facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Hello, こんにちは,

私の日本語があまり上手くありませんが許して下さい.

One day i was talking with a client and he mentioned that he has a chicken egg incubator and that it is hard to keep track of the temperature inside. I offered my help to build a device that can display the temperature of all the incubators on the same screen.

これは10の分野のためのデジタル温度計です。それがPIC18F4620マイクロコントローラ、LM35温度センサとDigole12864ZW LCDを使用しています。記事の終わりには、Cのソースコード、HEXファイルとPCBレイアウトを見つけることができます。

For this task i used a PIC18F4620 and a Digole 12864ZW graphic LCD. Sensor units (LM35) are separate and i will not discuss it in this article.

The below image (figure 1) shows the electronic schematic of the monitor. J1-10 are 3 pin terminal blocks like the ones in figure 2. Each terminal block provides +5V and ground connection and a pin for sensor data.

Temperature Monitor Digole 12864ZW PIC18F

Figure 1

3 pin TBlock Connector

Figure 2

The circuit is very simple each sensor is connected to one of the ADC inputs of the PIC18F4620 through a 100 ohms resistor and the rest is basically software. The LCD is configured to work in parallel 8 bit mode because it is easier and the microcontroller has enough I/O pins available.

Working with the display was a bit hard in the beginning as the documentation isn’t really clear on some aspects. There weren’t many resources from other DIY-ers that used this display either. I got it to work in graphic mode using a XLCD library from Microchip and Application Maestro to configure it. You can use this library for text mode with no modifications.

I will cover the graphic mode of the Digole LCD in a future article describing in detail how it works.

Once you have generated the XLCD files using application Maestro (setting the data port to port D, RS pin to RB5, RW pin to RB6 and EN pin to RB7, delay mode), you will need to modify XLCD.c file and specifically XLCDinit() function. You can delete it if you want and copy the one below:

void XLCDInit(void)
{
_vXLCDreg=1;

XLCD_DATAPORT_TRIS  = 0x00;
XLCD_DATAPORT = 0;
XLCD_RSPIN_TRIS =0;                        
XLCD_ENPIN_TRIS =0;
XLCD_RWPIN_TRIS =0;
XLCD_RSPIN  =0;                            
XLCD_ENPIN  =0;
XLCD_RWPIN=0;                              
XLCDDelay15ms();
XLCD_DATAPORT   = 0b00110000;  
XLCDDelay4ms();
XLCD_DATAPORT   = 0b00110000;  
XLCDDelay4ms();
XLCDCommand(0x0C);
XLCDDelaylcd();   
XLCDCommand(0x01);
XLCDDelay15ms();  
XLCDCommand(0x06);
XLCDDelaylcd();
XLCDCommand(0x34);
XLCDDelay15ms();    
XLCDCommand(0x36);
XLCDDelay15ms(); 

_vXLCDreg=0;
return;
}

I created functions to display digits and some special characters. Basically these functions accept coordinates as their arguments and draws the specific pixels at the proper address. An example of such a function is below:

void display1(int x, int y)
{
        if(y<27)
    {
            XLCDCommand(0x80 | y);
            XLCDCommand(0x80 | x);
                XLCDPut(0b00000000);
                XLCDPut(0b00000000);
            XLCDCommand(0x80 | y+1);
            XLCDCommand(0x80 | x);
                XLCDPut(0b00000000);
                XLCDPut(0b00000000);
            XLCDCommand(0x80 | y+2);
            XLCDCommand(0x80 | x);
                XLCDPut(0b11111000);
                XLCDPut(0b00000000);
            XLCDCommand(0x80 | y+3);
            XLCDCommand(0x80 | x);
                XLCDPut(0b00000000);
                XLCDPut(0b00000000);

    }            
    else
    {
            XLCDCommand(0x80 | y-27);
            XLCDCommand(0x88 | x);
                XLCDPut(0b00000000);
                XLCDPut(0b00000000);
            XLCDCommand(0x80 | y-26);
            XLCDCommand(0x88 | x);
                XLCDPut(0b00000000);
                XLCDPut(0b00000000);
            XLCDCommand(0x80 | y-25);
            XLCDCommand(0x88 | x);
                XLCDPut(0b11111000);
                XLCDPut(0b00000000);
            XLCDCommand(0x80 | y-24);
            XLCDCommand(0x88 | x);
                XLCDPut(0b00000000);
                XLCDPut(0b00000000);

    }    
}

As can be seen XLCDCommand sets the address and XLCDPut sets the value. These functions are defined in XLCD library from Microchip. The condition set for y coordinate is needed because of the way the LCD is made. It is split in two horizontally. Data width is 16 bits sent in two transmissions of 8 bits each.

Each bit in the 16 bits word represents the state of a pixel so you always draw 8 pixels with each instruction. This can be annoying when trying to write values that change dynamically. So you can’t control one pixel at the time horizontally, but you can control each vertical line. This is why i turned the display on a side and it proved much easier to draw the graphs.

digole 12864ZW PIC18F LCD

digole 12864ZW PIC18F LCD

digole 12864ZW PIC18F LCD

The role of SW1 push button is to switch between the screens on Digole 12864ZW showing time graphs and bar graph for each of the 10 sensors. The program verifies the state of SW1 on each loop so it will require to hold the button for about 1second. Also holding too long might cause the screen to go beyond the area you need.

The button is verified with the switch(counter) function in main(). Case 0 is the first screen displaying all the sensors. Cases 1 -> 10 correspond to individual areas and call the zone(area) function, where area takes a value between 0 and 9.

Here is how the zone(area) function looks like:

void zone(int area)
{
        int i;
        int val_t;
        int val_mem;
        xygraph(); // function that displays the time chart
        bargraph(); // function that displays the bargraph
        // below instructions display 0 Celsius
        XLCDCommand(0x80 | 30);
        XLCDCommand(0x80 | 4);            
        XLCDPut(0b00000000);
        XLCDPut(0b11100000);
        XLCDCommand(0x80 | 29);
        XLCDCommand(0x80 | 4);            
        XLCDPut(0b00000000);
        XLCDPut(0b10100000);
        XLCDCommand(0x80 | 28);
        XLCDCommand(0x80 | 4);            
        XLCDPut(0b00000000);
        XLCDPut(0b11100000);
        XLCDCommand(0x80 | 26);
        XLCDCommand(0x80 | 4);            
        XLCDPut(0b00000000);
        XLCDPut(0b01110000);
        XLCDCommand(0x80 | 25);
        XLCDCommand(0x80 | 4);            
        XLCDPut(0b00000000);
        XLCDPut(0b10001000);
        XLCDCommand(0x80 | 24);
        XLCDCommand(0x80 | 4);            
        XLCDPut(0b00000000);
        XLCDPut(0b10001000);
        XLCDCommand(0x80 | 26);
        XLCDCommand(0x80 | 6);            
        XLCDPut(0b01110000);
        XLCDPut(0b00000000);
        XLCDCommand(0x80 | 25);
        XLCDCommand(0x80 | 6);            
        XLCDPut(0b10001000);
        XLCDPut(0b00000000);
        XLCDCommand(0x80 | 24);
        XLCDCommand(0x80 | 6);            
        XLCDPut(0b10001000);
        XLCDPut(0b00000000);
        if(SW == 0) // Checking button
        {
            counter++;
        }
        switch(area) //display the area number
        {
            case 0: display0(6,17);break;
            case 1: display1(6,17);break;
            case 2: display2(6,17);break;
            case 3: display3(6,17);break;
            case 4: display4(6,17);break;
            case 5: display5(6,17);break;
            case 6: display6(6,17);break;
            case 7: display7(6,17);break;
            case 8: display8(6,17);break;
            case 9: display9(6,17);break;
        }
        //level display
        val_t=ADC_Read(area); //read the sensor specific to that area
        val_mem=val_t*48; //convert to degrees
        chart(val_mem); // plot value on xychart
        showtemp(val_mem,5,35); // displays the temperature
        showlevel(val_mem); // displays level on bar graph

        for(i=0;i<25;i++) // delay
        {
        XLCDDelay15ms();
        }

}

 

At the end of the article you can download the full C file without the XLCD library also the hex file. Below you can see a version of double sided PCB layout, images are not mirrored:

PCB Temperature Monitor

top silk

PCB Temperature Monitor

Top Copper

PCB Temperature Monitor

Bottom Copper

On the PCB J13 corresponds to SW1 in the schematic.

Temp Monitor PIC18LH4620 Digole 12864ZW

Thank you for visiting,

ご覧いただきありがとうございます。

 

 

The post Digital Thermometer monitoring up to 10 different areas appeared first on Project Ryu Blog.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images