FYP

FYP

Saturday, 22 March 2014

WEEK 7



MicroC PRO software is used to make a program for microcontroller to control selected output. By using this software we can create a program that can control several functions. For example to control motor. The motor speed or angle of the motor can be control using program. MicroC PRO have its own library contain an example of basic program that can be use directly such as program for motor, LED display, LCD display, temperature sensor and keypad.
For our project digital pH meter, we need to make two programs. The first program is for analogue to digital program. This program is important because to allow the LCD display can display the pH value in digital form. LCD display can only read digital value.




What microcontroller do is, it read the analogue output voltage or signal from pH meter circuit then convert the value into digital before it can be display on LCD display. In microcontroller pin, to convert analogue signal to digital signal, port A is use because port A is for analogue input only.
The second program is LCD display program. This program is made to display the pH value in digital and also to display the temperature value in digital.






Figure 3.3.1    program for PIC controller

Figure above show the overall program for our project. The program included analogue to digital converter program and LCD display program.

PIC microcontroller is the brain of our system in this project. PIC microcontroller has many advantages especially to design the process itself. By using the MikroC PRO for PIC software, we can simulate the circuit diagram on proteus before making the actual hardware. Source code is easy to program which variety instructions that we can programmed. There are many PIC type such as 16F84X, 16F877X, 18F8XX and many more. In our case, we use PIC16F877A to create the program.

To create the source code program, we need to insert the command, because, for our program have their own command to let one system can be function. In this project, we use some of command to displaying the value of pH and temperature such as the LCD library command and the ADC library. For the display the items, we use LCD library that we call them from the MikroC PRO for PIC for make communication with LCD (with HD44780 compliant controllers). Through the 8-bit interface. An example of LCD connections is given on the schematic from the pH meter circuit.







Figure 3.3.2    program code for LCD display

From the figure above, we insert the LCD pin out setting and the LCD pin direction for 8-bit to enable the value is function correctly. We use the port C and port D to enable the connection that can be read and have a communication between PIC and the display.




Figure 3.3.3    program code for LCD

From the figure above, we create the lcd_init command to initializes LCD module. Then, we create the Lcd_Out to prints text on LCD starting from specified position. Both string variables and literals can be passed as a text. After that, we add the command Lcd_Out_Cp to prints text on LCD at current cursor position. Both string variables and literals can be passed as a text. We go to add the Lcd_Chr command to prints character on LCD at specific position. Both variables and literals can be passed as a character. Then, we add Lcd_Chr_Cp to prints character on LCD at current cursor position. Both variables and literals can be passed as a character. Lastly we put the Lcd_Cmd to sends command to the LCD and completing the LCD program source code.




Figure 3.3.4    program code for ADC

From above figure is shown the main program, we use an ADC (Analog to Digital Converter) module library. Because the ADC is an electronic circuit that converts continuous signals to discrete digital numbers to target the goals of this project as Digital pH Meter as well. There are 3 main of command that must be used in creating the program. That is ADC_Init command, this routine initializes PIC’s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion. After that we use the ADC_Get_Sample, the function is acquires analog value from the specified channel.


Parameter channel represents the channel from which the analog value is to be acquired data. Lastly we add the ADC_Read in this command, because this command initializes PIC’s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion. The program of ADC command is to display the analog signal from the circuit of pH meter convert to the digital signal that can be display to the LCD display for the value of pH and also the value of temperature. We use the ADC_float cause of to create the character with the size of 15. Because we also want the output on the LCD can be read at the decimal point. For read the value of pH, we dividing the result with 20.45, and store the pH value before it can be display on the output display. For read the value of temperature, we multiple the result with 0.48828 to display the temperature result on LCD display.






Figure 3.3.6    program for display pH and Temperature

By referring the picture above, we are use command Lcd_Out to display the value. We put the pH value at the output by using the line 1 of text while we put the temperature value at the output by using the line 2 of text.





3 comments:

  1. What is the results of the simulation? You only shown the circuit diagrams.

    ReplyDelete
  2. sallamo alikom .......im mikroc beginner programmer ,can u be my friend on fb / lalaabdallah@gmail.com/ so we can share some knowledge thx

    ReplyDelete
  3. Thanks for the post. I am very glad after ready and get useful information about the water ph testing kits from your blog.
    water ph testing kits

    ReplyDelete