• No results found

ECE/CS 5780/6780: Embedded System Design

N/A
N/A
Protected

Academic year: 2020

Share "ECE/CS 5780/6780: Embedded System Design"

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

ECE/CS 5780/6780: Embedded System Design

Chris J. Myers

Lecture 16: Keyboards and Displays

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 1 / 43

Basic Approaches to Interfacing Multiple Keys

Row

Out3

Out2

Out1

Out0

3

0

HiZ

HiZ

HiZ

2

HiZ

0

HiZ

HiZ

1

HiZ

HiZ

0

HiZ

0

HiZ

HiZ

HiZ

0

Row

Out3

Out2

Out1

Out0

15

14

. . .

0

15

1

1

1

1

0

HiZ

. . .

HiZ

14

1

1

1

0

HiZ

0

. . .

HiZ

. . .

. . .

. . .

. . .

. . .

. . .

. . .

. . .

. . .

0

0

0

0

0

HiZ

HiZ

. . .

0

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 2 / 43

Sixteen-Key Electronic Piano

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 3 / 43

Hardware for Generating Interrupts

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 4 / 43

Multiplexed/Demultiplexed Scanned Keyboard

Software for Multiplexed Keyboard

unsigned char Key;

// current pattern

unsigned char PreviousKey;

// 10 ms ago

#define period 20000

// 10 ms

unsigned char KeyScan(void){

unsigned char key,row;

key=0;

// means no key pressed

for(row=0;row<16;row++){

PORTJ=row<<4;

// Select row

if((PORTJ&0x0F)!=0x0F){

(2)

Software for Multiplexed Keyboard (cont)

void Ritual(void){

asm(" sei");

// make atomic

DDRJ=0xF0;

PreviousKey=Key=KeyScan(); // read

TMSK1|=0x20;

// Arm OC5

TIOS|=OC5;

// enable OC5

TSCR|=0x80;

// enable

TMSK2=0x32;

// 500 ns clock

TC5=TCNT+wait;

TFLG1=0x20;

// clear OC5F

asm(" cli"); }

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 9 / 43

Software for Multiplexed Keyboard (cont)

#pragma interrupt_handler TOC5handler()

void TOC5handler(void){

unsigned char NewKey;

NewKey=KeyScan();

// Current pattern

if(NewKey==PreviousKey) Key=NewKey;

PreviousKey=NewKey;

TOC5=TOC5+period;

TFLG1=0x20;}

// ack OC5F

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 11 / 43

Interfacing Multiple LEDs

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 12 / 43

Single LED Interface

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 13 / 43

Typical Voltage/Current Response of a LED

Parameter

red

green

yellow

orange

units

Max power

55

75

60

75

mW

Peak current

160

100

80

100

mA

Max current

25

25

20

25

mA

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 14 / 43

Calculating the Resistor Value

(3)

Seven-Segment LED Interfaces (Common-Cathode)

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 16 / 43

Seven-Segment LED Interfaces (Common-Anode)

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 17 / 43

Scanned Seven-Segment LED Interface

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 18 / 43

Circuit Used to Scan a LED Interface

For MC9S12C32, replace PB with PT and PC with PM.

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 19 / 43

Software for Scanned LED Display

// PT7-PT0 output, 7 bit pattern

// PM2-PM0 output, selects LED digit

unsigned char code[3]; // binary codes

static unsigned char select[3]={4,2,1};

unsigned short index;

// 0,1,2

void LED_Init(void) {

asm sei

// make atomic

index = 0;

DDRT = 0xFF;

// outputs 7 segment code

DDRM |= 0x03;

// outputs select LED

TIE |=0x20;

// Arm OC5

TIOS |=0x20;

// enable OC5

TSCR1 =0x80;

// enable

TSCR2 =0x01;

// 500 ns clock

TC5 = TCNT+10000;

asm cli }

Software for Scanned LED Display

void interrupt 13 TC5handler(void){

TFLG1 = 0x20;

// Acknowledge

TC5 = TC5+10000;

// every 5 ms

PTM = select[index]; // which LED?

PTT = code[index];

// enable

(4)

Scanned LED Interface Using Decoder

For MC9S12C32, replace PB with PT.

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 24 / 43

Software for Multiplexed LED Display

unsigned short Global; // 12-bit packed BCD

const struct LED

{ unsigned char enable; // select

unsigned char shift;

// bits to shift

const struct LED *Next; };

// Link

typedef const struct LED LEDType;

typedef LEDType * LEDPtr;

LEDType LEDTab[3]={

{ 0x04, 8, &LEDTab[1] },

// Most sig

{ 0x02, 4, &LEDTab[2] },

{ 0x01, 0, &LEDTab[0] }}; // least sig

LEDPtr Pt;

// Points to current digit

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 26 / 43

Software for Multiplexed LED Display (cont)

void LED_Init(void) {

asm sei

// make atomic

DDRT = 0xFF;

// outputs to LED’s

Global = 0;

Pt=&LEDTab[0];

TIE |= 0x20;

// Arm OC5

TIOS |= 0x20;

// enable OC5

TSCR1 = 0x80;

// enable

TSCR2 = 0x01;

// 500 ns clock

TC5 = TCNT+10000;

asm cli }

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 28 / 43

Software for Multiplexed LED Display (cont)

void interrupt 13 TC5handler(void){

TFLG1 = 0x20;

// Acknowledge

TC5 = TC5+10000;

// every 5 ms

PTT = (Pt->enable)

+(Global>>(pt->shift))<<4);

Pt = Pt->Next; }

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 30 / 43

Extensions to Multiple Digits

Two issues to consider as number of digits is increased:

1

Scan frequency - for display to “look” continuous, each digit must be

updated faster than 60 Hz.

interrupt rate = 60 Hz

×

#digits

2

Duty cycle - this decreases as digits added, so must increase

instantaneous current.

instantaneous current = desired current

×

#digits

Ratio of maximum instantaneous current to desired LED current

determines maximum number of digits.

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 31 / 43

Integrated IC Interface for LED Digits

(5)

Data Timing of Integrated LED Controller

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 33 / 43

Software for Integrated LED Display

// PM4/MOSI = MC14489 DATA IN

// PM5/SCLK = MC14489 CLOCK IN

// PM3 (simple output) = MC14489 ENABLE

void LED_Init(void) {

DDRM |= 0x38;

// outputs to MC14489

SPICR1 = 0x50;

SPICR2 = 0x00; // regular drive

SPIBR = 0x01;

// 1MHz SCLK

PTM |= 0x08;

// ENABLE=1

PTM &=~0x08;

// ENABLE=0

SPIDR= 0x01;

// hex format

while(SPISR&0x80)==0){};

PTM |=0x08;}

// ENABLE=1

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 35 / 43

Software for Integrated LED Display

void LED_out(unsigned char data[3]){

unsigned char dummy;

PTM &=~0x08;

// ENABLE=0

while((SPISR&SPTEF)==0); // wait for transmit empty

SPIDR = data[2];

// send MSbyte

dummy = SPIDR;

// clear SPIF

while((SPISR&SPTEF)==0); // wait for transmit empty

SPIDR = data[1];

// send middle byte

dummy = SPIDR;

// clear SPIF

while((SPISR&SPTEF)==0); // wait for transmit empty

SPIDR = data[0];

// send LSbyte

dummy = SPIDR;

// clear SPIF

Timer_Wait(10);

// wait for SPI output completion

PTM |=0x08;}

// ENABLE=1

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 37 / 43

LCD Fundamentals

LCD display consume less power than LED displays.

LCDs are more flexible in sizes and shapes, allowing for combination of

numbers, letters, words, and graphics.

Uses liquid-crystal material that behaves as a capacitor.

While LED converts electric power to emitted optical power, LCD uses AC

voltage to change light reflectivity.

Light energy is supplied by room or separate back light.

Display controlled by altering reflectivity of each segment.

Disadvantage is that they have slow response time, but typically fast

enough for human perception.

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 38 / 43

(6)

Latched Interface of a LCD

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 41 / 43

Artwork for 8-Segment LCD Digits

Chris J. Myers (Lecture 16: Keys and Displays) ECE/CS 5780/6780: Embedded System Design 42 / 43

Interface of a 48-Segment LCD Display

References

Related documents

Status rmb 1 0 means empty, -1 otherwise Message rmb 1 data to be communicated * Input param: Reg B contains an 8 bit message. * Output param: Reg CC (C bit) is 1 for OK, 0 for

Myers (Lecture 9: 6812 Interrupts) ECE/CS 5780/6780: Embedded System Design 1 / 52.. General Features

Myers (Lecture 13: Output Compare) ECE/CS 5780/6780: Embedded System Design 34 / 56.. Period Measurement with ∆p

Receive Data Register Full flag (RDRF), set when new data available, clear by reading RDRF and SCDR.. Receiver Idle flag (IDLE), set when receiver line is idle, clear by reading

Myers (Lecture 18: Filters/DACs) ECE/CS 5780/6780: Embedded System Design 7 / 35..

You do not need to write the main program as the interrupt handler should do everything specified anyway.

This non-invasive optical measurement method is based on radiation of red and near infrared light, emitted by Light Emitting Diodes (LED) in the range of 600nm to 1400nm.The

TX-ET5 DC/DC Power for Panel drive Dr Dr DC/DC Power for LED TNPH0993 Back Light (LED) TNPA5587 IC8000 ( Peaks LD4 ) Resize IP conv.. Structure of LCD Panel and Signal Process