Friday, 5 June 2015

WEEK 14 (FYP 2)

WEEK 14




presentation day

during the presentation the hardware is not satisfied  but the relay is working well. the driver of the motor is working but the sensor of does not detect the current over flow exceding 7 A.

WEEK 13 (FYP 2)

WEEK 13
Experiment of Trouble shooting : Main Problem

Not all planning will be end exactly well done. For this project, there were many of problem occurs during the period from the start until the end. By making the investigation and listed the problem occurs during the period.

  1. Wrong decision. At the starting project, the current sensor using comparator op-amp was chosen to sensing the current through the power windows. However in the middle of the project, realize that the Acs756 is better to be used and the configuration is written through the datasheet.
  2. H-bridge mosfet with high current rating failure to operate due to the burn of the transistor because of no heat sink used.
  3. Careless. This problem is always face it during the period that use to finish hardware part works. Not using any circuit protection make the circuit and relays damage and burns due to high current and voltage spikes.
  4. Lack of resource. Some of part in this project is hard to find the solution.
  5. The starting current of the motor cannot be monitor due to limitation of device or laboratory equipment that can measure the current in real time.

Upon the completion of the system, a test should be conducted to test the accuracy and the stability of the system.


Conclusion

This chapter has discussed about the result of this project and hard ware development. In order to make this project successful, all these element have recorded the result to make sure that it functions to make a quality process according to need of the project objective. The real picture of hardware development, PCB design, and assemble process are already attached. The important stages in this chapter are trouble shooting the problems that faced. This is because, to test the project circuit and collect the output result. Results from circuit development will interface with program and compile it in order to run this project smoothly.




CONCLUSION AND RECOMMENDATION


 Introduction

This chapter discuss about the conclusion and suggestion in the future. This project has two major parts which is hardware description and software implementation. Both topics were very related and important to each other and can be applied to perform the system more effective. This chapter is very important because it helps to overcome the problem and improve the efficiency of the project.
The overall summary can be made for this project is the entire objective for this project is achieved. This project is actually will make a new evolution in furniture industrial era. For these reason, it is important to develop methods to show a different ways of marketing to popularize their products. It will show that electric and electronic field has a lot of criteria to impose in engineering section.

 Conclusion

The revolution of car technology have become drastically change and widely practiced throughout the world. The development of power windows safety system becomes a new technology that can be commercialized in the world. Actually this project is a new solution for user that always wanted for technologies that will ease their concerned of safety.
 Nowadays, technologies are very advance. Majority products that produce from manufacture are in automatic mode. So basically this project is a new way to follow up the technologies. This new development totally can save their energy by using this project.

 Recommendation

The performance of the system is can be increases so that this system will be more up to date and more flexible. For future works, some recommendations have been listed in order to improve the system performance

      i.        Puts the program in engine control unit (ECU) of the car to minimize the costing to use new Microcontroller. Almost all of the ECU of the car can be reprogram and update the system so that is more efficient.
    ii.        For the next improvement is protecting the microcontroller from the heat is very important the microcontroller should be able to function efficiently.  Therefore, microcontroller should be protected as well as possible to avoid microcontroller exposed to extreme temperatures and cause damage. . It is important to make the user feel comfortable and safe.
   iii.        Then, for lastly is need to improve the program and circuit so that the power windows can goes up and down automatically with 1 input from the user.








 Summary

In this final year project the power window looking forward in improving the design so that it is more convenient to be used and have more safety. Therefore the basic operation to improve the power windows is connecting the power window motor to the MCU. When the power windows is stuck by something or have more loaded then usual the MCU directing the motor to give a chance to remove the anything that disturbs the windows before it closed. Other than that the time to service and put a lube to the mechanical part will make the longer life time to the motor and overall mechanism of the power window.
This development of the project is reviews the various type and configuration of the power windows systems which will be then to be used to test and validate the proposed reliability estimation method.
This project involves hardware and software parts construction and the integration of both parts to create the system. In the end of this project, all the document, hardware and software development and provide a simulation model of the system.
Through overall of the project the procedure to test the circuit is need to be listed so that the circuit is not damage. The damage of the circuit is costing lots of money and wasting time during troubleshoot and testing.







 REFERENCES
[5         ]http://www.iihs.org/iihs/topics
[6]        Model Based Automotive System, Design: A Power Window Controller Case Study © Zubair Akhtar 2015
[7]        J. Axelsson. Evolutionary architecting of embedded automotive product lines: An industrial case study. In Software Architecture, 2009 European Conference on Software Architecture. WICSA/ECSA 2009. Joint Working IEEE/IFIP Conference on, pages 101–110, Sept 2009.

[8]        Design And Fabrication Power Window Apparatus by Ahmad Kamil Bin Miskam Faculty Of Mechanical Engineering University Malaysia Pahang November 2007
[9]        http://cp.literature.agilent.com/litweb/pdf/5989-7805EN.pdf




WEEK 12 (FYP 2)


WEEK 12


ANALYSIS AND RESULT
Introduction

This chapter discusses on the result, analysis and problem that are encountered throughout the completion of designing this project after fabrication hardware. Upon the completion of the appropriate software and hardware implementation, the car starter system operation should be tested to ensure the stability and accuracy of operating process is running smoothly. Several tests had been done and the result showed the mailing system achieved the stability and accuracy as desired.

Experiment and analysis the current demand for the motor

Each motor have high starting current to drive and need a high torque to rotate the motor therefore the motor will need high current at the starting of the motor compare to the nominal current of the motor. Due to this situation its need to be analyze the starting current of the motor using real time measurement that can record very precise about the current of the motor.
            In this final year project the experiment cannot be Cary out at the British Malaysian Institute (BMI) due to limitation of device or laboratory equipment that can measure the current in real time. Therefore there is another method that is by make a research in internet and found that someone already make a research of the power windows motor through that is can be summarize and that there have high starting of armature current of the DC motor and the value is not constant up to 15A, and its happened less than 1m second. Figure below shows the starting high armature current of the DC motor when it begin start to rotate.

Therefore its need to considered the starting current of the motor to make a program for the safety system of the power windows



Motor Driver.
In this final year project there is two approaching method to make the motor driver of the motor that control the rotation clockwise and anti-clockwise of rotation of the power windows motor. The motor driver that been used to control the motor is using:
1.    H-bridge Mosfet with high current rating
2.    Relay with high ampere (10A).


 H-Bridge Mosfet with High Current Rating
Figure above show the configuration of the H-bridge. The connection of the transistor is connected in shape like H and its can control forward and reverse of DC motor, other than that its can converting direct current Dc signal to alternating current AC, but in this project is to control the movement of the motor either in clockwise or anticlockwise. The motor that is used for this project is power windows motor that consumes current until 32A if the motor is stall referenced to the power windows motor specification. MOSFET transistor used is P-Channel IRF9540N at the top and N-Channel IRFZ44N on the bottom. IRF9540 has the ability to skip a current of 23A and 40A of IRFZ44N with a maximum voltage of 24V, therefore it is suitable to use in this project.
The working principle of this H-bridge configuration is by allowing the current trough Q2 and Q4 at the same time Q1 and Q3 block the current make the motor turns clockwise. It is same to make the motor to turn in anticlockwise is by allowing current through Q1 and Q3 and at the same time Q2 and Q4 block the current. The resistor R1 and R4 is used to limit the current flow and it is set to 10kΩ, the higher the resistance value the small the value of the current flow in through.
Optocoupler is used in this circuit as a safety component that transfer electrical signal between two isolated circuit by using light signal, it is maintains the connection between two devises or component without any direct conduction. Refer to the figure 4.2, U2 and U3 is an optocoupler for the simulation but the real devise use other type of optocoupler because the limitation component library of proteus. The optocoupler that is used in the hardware is PC817 and have same function of the simulation software.


Result for H-bridge circuit is unsatisfied because the bottom transistor that referred to figure above with mark with red circle that is N-Channel IRFZ44N (Q1 & Q4) is becoming very hot during the operation of the system. After a few try the transistor of IRFZ44N is damage because there is no current protection to the circuit.
Therefore to improve the circuit is need to add heat sink to transfer the heat to ambient and adding capacitor to filter the current so that there is no spark and reduced arced when switching the transistor off and on. For extra protection is need a fuse to limit the current moreover its can protect the circuit from being damage.
4.3.2   Relay with High Ampere (10A)
The relay also can be used to be the motor driver. Because of the H-bridge configuration becoming hot during operation this relay is design to substitute of the H-bridge motor driver and the design was improve with present of capacitor and fuse to protect the circuit from being damage. Capacitor rating with bigger than 10k µF is used to stop voltage spikes and between 10nF to 100nF is used to absorbed high frequency surges.


Figure above show there is two relay to control forward and reverse of the motor which is single pole double trough. Relay 1 is connected with normally open connection and relay 2 is connected with normally close connection.
            The working principle for the relay operation to control forward and reverse of the motor is when the switch up is press the motor can move in forward direction because it’s get the close loop supply to the motor directing the motor to forward. For the reverse function, when the switch down is press both relay will triggered and is will cut off the forward supply and reverse the polarity of the motor and will make the motor moving reverse direction. The optocoupler is used in this relay configuration which is connected to the microcontroller.  The working principle of the optocoupler is when get signal from the microcontroller is its will directing the motor reverse direction same function as the switch down is press by user. The function of the opt coupler also as a protection of the microcontroller from being directly connected to the motor driver. For the optocoupler at the hardware PC817 is used refer to figure 4.5 below. This configuration of the relay is more stable compare to the H-bridge configuration therefore using relay is suitable to be used as a motor driver for this project. The result for this relay configuration is satisfactory.

Figure abpve show the optocoupler PC817 that is being used for interconnection between microcontroller and motor driver. This optocoupler is a protection to avoid high current from motor driver to the microcontroller that can damage the microcontroller itself. Pin no 1 and no to is connected to microcontroller to give a signal to the motor driver and pin no 3 and for is connected to the motor driver to allow or block the current flow.
            The diode D4 and D1 is used as protection if the one of the relay failure to working simultaneously, so that only one direction of current is allowed to flow through the relay.





Result for experimenting relay circuit.
           
During the first testing of the relay there is no protection to the relay which damage the relay and the circuit due to voltage spikes and high current. Referring to figure 4.6 relay at the left is normal relay and relay at the right is the damage relay. The wire inside the relay is burn and make the relay totally damage. 

Figure above show the damage relay due to no protection to the relay and circuit. Therefore to protect the relay it’s must to add capacitor rating with bigger than 10k µF to stop voltage spikes and between 10nF to 100nF to absorbed high frequency surges. To protect the circuit and relay due to high current the fuse is need to be add on to limit the current flow through the relay and the circuit. The fuse will cut off the circuit when there is high current flowing through the circuit is make the circuit safer and only the fuse is need to be replace when is blow off. Through the experiment there is many fuse already blow off because of the high current flowing through the circuit when the power windows of the motor stall due to heavy weight or struck.



result of combined circuit 
            Figure shows all the circuit is combined into one circuit which is power supply circuit, relay circuit, and microcontroller circuit. The circuit consist of two fuse which is to protect the relay and microcontroller circuit. Rating for fuse microcontroller circuit is 1A and for the relay circuit rating is 7.5A.  16x2 display is used to monitor the current and to calibrate the sensor through programing. The result for overall circuit is unsatisfied due to not adding the fuse through the circuit at beginning of the testing make the microcontroller circuit is not working as predicted but the relay circuits is working well.

WEEK 11 (FYP 2)

WEEK 11

Burning the Hex File to the Microcontroller.

To burn the microcontroller its need to used 8051 Mini Kit-board and software ProgIsp. Below is the simple step to burn the microcontroller IC.

Step to burn Atmel AT89S52


1.    Install the driver for the 8051 Mini Kit-board so that the computer can recognize the hardware.
2.    Run ProgIsp
3.    Insert the Atmel AT89S52 into the 40 pin slot, and lock at the kit.
4.    Click erase button to erase the older hex file
5.    Load flesh by selecting the hex file that need to be burn.

6.    Press auto to start the burning process.
Figure  show 8051 Mini Kit-board model AD-MCSZ V.1 that is used to burn the program inside the microcontroller.



show the interfaced software that being used as a program that is called ProgIsp.



WEEK 10 (FYP 2)

WEEK 10


Developing Programming to Suit The Hardware Configuration
Figure above show the operation of the whole system. The program for the microcontroller must be configure and referred to this block diagram. When the switch up is press the microcontroller will allow the windows go up only when the current is below 7 ampere. Above 7 ampere current the microcontroller will give signal to the motor driver so that the windows sliding down a little bit. 


Developing program for the MCU using Keil uVision5

Figure  shows the program is constructed using C language and the program is attached at below. the program is need to be read the current sensor output from analog digital converter ADC and if the current of the sensor is read 7A and above the motor drive is need to change direction of the motor so that the power windows is not continue going up.


//main POGRAM
#include <reg52.h>
#include "stdio.h"
#include "delays.c"
#include "usart_header.c"
#include "lcd4bitdriver.c"
#include "adc0804driver.c"

sbit LED0         = P0^0;

//const unsigned char d[]=("                Voltage                ");
const unsigned char d[]=("Voltage");

char buf[20];
signed int val;

void main(void)
{
char i,j,k;
unsigned int Vdig,Vdig_smlm, loop ;
float Vana;
init_ADC0804();
init_usartBR9600();
Initialize_LCD();
printf("\n\r OK PASS");
lcd_gotoxy(1,0);
puts_lcd("current");
delay_1ms(100);
while(1){
  Vdig =           ADC_read();
           
            Vana = (float)Vdig*0.019608;
           
printf("\n\r%u : %1.2f",Vdig, Vana);
           
            if(Vdig!=Vdig_smlm){
                        sprintf(buf,"%u : %1.2f",Vdig,Vana);
                        lcd_gotoxy(2,1);
                        puts_lcd("        ");
                        lcd_gotoxy(2,1);
                        puts_lcd(buf);
                        Vdig_smlm=Vdig;
              }
           
            if(Vana/0.040>7)
                        LED0=0;
  if(Vana/0.040<6.5)
                        LED0=1;
           
}
}


*--------------------------------------------------------------------------
REG52.H

Header file for generic 80C52 and 80C32 microcontroller.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __REG52_H__
#define __REG52_H__

/*  BYTE Registers  */
sfr P0    = 0x80;
sfr P1    = 0x90;
sfr P2    = 0xA0;
sfr P3    = 0xB0;
sfr PSW   = 0xD0;
sfr ACC   = 0xE0;
sfr B     = 0xF0;
sfr SP    = 0x81;
sfr DPL   = 0x82;
sfr DPH   = 0x83;
sfr PCON  = 0x87;
sfr TCON  = 0x88;
sfr TMOD  = 0x89;
sfr TL0   = 0x8A;
sfr TL1   = 0x8B;
sfr TH0   = 0x8C;
sfr TH1   = 0x8D;
sfr IE    = 0xA8;
sfr IP    = 0xB8;
sfr SCON  = 0x98;
sfr SBUF  = 0x99;

/*  8052 Extensions  */
sfr T2CON  = 0xC8;
sfr RCAP2L = 0xCA;
sfr RCAP2H = 0xCB;
sfr TL2    = 0xCC;
sfr TH2    = 0xCD;


/*  BIT Registers  */
/*  PSW  */
sbit CY    = PSW^7;
sbit AC    = PSW^6;
sbit F0    = PSW^5;
sbit RS1   = PSW^4;
sbit RS0   = PSW^3;
sbit OV    = PSW^2;
sbit P     = PSW^0; //8052 only

/*  TCON  */
sbit TF1   = TCON^7;
sbit TR1   = TCON^6;
sbit TF0   = TCON^5;
sbit TR0   = TCON^4;
sbit IE1   = TCON^3;
sbit IT1   = TCON^2;
sbit IE0   = TCON^1;
sbit IT0   = TCON^0;

/*  IE  */
sbit EA    = IE^7;
sbit ET2   = IE^5; //8052 only
sbit ES    = IE^4;
sbit ET1   = IE^3;
sbit EX1   = IE^2;
sbit ET0   = IE^1;
sbit EX0   = IE^0;

/*  IP  */
sbit PT2   = IP^5;
sbit PS    = IP^4;
sbit PT1   = IP^3;
sbit PX1   = IP^2;
sbit PT0   = IP^1;
sbit PX0   = IP^0;

/*  P3  */
sbit RD    = P3^7;
sbit WR    = P3^6;
sbit T1    = P3^5;
sbit T0    = P3^4;
sbit INT1  = P3^3;
sbit INT0  = P3^2;
sbit TXD   = P3^1;
sbit RXD   = P3^0;

/*  SCON  */
sbit SM0   = SCON^7;
sbit SM1   = SCON^6;
sbit SM2   = SCON^5;
sbit REN   = SCON^4;
sbit TB8   = SCON^3;
sbit RB8   = SCON^2;
sbit TI    = SCON^1;
sbit RI    = SCON^0;

/*  P1  */
sbit T2EX  = P1^1; // 8052 only
sbit T2    = P1^0; // 8052 only
            
/*  T2CON  */
sbit TF2    = T2CON^7;
sbit EXF2   = T2CON^6;
sbit RCLK   = T2CON^5;
sbit TCLK   = T2CON^4;
sbit EXEN2  = T2CON^3;
sbit TR2    = T2CON^2;
sbit C_T2   = T2CON^1;
sbit CP_RL2 = T2CON^0;

#endif




/*--------------------------------------------------------------------------
STDIO.H

Prototypes for standard I/O functions.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __STDIO_H__
#define __STDIO_H__

#ifndef EOF
 #define EOF -1
#endif

#ifndef NULL
 #define NULL ((void *) 0)
#endif

#ifndef _SIZE_T
 #define _SIZE_T
 typedef unsigned int size_t;
#endif

#pragma SAVE
#pragma REGPARMS
extern char _getkey (void);
extern char getchar (void);
extern char ungetchar (char);
extern char putchar (char);
extern int printf   (const char *, ...);
extern int sprintf  (char *, const char *, ...);
extern int vprintf  (const char *, char *);
extern int vsprintf (char *, const char *, char *);
extern char *gets (char *, int n);
extern int scanf (const char *, ...);
extern int sscanf (char *, const char *, ...);
extern int puts (const char *);

#pragma RESTORE

#endif


/*
Please put
#include "usart_header.c"
    on top of main file.
                       
Call init_usart(); once in your code

Please take notes
USART in MODE1 Fosc = 11.0592 MHz
MODE = 1;
TIMER1 in MODE 2 (Auto reload)
*/


#include <stdio.h>



/*
Call this function once in the main file to work at 2400 b/s
*/
void init_usartBR2400(void){
PCON = 0x00;
SCON  = 0x50;                   /* SCON: mode 1, 8-bit UART, enable rcvr    */
TMOD |= 0x20;                   /* TMOD: timer 1, mode 2, 8-bit reload      */
TH1   = 244;                   /* TH1=244  reload value for 2400 baud         */
TR1   = 1;                      /* TR1:  timer 1 run                        */
TI = 1;
}


/*
Call this function once in the main file to work at 4800 b/s
*/
void init_usartBR4800(void){
PCON = 0x00;
SCON  = 0x50;                   /* SCON: mode 1, 8-bit UART, enable rcvr    */
TMOD |= 0x20;                   /* TMOD: timer 1, mode 2, 8-bit reload      */
TH1   = 250;                   /* TH1=250  reload value for 4800 baud         */
TR1   = 1;                      /* TR1:  timer 1 run                        */
TI = 1;
}


/*
Call this function once in the main file to work at 9600 b/s
*/
void init_usartBR9600(void){
PCON = 0x00;
SCON  = 0x50;                   /* SCON: mode 1, 8-bit UART, enable rcvr    */
TMOD |= 0x20;                   /* TMOD: timer 1, mode 2, 8-bit reload      */
TH1   = 253;                   /* TH1=253  reload value for 9600 baud         */
TR1   = 1;                      /* TR1:  timer 1 run                        */
TI = 1;
}



Filename : lcd4bitdriver.c
Auhor    : ISA
Date     : 28/11/2013
Dependency : delays.c

Please put
#include "lcd4bitdriver.c"
    on top of main file.

2 x 16  LCD Driver - 4 bit interfacing as details below.

The connection of control lines and data should be as below

EN    - P1.0
RS    - P1.1
RW    - P1.2
D4/D7 - P1.4/P1.7


This free codes are provided as is without any guarantees or warranties.

Although the author has attempted to find and correct any bugs in the codes, the author is not
responsible for any damage or losses of any kind caused by the use or misuse of the codes.

The author is under no obligation to provide support, service, corrections,
or upgrades to the programs.

Please email to i.adam.mlk@gmail for any comments and visit my blogspots
(http://maelnotesonmicrocontrollerinterfacing.blogspot.com) for any updates
*/

#include <reg52.h>


//LCD lines
#define D_LCD P2
sbit EN = D_LCD^0;
sbit RW = D_LCD^1;
sbit RS = D_LCD^2;

void Delay_uS(unsigned int x);
unsigned char ADC_read(void);

const unsigned char set_lcd_4bit[7]={0x20, 0x20, 0x80, 0x00, 0xe0, 0x00, 0x60};

void EN2HIGH(void);
void EN2LOW(void);
unsigned char check_busy(void);
char read_data(void);
void send_control(char x, char i);
void send_data(char x);
void Initialize_LCD(void);
void puts_lcd(char *pointer);
void lcd_gotoxy(char line_number,char position);


/*
This function allows the string to be displayed on LCD
example 1:
       puts_lcd("saya");
       puts_lcd(arr1);
       puts_lcd(arr2);
*/
void puts_lcd(char *pointer){
     while(*pointer)                                         // print till null encountered
                                               send_data(*pointer++);  
}


/*
This function directs the cursor to Y and X of LCD.
Note:
     Line_number is 1/2 correspond to upper or lower ROW
     Position is 0-15 correspond to column 0-15

example:
        lcd_gotoxy(2,1);
result:
                                               cursor will be placed at ROW 2, COLUMN 1
*/
void lcd_gotoxy(char line_number,char position){
 char a;

 if(line_number==1)
          a=0x80+position;
 else if(line_number==2)
          a=0xC0+position;
 send_control(a,2);

}


/*
This function returns status of busy flag.

returns:
  0      Not busy
  1      Busy

example:
        while(check_busy());

result:
                                               the statement true if LCD is in its busy state

*/
unsigned char check_busy(void){
            RS = 0;                        // Logic ‘0’
  RW = 1;                                // Logic ‘1’     
            D_LCD|=0xf0;   // Set data line as input
  delay_0dot1ms(1);
            EN2HIGH();
            if(D_LCD&0x80){
                        EN2LOW();
                        EN2HIGH();    
                        EN2LOW();                
                        D_LCD&=0x0f;   // Set data line as output
                        return 1;
                        }
            else{
                        EN2LOW();
                        EN2HIGH();    
                        EN2LOW();                
                        D_LCD&=0x0f;   // Set data line as output
                        return 0;
                        }
}



/*
This function returns data from CGRAM/DDRAM to controller

example:
        x = read_data();
result:
        x contains CGRAM/DDRAM data
*/
char read_data(void){           
  char x;          
  while(check_busy());
           
            D_LCD|=0xf0;   // Set data line as input
  RS = 1;                                  // Logic ‘1’
  RW = 1;                                // Logic ‘1’
            delay_0dot1ms(1);
            EN2HIGH();
            x = D_LCD;
            EN2LOW();
            EN2HIGH();
            x |= D_LCD>>4;
            EN2LOW();
            D_LCD&=0x0f;   // Set data line as output
            return x;
            }


/*
This function sends control to LCD

example 1:
       send_control(x,2);
result:
                 both nibble of x will be sent to LCD
           
example 2:
       send_control(x,1);
result:
                 only lower nibble of x will be sent to LCD
*/       
void send_control(char x, char i){
  while(check_busy());
  D_LCD&=0x0f;  
  RS = 0;      
  RW = 0;     
  switch(i){
     case 2:
            D_LCD&=0x0f;     // clear previous data
            D_LCD |= x&0xf0;
            delay_0dot1ms(1);
            EN2HIGH();
            EN2LOW();
     case 1:
            D_LCD&=0x0f;    
            D_LCD |= x<<4;
            delay_0dot1ms(1);
            EN2HIGH();
            EN2LOW();
            break;
     default:
            break;
           }
}

/*
This function sends data to LCD

example:
        send_data(x);
result:
        x will be sent to LCD
*/
void send_data(char x){
            while(check_busy());
            D_LCD&=0x0f;   // Set data line as output
            RS = 1;                        // Logic ‘0’
  RW = 0;                                // Logic ‘0’
           
            D_LCD&=0x0f;                       // clear previous data
            D_LCD |= x&0xf0;
            delay_0dot1ms(1);
            EN2HIGH();
            EN2LOW();
            D_LCD&=0x0f;                       // clear previous data
            D_LCD |= x<<4;
            delay_0dot1ms(1);
            EN2HIGH();
            EN2LOW();
}

/*
This function initialize the LCD in 4-bit

void Initialize_LCD(void){
            unsigned char i;
  D_LCD = 0x00;    
  delay_0dot1ms(180);       // more than 15 ms @ 12MHz

            for(i=0; i<3; i++){
                        D_LCD &= 0x0f;                     // clear previous data
                        D_LCD |= 0x30;
                        delay_0dot1ms(1);
                        EN2HIGH();
                        EN2LOW();
                        delay_1ms(5);
            }

           
  send_control(0x02,1);
  send_control(0x28,2);                      //         function set
  send_control(0x0e,2);                      //         display ON/OFF
  send_control(0x06,2);                      //         Entry mode set          
}
            */



/*
This function initialize the LCD in 4-bit
must be called once in the main program
*/
void Initialize_LCD(void){
            char i;
            D_LCD = 0x00;                                                                                              // Set data line as output
            delay_0dot1ms(152);                                                                        // 20ms           @ 16MHz
            for(i=0; i<7; i++){
                        D_LCD&=0x0f;                                                                      // clear previous data
                        D_LCD |= set_lcd_4bit[i];
                        delay_0dot1ms(1);
                        EN2HIGH();
                        EN2LOW();
            }
}

void EN2HIGH(void){
            EN=1;
  delay_0dot1ms(1);
}

void EN2LOW(void){
            EN=0;
            delay_0dot1ms(1);
}


/*
Filename : adc0804driver.c
Auhor    : ISA
Date     : 28/11/2013

ADC0804 Driver as details below.

The connection of control lines and data should be as below
EOC   - P3.4
CS    - P3.5
WR    - P3.6
RD    - P3.7
D0/D7 - P1.0/P1.7

Please put
#include "adc0804driver.c"
    on top of main file.
Call init_ADC0804(); once in your code

This free codes are provided as is without any guarantees or warranties.

Although the author has attempted to find and correct any bugs in the codes, the author is not
responsible for any damage or losses of any kind caused by the use or misuse of the codes.

The author is under no obligation to provide support, service, corrections,
or upgrades to the programs.

Please email to i.adam.mlk@gmail for any comments and visit my blogspots
(http://maelnotesonmicrocontrollerinterfacing.blogspot.com) for any updates
*/


#define D_ADC P1
#define C_ADC P3
sbit EOC          = C_ADC^4;
sbit CS             = C_ADC^5;
sbit WRS         = C_ADC^6;
sbit RDS          = C_ADC^7;


void init_ADC0804(void);
unsigned char ADC_read(void);



void init_ADC0804(void){
            D_ADC = 0xFF;       // Set the port to 'read mode'
  EOC=1;
}


/*
unsigned char ADC_read(void)

Returns 8-bit data from ADC
example:
   i=ADC_read();
*/
unsigned char ADC_read(void){
unsigned  char x;
CS=0;delay_10us(1);                                      // select ADC
WRS=0;
WRS=1; delay_10us(1);
CS=1;
while(EOC);     // wait till end of conversion
           
CS=0;delay_10us(1);
RDS=0;delay_10us(1);
x=D_ADC;                                           // read data
RDS=1;
CS=1;
return x;
}