applictaions.8051
TRANSCRIPT
-
8/3/2019 Applictaions.8051
1/17
APPLICATIONS OF 8051
Analog to Digital Conversion
(ADC 0804)
DC-Voltmeter
by. Engr. Khurram Hashmi
-
8/3/2019 Applictaions.8051
2/17
Introduction
One of the applications that an 8051 micro-Controllermight provide is in cohesion with Analog to DigitalConversion ICs
ADC 0804 or ADC 0808
ADC 01101011
-
8/3/2019 Applictaions.8051
3/17
Flow Representation
ADC converts Analog input to Digital8 bit output
8051 handles this data
Algorithms implemented to converthex standard format to ASCII anddisplayed on LCD
ADC 01101011
8051
LCD Display
8 bit
voltage signal
-
8/3/2019 Applictaions.8051
4/17
Circuit Diagram
-
8/3/2019 Applictaions.8051
5/17
Voltage Divider Input
Voltage Input takenacross voltage Divider.
Max of 5volts appears atInput pins
8bit
DB0-DB7 to 8051
-
8/3/2019 Applictaions.8051
6/17
LCD Display Output
Output read at Port 1and intrinsicallyprocessed as Hexvalues
Algorithm converts hexvalued to ASCIIequivalents and Displays
on LCD
-
8/3/2019 Applictaions.8051
7/17
Algorithm
Lcd.h
A Library file that defines function prototypesused in files
Lcd.cContains functions involved in coveting hex data
to ASCII and writing it to LCD
Voltmeter.cContains functions for reading ADC output and
passes this to LCD write functions in Lcd.c
-
8/3/2019 Applictaions.8051
8/17
Lcd.h a header file
#ifndef __LCD_H__
#define __LCD_H__
#include
#define lcd_port P2 // Where the LCD is attached and output to LCD shall be sent
#define rs P3_0 // READ#define rw P3_1 // WRITE
#define en P3_2 // ENABLE
#define flag P2_7 // D7 of LCD the Busy Flag
void wrt_cmd(unsigned char);
void wrt_data(unsigned char);
void wrt_string(unsigned char*);
void LCD_INI(void);
void busy(void);
void hex2lcd(unsigned char);
#endif
Function prototypes
LCD
-
8/3/2019 Applictaions.8051
9/17
Voltmeter.c
#include
#include "lcd.h"
#define adc_port P1 //Port where ADC output is attached
#define rd P3_7 //Assigning Read signal P3.7
#define wr P3_6 //Assigning Write signal P3.6
#define cs P3_5 //Assigning Chip Select P3.5
#define intr P3_4 //Assigning INTR signal P3.4
void conv(); // Start of conversion function called
void read(); //Read ADC function called
unsigned int adc_avg , adc; //defining two integers
ADC
-
8/3/2019 Applictaions.8051
10/17
ADC 0804 Timing diagram
-
8/3/2019 Applictaions.8051
11/17
voltmeter.c continued
void conv( )
{
cs = 0; //Make CS low
wr = 0; //Make WR low
wr = 1; //Make WR high
cs = 1; //Make CS high
while(intr); //Wait for INTR to go low
}
void read( )
{
cs = 0; //Make CS low
rd = 0; //Make RD lowadc = adc_port; //Read ADC port
rd = 1; //Make RD high
cs = 1; //Make CS high
}
Low Active pins on ADC
Activates ADC output
When CS=0Low to High transition of WRStarts data conversionAnalog to BCD
at the end of which INTR pin goes lowas an indication to the CPU
Low Active pins on ADCrestored to high for next reading
-
8/3/2019 Applictaions.8051
12/17
void main() {
char i; //a counter variable i
LCD_INI(); //Initiate LCD
while(1){ //Forever loop
adc_avg = 0;
for(i=0;i
-
8/3/2019 Applictaions.8051
13/17
Lcd.c
void busy(){
flag=1; //Set flag
rs=0; //RS low select instruction command register to send command
rw=1; //RW high reading informtion
while(flag!=0) / /untill LCD hasnt completed its operation
{
en=0; //high to low
en=1; //Low to high
}
}
void wrt_cmd(unsigned char val_lcd)
{
busy(); // check if LCD is NOT BUSY
lcd_port=val_lcd; // send data to LCD port
rs=0; /Instruction Register Selected
rw=0; //for writing information
en=1; //high to low latch for enable
en=0;
For writing a Command to the LCDSuch as clear screen,cursor shift
EN high to Low transition Latches
in Information
Check to see ifLCD is Busy
-
8/3/2019 Applictaions.8051
14/17
Lcd.c continued.
void wrt_data(unsigned char dat)
{
busy();
lcd_port=dat;
rs=1;
rw=0;en=1; //high to low
en=0; //to latch the data present on the data pins
}
void wrt_string(unsigned char *string)
{while(*string)
wrt_data(*string++);
}
For Writing Data to LCDAs A or 55.3 etc
EN high to Low transition Latchesin Information
For Writing String Data to LCD
As V(DC):Achieved through incrementinggradually and passing to LCD
-
8/3/2019 Applictaions.8051
15/17
Lcd.c continued.
void LCD_INI(void)
{
wrt_cmd(0X30); //initiate LCD
wrt_cmd(0X0C);
wrt_cmd(0X01); //clear LCD
wrt_cmd(0X06); //shift cursor right
}
Initiates the LCD
-
8/3/2019 Applictaions.8051
16/17
void hex2lcd ( unsigned char hex)
{ //converts hex to AASCII and displays on LCD
char temp1, temp2; //temporary variables
temp1 = hex;
temp2=0;
do{
temp1 = temp1-100;
if(temp1>=0)
temp2++;
} while(temp1>=0);
if(temp2>0)
wrt_data(temp2+0x30);
temp2=0;
temp1 = temp1+100;
do{
temp1 = temp1-10;
if(temp1>=0)
temp2++;
} while(temp1>=0);
wrt_data(temp2+0x30);
temp2 = temp1+10;
wrt_data(temp2+0x30);}
Converts HEX values to ASCII and Sends to LCD Port
hex
Hex ASCII
30 031 1
. .
57 9
Tens
digitHundreds
digitUnitsdigit
+30 H +30 H +30 H
Unit
DgitTens digit
Fractional
digit
LCD
-
8/3/2019 Applictaions.8051
17/17
by
Engr. Khurram Hashmi
Faculty of Engineering
University of Central Punjab