Wednesday 16 October 2013

HOW CONVERT ARRAY OF ELEMENTS INTO DECIMAL VALUE



Convert Array data to an decimal number
In some programs it is necessary to convert the array elements into an integer value like receive value from keyboard and set the value as input for countdown timer.4x3 or 4x4 matrix keypads will give one key value at one time and LCD Display also display only one number at a time. So  if we need to display keyboard value 5432 you need to convert separate value of 5,4,3,2 into 5432 to set the timer. You can use this program for convert array elements to an integer.




Microcontroller AT89C51:

Microcontroller AT89C51 is at the heart of the circuit. It is a low power, high performance, 8-bit microcontroller with 4 kB of flash programmable and erasable read-only memory (PEROM) used as on-chip program memory, 128 bytes of RAM used as internal data memory, 32 individually programmable input/output (I/O) lines divided into four 8-bit ports, two 16-bit programmable timers/counters, a five-vector two-level interrupt architecture, on-chip oscillator and clock circuitry. A 11.0592MHz crystal (XTAL1) is used to provide basic clock frequency for the microcontroller. Capacitor C3 and resistor R3 form the power-on reset circuit, while push-to-on switch S20 is used for manual reset.


Liquid Crystal Display (LCD):

Liquid crystal display a type of display used in digital watches and many portable computers.LCD displays utilize two sheets of polarizing material with a liquid crystal solution between them. An electric current passed through the liquid causes the crystals to align so that light cannot pass through them. Each crystal, therefore, is like a shutter, either allowing light to pass through or blocking the light.

The liquid crystals can be manipulated through an applied electric voltage so that light is allowed to pass or is blocked. By carefully controlling where and what wavelength (color) of light is allowed to pass, the LCD monitor is able to display images. A back light provides LCD monitor’s brightness.Other advances have allowed LCD’s to greatly reduce liquid crystal cell response times. Response time is basically the amount of time it takes for a pixel to “change colors”. In reality response time is the amount of time it takes a liquid crystal cell to go from being active to inactive. Here the LCD is used at both the Transmitter as well as the receiver side. The input which we give to the microcontroller is displayed on the LCD of the transmitter side and the message sent is received at the receiver side which displays at the receiver end of the LCD and the corresponding operation is performed.

They make complicated equipment easier to operate. LCDs come in many shapes and sizes but the most common is the 16 character x 4 line display with no backlight. It requires only 11 connections – eight bits for data (which can be reduced to four if necessary) and three control lines (we have only used two here). It runs off a 5V DC supply and only needs about 1mA of current. The display contrast can be varied by changing the voltage into pin 3 of the display.

 Power Supply Unit

The power supply unit is used to provide constant 5 V dc supply to the peripherals. The 230 V ac is converted into 9 V ac by using a transformer and then a bridge rectifier rectifies it to a 9 V dc with ac ripples. This is then filtered by electrolytic capacitors used across the rectifier output. LM7805 regulator is employed to obtain a constant 5 V dc at the output.




 Convert Array data to an decimal number Program:


 #include<reg51.h>
sfr lcd_data_pin=0xA0;  // data port P2
sbit rs=P3^0; // Register select pin
sbit rw=P3^1; // Read write pin
sbit en=P3^6; // Enable pin
void delay(unsigned int msec)    //delay function
{
int i,j;                                   
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}
void lcd_data(unsigned char disp)    // function to send data on LCD
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void main()
{
 unsigned int i,s,test_final,test_final_1,test_final_2,test_final_3,test_final_4,test_final_5;
unsigned int value[4]={5,4,3,2};
while(1)
{
lcd_command(0x38);  
delay(5);
lcd_command(0x0F);      
delay(5);
lcd_command(0x80);
delay(5);
  i=value[0]*1000+value[1]*100+value[2]*10+value[3];
                  test_final=i;               
                  s=test_final/10000;                                               
                   if(s!=0)
                    {
                      lcd_data(s+48);
                       delay(250);
                    }
                   else
                     {                            
                            s=test_final/1000;
                            test_final_1=test_final%1000;
                             test_final_2=test_final_1/100  
                             test_final_3=test_final_1%100;
                              test_final_4=test_final_3/10;
                             test_final_5=test_final_3%10;
                            lcd_data(s+48);
                             lcd_data(test_final_2+48);
                               lcd_data(test_final_4+48);
                                 lcd_data(test_final_5+48);                           
                                                                  
             }                                

    }
}
                                                                       

 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...