0% found this document useful (0 votes)
65 views

Embedded System Design - Displays

The document discusses interfacing a microcontroller with 7-segment displays and LCD displays to display numbers and characters. It provides circuit diagrams and code examples to interface a PIC microcontroller with multiple 7-segment displays to continuously display the number 876. Additionally, it explains how to interface the same microcontroller with an LCD display and use it to display voltage readings from an analog to digital converter.

Uploaded by

Ananth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Embedded System Design - Displays

The document discusses interfacing a microcontroller with 7-segment displays and LCD displays to display numbers and characters. It provides circuit diagrams and code examples to interface a PIC microcontroller with multiple 7-segment displays to continuously display the number 876. Additionally, it explains how to interface the same microcontroller with an LCD display and use it to display voltage readings from an analog to digital converter.

Uploaded by

Ananth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

BITS Pilani

presentation
BITS Pilani Faculty Name
Faculty Department
Pilani Campus
BITS Pilani
Pilani Campus

AEL ZG512 Embedded Systems


Lecture No. 2-Simple Embedded Systems
Small Scale Embedded
System Design
Display Example - 7 segment Displays
Problem Specification
User and System Design Requirements
System Block Diagram Development
Selection of Hardware and Software – Considerations
Hardware/Software design & Testing Considerations
Final System Design

BITS Pilani, Pilani Campus


Interfacing with 7 Segment Displays

In order to display a character current needs to be passed through several


LEDs by connecting the Common cathode pin to Ground and providing
current to one or more segments from a microcontroller pin.
Using a PORTB microcontroller port, an 8-bit pattern needs to be written to
display a character

BITS Pilani, Pilani Campus


Interfacing with 7 segment
Displays

0x5b

080x

BITS Pilani, Pilani Campus


Interfacing with a Controller( Single 7 segment)

BITS Pilani, Pilani Campus


Displaying three segments

Draw the circuit schematic diagram for interfacing a three digit 7-segment
LED with an 8-bit microcontroller. Explain the function of the circuit. Show
how the decimal number 876 can be displayed continuously with a short
program.

BITS Pilani, Pilani Campus


7 Segment Display

PORTB pins RB RB RB RB RB RB RB RB PORT


7 6 5 4 3 2 1 0 B
value
DP g f e d c b a
Number 8 0 1 1 1 1 1 1 1 0x7F
Number 7 0 0 0 0 0 1 1 1 0x07
Number 6 0 1 1 1 1 1 0 1 0x7D

BITS Pilani, Pilani Campus


Program – PIC 16F877A using Mikro C compiler

void main()
{
TRISC = 0x00; // Define PORTC for output operation
TRISB = 0x00; //Define PORTB for output operation

while(1)
{
PORTC = 0x01; //Make RC0 logic high – Binary value 0000 0001
PORTB = 0x7F; //Pattern for Digit 8 in Seg1
Delay_ms(10);
PORTC = 0x02;//Make RC1 logic high - Binary 0000 0010
PORTB = 0x07; //Pattern for Digit 7 in Seg2
Delay_ms(10);
PORTC = 0x04;//Make RC2 high - Binary 0000 0100
PORTB = 0x7D; //Pattern for Digit 6 in Seg3
Delay_ms(10);
}
}

BITS Pilani, Pilani Campus


Problem Specification

There are five steps to design a simple embedded system


• Requirements Definition
• System specification
• Functional Design
• Architectural Design
• Prototyping

BITS Pilani, Pilani Campus


Steps in Program - Algorithm

• In order to display a number in the first digit, transistor T1 needs to be turned ON by giving a logic
high from port pin RC0 and the data for the segment needs to be written in PORTB.
• To display the second digit in Seg2, T1 needs to be turned OFF by giving a logic low at RC0 first
and then a logic high at RC1 is given to turn ON T2 connecting the COM of display to GND. Now
PORTB is written with the data byte for display in Seg2.
• Finally the third segment is written by turning OFF T1 and T2 and turning T3 ON by making RC2
logic high and the corresponding data byte written in PORTB.
• Each segment is therefore turned ON in sequence using PORTC bits RC0, RC1 and RC2.
PORTB is then sequentially written with corresponding data bytes that will display the numbers in
each of the segments.
• To write 876 the following pattern needs to be written in PORTB.

Note: Assuming a common cathode type, each segment is lit up when a logic high voltage is given to
the anode terminal using a microcontroller port pin.

BITS Pilani, Pilani Campus


LCD Display Interface

BITS Pilani, Pilani Campus


PIC 16F877A to LCD Interface

Hardware Connections
Register Select RS-> RC3
Enable EN-> RC0
Read/Write is connected to GND
LCD data lines-> PORTD(RD0 to RD7)
Contrast VEE – Connected to a resistor divider to get 0.3V
VCC +5V
GND
LED+ Connected with series resistance to 5V (Backlight)
LED- connected to GND

BITS Pilani, Pilani Campus


BITS Pilani, Pilani Campus
LCD – 8 bit initialization
void init(void)
{
TRISA=0X01; //port-Ra0 is made as input
TRISB=0X00;
TRISC=0X00;
TRISD = 0x00;
ADCON0=0X81; //configure the A/D control registers
ADCON1=0X8E;
LCD_command(0x38); //Initialize the 2lines and 5*7matrix LCD
LCD_command(0x38);
LCD_command(0x38);
LCD_command(0x38);
LCD_command(0x06); //Increment cursor(shift cursor to right)
LCD_command(0x0c); //Display on,cursor off
LCD_command(0x01); //Clear display screen
LCD_command(0x80);
}

BITS Pilani, Pilani Campus


LCD_Command ()

void LCD_Command(unsigned char i)


{
PORTC&=~0x08; //RS=0
PORTD=i;
PORTC |= 0x01; // RS=0,R/W=0,EN=1
PORTC&= ~0x01; // RS=0,R/W=0,EN=0
Delay(100);
}
Example: Clear cursor, Blink cursor, Place cursor at a
specific location in a line are examples of commands

BITS Pilani, Pilani Campus


LCD_Data ()

void LCD_Data(char i)
{
PORTC|=0x08; //RS=1
PORTD=i; //Assign the value to PORTD to display
PORTC|=0x01; // RS=1,R/W=0,EN=1
PORTC&=~0x01; // RS=1,R/W=0,EN=0
Delay(100);
}
Example: Writing ASCII character such as LCD_Data(0x31)
to display the number 1.

BITS Pilani, Pilani Campus


Display Alpha Numeric
characters

BITS Pilani, Pilani Campus


ADC Characteristics
• 10-bit resolution
• 8 Channel Selection by Multiplexing
• Successive Approximation
• Reference Voltage Selection
INTERFACING TO ADC
Start

ADC conversion Configure TRISA, TRISE


I/O Pins (BANK 1)

Flow Chart Configure ADCON1 (BANK 1)


Analog pins, Reference voltage,
ADCON1 Justification

Configure ADCON0 (BANK 0)


Clock speed, Channel Select,
ADCON0 Enable ADC

Wait Acquisition
20µsec delay
Time

Initiate A/D Set GO/DONE bit


Conversion on ADCON0

Read ADCON0 No
GO/DONE
=0?
Yes
ADRESH:ADRESL
Read Result (BANK 0:BANK 1)

End
Steps for Conversion
1. Configure the A/D module:
• Configure analog pins / voltage reference /and
digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADCON0)
2. Wait the required acquisition time.
3. Start conversion:
• Set GO/DONE bit (ADCON0)
4. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
5. Read A/D Result register pair(ADRESH:ADRESL).
ADC Result Registers
Program
void init(void);
void LCD_command(unsigned char);
void LCD_data(unsigned char);
void LCDoutput(unsigned int);
void delay(unsigned int);
unsigned char k[10];
unsigned int voltage,hivalue,lovalue,value;
void main()
{
init();
while(1)
{
ADCON0=0x81; //configure the A/D control
registers
ADCON0|=0X04; //start ADC conversion
while(ADCON0&0X04); //wait for conversion to
complete
lovalue=ADRESL; //read the low 8 bit value
hivalue=ADRESH; //read the upper 8 bit value
value=((unsigned int)hivalue<<8)+(unsigned int)lovalue;
//load the 10 bit result into value
voltage=value*48/1023; //scale the value to the range
0.0-48.0
LCD_command(0x80);
LCDoutput(voltage); //LCD display function is
called
delay(1000);
}
}
void init(void)
{
TRISA=0X01; //port-Ra0 is made as input
TRISB=0X00;
TRISC=0X00;
ADCON0=0X81; //configure the A/D control
registers
ADCON1=0X8E;
LCD_command(0x38); //Initialize the 2lines and 5*7matrix LCD
LCD_command(0x38);
LCD_command(0x38);
LCD_command(0x38);
LCD_command(0x38);
LCD_command(0x06); //Increment cursor(shift cursor to
right)
LCD_command(0x0c); //Display on,cursor off
LCD_command(0x01); //Clear display screen
LCD_command(0x80);
}
void LCDoutput(unsigned int i)
{
unsigned char n,s,j=1;
unsigned int m;
m=i; //assign formal argument to other
variable
while(m!=0) //check that value is zero or not
{
s=m-(m/10)*10; //Store the remainder of m/10 in s
k[j]=s; //move s to an array
j++; //increment the array address
m=m/10; //Divide the value by 10,store the quotient in `m`
}
k[j]=`\0`; //assign the NULL value at the end of the array
j=j-1; //decrement the array address
if(k[2]>0)
{
n=0x30+k[2]; //convert to ascii value
LCD_data(n); //pass that value to display function
}
else LCD_data(0x20); //print a space if a zero value
n=0x30+k[1]; //convert to ascii value
LCD_data(n); //pass that value to display function
n=0x56; //print v for volts
LCD_data(n);
}
void LCD_command(unsigned char i)
{
//LCD connections
//RSRB6
//ENRB7
PORTB&=~0x40; //RS=0
PORTC=i;
PORTB|=0x80; //RS=0,R/W=0,EN=1
PORTB&=~0x80; //RS=0,R/W=0,EN=0
delay(10);
}
void LCD_data(char i)
{
PORTB|=0X40; //RS=1
PORTC=i; //assign the value to
portc to display
PORTB|=0x80; //RS=1,R/W=0,EN=1
PORTB&=~0x80; //RS=1,R/W=0,EN=0
delay(10);
}
void delay(unsigned int delaycount)
{
while(--delaycount);
}

You might also like