The University of Texas at Arlington Lecture 8Lecture...

34
The University of Texas at Arlington Lecture 8 Lecture 8 CSE 3442/5442

Transcript of The University of Texas at Arlington Lecture 8Lecture...

Page 1: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

The University of Texas at Arlington

Lecture 8Lecture 8

CSE 3442/5442

Page 2: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Agenda Thursday September 24Agenda Thursday September 24

• Exam1 Thursday, October 1st.• HW4 Due todayy• Answers to HW3• LAB3 begins next week (2 weeks for• LAB3 begins next week (2 weeks for

completion).Using LCD with PIC• Using LCD with PIC

CSE 3442/4442 Lecture 9 Dr. Roger Walker

2

Page 3: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Assignment 3 Chapter 5Assignment 3 Chapter 5

On pages 187 – 189 Chapter 5 in your textOn pages 187 189, Chapter 5 in your text, work problems 1, 8, 14, 15, 16, 17, 21, 22, 25 and 2725, and 27.

CSE 3442/4442 Lecture 9 Dr. Roger Walker

3

Page 4: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Parity and Check SumParity and Check Sum

• Parity and Check Sum: Parity andParity and Check Sum: Parity and checksum are used to help insure data is transmitted from one module to anothertransmitted from one module to another without loss of bits or data. Your text discusses check sum in Chapter 5discusses check sum in Chapter 5. Neither method will guarantee signal integrity but are simple methods oftenintegrity, but are simple methods often used for aiding loss of information in communications

CSE 3442/5442 Lecture 9 Dr. Roger Walker

4

communications.

Page 5: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Parity and Check SumParity and Check Sum

Check Sum:Check Sum:1. Add the bytes and ignore the carries2 The 2’s complement of the result in 1 forms2. The 2 s complement of the result in 1. forms

the check sum.Parity:Parity:For odd carry, count the number of ones in each

column. Make the carry bit for that column one co u a e t e ca y b t o t at co u o eif there is an even number of ones. If an odd number the carry bit should be zero.

CSE 3442/5442 Lecture 9 Dr. Roger Walker

5

Page 6: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Parity and Check Sum – cont.Parity and Check Sum cont.

• Parity Example Check Sum ExampleParity Example Check Sum Example1001 400110 200110 201101 311111 91 = 1001 00010010 Or 2’s Comp 0110 11110010 Or 2 s Comp. 0110 1111

CSE 3442/5442 Lecture 9 Dr. Roger Walker

6

Page 7: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

In Class Assignment #2 – cont.In Class Assignment #2 cont.

• The Hex files generated by Microchip’sThe Hex files generated by Microchip s assembler uses a check sum with each load fileload file.

• Additional information can be found on the web at the following two links:web at the following two links: http://en.wikipedia.org/wiki/Parity_bithttp://en wikipedia org/wiki/Checksumhttp://en.wikipedia.org/wiki/Checksum

CSE 3442/5442 Lecture 9 Dr. Roger Walker

7

Page 8: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Parity and ChecksumParity and Checksum

Additional Examples:Additional Examples: The (vertical) parity and checksum bytes for the

following four hex bytes are 35 (0011 0101) and g y ( )E8 respectively.23 (0010 0011) 23 + A2 + 8F + C4 = 218h( )A2 (1010 0010) 0001 1000’ = 1110 0111 = 8F (1000 1111) E7 + 1 = E8 C4 (1100 0100)

0011 0101 – 35 Parity (odd)

CSE 3442/5442 Lecture 9 Dr. Roger Walker

8

y ( )

Page 9: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Parity and Checksum– cont.Parity and Checksum cont.

Compute first the odd (vertical) parity byteCompute first the odd (vertical) parity byte and then checksum for the following bytes:

1 0010 1001 291. 0010 1001 291101 0111 D71000 1010 8A1100 1001 C9

CSE 3442/5442 Lecture 9 Dr. Roger Walker

9

Page 10: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Lab 3 – Working with the LCD Di lDisplay.

• Part 1:Part 1:• Write a program that will display all the

characters supported by the LCD in thecharacters supported by the LCD in the QwikFlash board.

• The program should display the charactersThe program should display the characters starting from the first location of line 1; the next character will be displayed in the second location of line 1 and so on until the first line is full then start displaying the characters in line 2.

CSE 3442/4442 Lecture 9 Dr. Roger Walker

10

Page 11: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Lab 3 - ContinuedLab 3 Continued

• Part 1 - Continued:Part 1 - Continued:Once line 2 is full clear the contents of line 1 and

continue displaying the rest of the characters incontinue displaying the rest of the characters in the same way. When finished displaying, move to the next line.

• 2. Repeat this process until all the characters are displayed. You are not allowed to create an array (or arrays) for the character set supported by the LCD, instead use the character's ASCII

dcode.CSE 3442/4442 Lecture 9

Dr. Roger Walker11

Page 12: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Lab 3 - ContinuedLab 3 Continued

• Part 2:Part 2:• Write a function to display the following

equationsequations• X = α * Σ β * Y,• Y = sin(Ω*t)

CSE 3442/4442 Lecture 9 Dr. Roger Walker

12

Page 13: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Lab 3 - ContinuedLab 3 Continued

• Part 3:Part 3:• During the lab session a new character will

be assigned to you in order to add it to thebe assigned to you in order to add it to the user-defined characters. Write a function that will continuously display the newthat will continuously display the new character in the center of line 1 for 1 sec then in the center of line 2 for 1 secthen in the center of line 2 for 1 sec.

CSE 3442/4442 Lecture 9 Dr. Roger Walker

13

Page 14: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Using LCDswith PIC

14

Page 15: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

LCD Pi P itiLCD Pin Positions

15

Page 16: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

LCD I t fLCD Interface

For our embedded PC we used

Just another I/O device

Input or Output

16

Page 17: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Wiring the LCD using Embedded PC and 8255

Configure Ports A & B as output Data pins connect to port A

LCD RS t PB0 LCD-RS to PB0 LCD-R/W to PB1 LCD-E to PB2 LCD-E to PB2

17

Page 18: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

S di D t t th LCDSending Data to the LCD

• Set RS=1S d hi h t l l t E t bl• Send high-to-low pulse to E to enable latching of the data

• Data sent is ASCII value of character to be displayed

18

Page 19: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

PIC Interface

Page 20: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

4 – Bit Interface4 Bit Interface

Lines RD0-RD4 – NoNo Connection

Page 21: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Display ControlDisplay Control

Page 22: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Display Control TimingDisplay Control Timing

Page 23: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Intialize 4 Bit LCDIntialize 4 Bit LCD

• Insure Controller of LCD finished ownInsure Controller of LCD finished own power on reset wait 0.1 seconds

• Drive RS low and leave low for entire• Drive RS low and leave low for entire initialization.S d i iti li ti t i f 4 bit i t f• Send initialization string for 4 bit interface:

• const char LCDstr[] = 0x33,0x32,0x28,0x01,0x0c,0x06,0x00,0x00;// LCD Initialization string

Page 24: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Intialize 4 Bit LCD contIntialize 4 Bit LCD cont

PORTEbits.RE0 = 0; // RS 0 f d// RS=0 for command tempPtr = LCDstr; while (*tempPtr) // if the byte is not zero// if the byte is not zero currentChar = *tempPtr;PORTEbits.RE1 = 1; // Drive E pin high// Drive E pin high PORTD = currentChar;// Send upper nibble PORTEbits.RE1 = 0; ;// Drive E pin low so LCD will accept nibble LoopTime();

Page 25: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Intialize 4 Bit LCD cont

currentChar <<= 4;

Intialize 4 Bit LCD cont

currentChar 4; // Shift lower nibble to upper nibble PORTEbits.RE1 = 1; // Drive E pin high again PORTD = currentChar; // Write lower nibble PORTEbits.RE1 = 0; // Drive E pin low so LCD will process byte LoopTime(); // Wait 40 usec tempPtr++;tempPtr++; // Increment pointerto next character

Page 26: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

For 8 Bit InterfaceFor 8 Bit Interface

• const char LCDstr[] = 0x38 0x38 0x38 0380x38,0x38,0x38,038, 0x01,0x0c,0x06,0x06,0x00;// LCD Initialization string for 8 bit interfaceInitialization string for 8 bit interface

Page 27: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

Display StringsDisplay Strings

• Where should the display beginWhere should the display begin• What characters should be displayed.

• Use Figure 12-5 for 8x2 LCD on QwikFlash

• 0x80 0x81 0x82 ………0x87• 0xc0 0xc1 ……………..0xc7

Page 28: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

What Characters to DisplayWhat Characters to Display

• For the Hitachi HD44780 compatible controller:For the Hitachi HD44780 compatible controller:1. Codes between 0x20 and 0x7f ASCII character

set2. Codes between 0xa0 and 0xff produce

Japanese charactersp3. Codes between 0x00 and 0x07 produce eight

user-defined characters. These are also available with codes between 0x08 and 0x0f.

Page 29: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

“Embedded Design with the PIC18F452 MicrocontrollerPrentice Hall, 2003” Peatman

29

Page 30: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

What Characters to DisplayWhat Characters to Display

• const char StrtStr[] = 0x80,'P','u','s','h',' ','P','B',' [] , , , , , , , ,',0;// Startup screen

• void Screens() • …………..• DisplayC(FreqStr); • Frequency(); // MAYBE TO DISPLAY A FREQ

VALUE•• ……………• const char FreqStr[] = 0x80,'F','r','e','q','

' 'k' 'H' 'z' 0;// Frequency instrument, k , H , z ,0;// Frequency instrument

Page 31: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

User Defined CodesUser Defined Codes

“Embedded Design with the PIC18F452 MicrocontrollerPIC18F452 MicrocontrollerPrentice Hall, 2003” Peatman

Page 32: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

User Defined CodesUser Defined Codes

“Embedded Design with the PIC18F452 MicrocontrollerPrentice Hall, 2003” Peatman

Page 33: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

User Defined CodesUser Defined Codes

“Embedded Design with the PIC18F452 MicrocontrollerPrentice Hall, 2003” Peatman

Page 34: The University of Texas at Arlington Lecture 8Lecture 8ranger.uta.edu/~walker/CSE3442_5442_FALL09/Web/Lectures/lecture8.pdfAssignment 3 Chapter 5Assignment 3 Chapter 5 On pages 187On

User Defined CodesUser Defined Codes

“Embedded Design with the PIC18F452 MicrocontrollerPrentice Hall, 2003” Peatman