28
LCD interfacing +Other Peripherals in AVR Microcontrollers Microprocessors , Lecture 11:

Microprocessors , Lecture 11: LCD interfacing +Other

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Microprocessors , Lecture 11: LCD interfacing +Other

LCD interfacing +Other Peripherals in AVR Microcontrollers

Microprocessors , Lecture 11:

Page 2: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 2

Contents

• A brief overview over the AVR peripherals not covered by the course

• LCD

Page 3: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 3

AVR peripherals

Page 4: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 4

AVR peripherals

• PWM generation

• Sleep mode

• Watchdog timer

• EPROM

• Analog comparator

Page 5: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 5

Sleep mode

• To save power when the microcontroller is idle

• Controlled by MCUCR

• The clock is shut-down, CPU is inactive

• Registers and SRAM keep their value

• Wakeup on reset and interrupts

Page 6: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 6

Sleep mode

• SE: enables sleep mode

• SM0 to SM2 determine the sleep type

• After setting SE to 1, the “sleep” assembly command should be executed

– To make microcontroller enter the sleep mode

– Use sleep.h functions in C to enter sleep mode

– CPU exits the sleep mode by an external interrupt

Page 7: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 7

Sleep mode

Page 8: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 8

Two important sleep states

• Idle state: the clock of CPU and Flash (instruction memory) is disconnected

– Other parts have their clock active

• Power down state:

– All clocks are deactivated

– Registers and PCs are stored

• Exit by interrupts

Page 9: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 9

Watchdog timer

• A fault-tolerant approach

• Resets the microcontroller if detects a crash!

• To ensure that the microcontroller is functional and doesn’t hang

– Start watchdog timer and set its registers to reset the micro after a time

– In program disable the watchdog timer before that time

– If the micro is frozen, the code that disables the watchdog is not executed and it resets the micro

– Otherwise the watchdog resets the micro

Page 10: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 10

Watchdog timer

• Watchdog uses an independent clock (1 MHz)

• WDTCR register controls the watchdog

Page 11: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 11

WDTCR register

• WDE: enable timer

• WPD[0-2]: the reset time

Page 12: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 12

Timer timeout delay

Page 13: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 13

EEPROM

• Kind of data memory

• To keep permanent data not changed during time

• Using some registers to communicate with EEPROM

• Two registers to send and receive data

• A register to control read and write

Page 14: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 14

Analog comparator

• Compares two analog inputs on AIN0 And AIN1 pins

• Sets the bits of a register based on the results to be used by the micro

Page 15: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 15

PWM

• Control the power of DC (Direct current) motors

While(1){

PORTB.1=1;Delay_ms(75);PORTB.1=0;Delay_ms(25);

}

Page 16: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 16

LCD

Page 17: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 17

LCD interfacing

• A device that Displays characters• Many variations • We study a very common 14-pin LCD

Page 18: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 18

LCD to AVR connection

Page 19: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 19

LCD pins

• Lcd has two important registers:

• Data register: saves the data to be shown

• Instruction register: commands received to do something

– e.g. clear display

Page 20: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 20

LCD commands• Example: initialize

lcd for 8 bit and 5x7• Commands 38, 0E,

and 01 should be sent

• To send a command:

• RS and w/r set to 0• Send appropriate

command on data pins

Page 21: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 21

Character addresses

Page 22: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 22

LCD 4-bit

• Can work with 4-bit data to save pins

Page 23: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 23

LCD commands

Page 24: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 24

Page 25: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 25

Page 26: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 26

Page 27: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 27

Page 28: Microprocessors , Lecture 11: LCD interfacing +Other

University of Tehran 28