U of U ECE 3720 - ECE 3720 Lecture Notes
Pages 10

Unformatted text preview:

Slide 1'&$%ECE/CE 3720: Embedded System DesignChris J. MyersLecture 17: Output LEDs and LCDsSlide 2'&$%Interfacing Multiple LEDs(See Figure 8.29)1Slide 3'&$%Single LED Interface(See Figures 8.30 and 8.31)Slide 4'&$%Output Param. for Open-Collector/Emitter Gates(See Tables 8.4 and 8.5)2Slide 5'&$%Typical Voltage/Current Response of a LED(See Figure 8.32 and Table 8.6)Slide 6'&$%Calculating the Resistor Value(See Figure 8.33)3Slide 7'&$%Seven-Segment LED Interfaces (Common-Cathode)(See Figure 8.34)Slide 8'&$%Seven-Segment LED Interfaces (Common-Anode)(See Figure 8.35)4Slide 9'&$%Scanned Seven-Segment LED Interface(See Figures 8.36 and 8.37, Table 8.7)Slide 10'&$%Circuit Used to Scan a LED Interface(See Figure 8.38)5Slide 11'&$%Software for Scanned LED Display// PB7-PB0 output, 7 bit pattern// PC2-PC0 output, selects LED digitunsigned char code[3]; // binary codesstatic unsigned char select[3]={4,2,1};unsigned int index; // 0,1,2#define OC5F 0x08void ritual(void) {asm(" sei"); // make atomicindex=0;DDRC=0xFF; // outputsTMSK1|=OC5F; // Arm OC5TFLG1=OC5F; // clear OC5FTOC5=TCNT+10000;asm(" cli"); }Slide 12'&$%Software for Scanned LED Display#pragma interrupt_handler TOC5handler()void TOC5handler(void){TFLG1=OC5F; // AcknowledgeTOC5=TOC5+10000; // every 5 msPORTC=select[index]; // which LED?PORTB=code[index]; // enableif(++index==3) index=0;}6Slide 13'&$%Scanned LED Interface Using Decoder(See Figure 8.39)Slide 14'&$%Software for Multiplexed LED Displayunsigned int global; // 12 bit packed BCDconst struct LED{ unsigned char enable; // selectunsigned char shift; // bits to shiftconst 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 sigLEDPtr Pt; // Points to current digit#define OC5F 0x087Slide 15'&$%Software for Multiplexed LED Display#pragma interrupt_handler TOC5handler()void TOC5handler(void){TFLG1=OC5F; // AcknowledgeTOC5=TOC5+10000; // every 5 msPORTB=(Pt->enable)+(global>>(pt->shift))<<4);Pt=Pt->Next; }void ritual(void) {asm(" sei"); // make atomicglobal=0;TMSK1=OC5F; // Arm OC5Pt=&LEDTab[0];TFLG1=OC5F; // clear OC5F */TOC5=TCNT+10000;asm(" cli"); }Slide 16'&$%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 × #digits2. Duty cycle - this decreases as digits added, so mustincrease instantaneous current.– instantaneous current = desired current × #digits• Ratio of maximum instantaneous current to desired LEDcurrent determines maximum number of digits.8Slide 17'&$%Integrated IC Interface for LED Digits(See Figure 8.40)Slide 18'&$%Data Timing of Integrated LED Controller(See Figures 8.41 and 8.42)9Slide 19'&$%Software for Integrated LED Display// PD3/MOSI = MC14489 DATA IN// PD4/SCLK = MC14489 CLOCK IN// PD5 (simple output) = MC14489 ENABLEvoid ritual(void) {DDRD |= 0x38; // outputs to MC14489SPCR=0x50;PORTD|= 0x20; // ENABLE=1PORTD&= 0xDF; // ENABLE=0SPDR=0x01; // hex formatwhile(SPSR&0x80)==0){};PORTD|=0x20;} // ENABLE=1Slide 20'&$%Software for Integrated LED Displayvoid LEDout(unsigned char data[3]){// 24 bit packed BCDPORTD &= 0xDF; // ENABLE=0SPDR = data[2]; // send MSbytewhile(SPSR&0x80)==0){};SPDR = data[1]; // send middle bytewhile(SPSR&0x80)==0){};SPDR = data[0]; // send LSbytewhile(SPSR&0x80)==0){};PORTD |= 0x20;} // ENABLE=110Slide 21'&$%LCD Fundamentals• LCD display consume less power than LED displays.• LCDs are more flexible in sizes and shapes, allowing forcombination of numbers, letters, words, and graphics.• Uses liquid-crystal material that behaves as a capacitor.• While LED converts electric power to emitted opticalpower, 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, buttypically fast enough for human perception.Slide 22'&$%Basic Idea of a Liquid Crystal Interface(See Figures 8.43, 8.44, and 8.45)11Slide 23'&$%Direct Interface of a LCD(See Figure 8.46)Slide 24'&$%Helper Function for a Simple LCD Displayvoid LCDOutDigit(unsigned char position,unsigned char data) {// position is 0x80, 0x40, 0x20, or 0x10// and data is the BCD digit// set BCD digit on A-D inputs of the MC14543BPORTB=0x0F&data;// toggle one of the LD inputs highPORTB|=position;// LD=0, latch digit into MC14543BPORTB=0x0F&data;}12Slide 25'&$%Software Interface for a Simple LCD Displayvoid LCDOutNum(unsigned int data){unsigned int digit,num,i;unsigned char pos;// data should be unsigned from 0 to 9999num=min(data,9999);pos=0x10; // position of first digit (ones)for(i=0;i<4;i++){// next BCD digit 0 to 9digit=num%10; num=num/10;LCDOutDigit(pos,digit); pos=pos<<1;}}Slide 26'&$%Latched Interface of a LCD(See Figure 8.47)13Slide 27'&$%Artwork for 8-Segment LCD Digits(See Figures 8.48 and 8.49)Slide 28'&$%LCD Timing(See Figures 8.50 and 8.51)14Slide 29'&$%LCD Timing (cont)(See Figures 8.52 and 8.53)Slide 30'&$%Interface of a 48-Segment LCD Display(See Figure 8.54)15Slide 31'&$%Bit-Banged Interface to a Scanned LCD Displayvoid LCDOut (unsigned char *pt) {unsigned int i;unsigned char mask;for(i=0;i<6;i++){// look at bits 7,6,5,4,3,2,1,0for(mask=0x80;mask;mask=mask>>1){if((*pt)&mask) PORTB=1;else PORTB=0; // Serial data of the MC145000PORTB|=2; // toggle the serial clock highPORTB&=0xFD;} // then lowpt++; }}Slide 32'&$%SPI Interface to a Scanned LCD Display// PD3/MOSI = MC145000 DATA IN// PD4/SCLK = MC145000 CLOCK INvoid ritual(void) {DDRD |= 0x18; // outputs to MC145000SPCR=0x50; }void LCDout(unsigned char data[6]){unsigned int j;for(j=5; j>=0 ; j--){SPDR = data[j]; // Msbyte firstwhile(SPSR&0x80)==0){};}}16Slide 33'&$%Interface of a HD44780 LCD Controller(See Figure 8.55 and Table 8.8)Slide 34'&$%Private Functions for LCD Display// 1 by 16 char LCD Display (HD44780)#define LCDdata 1 // PB0=RS=1#define LCDcsr 0 // PB0=RS=0#define LCDread 2 // PB1=R/W=1#define LCDwrite 0 // PB1=R/W=0#define LCDenable 4 // PB2=E=1#define LCDdisable 0 // PB2=E=0void LCDcycwait(unsigned short cycles){TOC5=TCNT+cycles; // 500ns cyclesTFLG1 = 0x08; // clear C5Fwhile((TFLG1&0x08)==0){};}17Slide 35'&$%Public Functions for LCD Displayvoid LCDinit(void){DDRC=0xFF;LCDputcsr(0x06);// I/D=1 Increment, S=0


View Full Document

U of U ECE 3720 - ECE 3720 Lecture Notes

Course: Ece 3720-
Pages: 10
Download ECE 3720 Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ECE 3720 Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ECE 3720 Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?