Microprocessoren lesson 5 Digital input and counters Debouncing - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Microprocessoren lesson 5 Digital input and counters Debouncing

Description:

Preparation lesson 5, Timer0, IO port as input. AD conversion ... Schmitt trigger. From. Reference Manuals for. the mid-range MCU Family (document 33023a) ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 19
Provided by: wwwhomeC
Category:

less

Transcript and Presenter's Notes

Title: Microprocessoren lesson 5 Digital input and counters Debouncing


1
Microprocessoren lesson 5
Digital input and countersDebouncing
2
Topics lesson 5
  • Questions / remarks
  • Lesson 4
  • Preparation lesson 5, Timer0, IO port as input
  • AD conversion methods (introduction)
  • General
  • Example
  • Programming C, registers,
  • Functional description, problem analysis
  • IO, Timer0 and deboucing
  • Result self-tuition
  • Lab Problem 3 Switch
    connecting reflection logbook (optional)
    check on result Problem 1,2
    (listing, flowchart, result)
  • 3th hour, AD evaluation

3
(No Transcript)
4
(No Transcript)
5
Program example (code snip)no debounced input
void init() //init other registers !!!
PORTA0 TRISA0b.1100.1111 //al pins as input
except RA4 RA5 void main() init()
while (1) if (PORTA.20) PORTA.41
PORTA.50 //RA4 High, RA5 stays
low, //D0off, D1on else
PORTA.40PORTA.51 //RA5 high Ra4
low //D0on, D1off
6
Program example (code snip)no debounced input
void main (void) int var 0 init()
while(1) if (PORTA.20) var
CharToLed(var)
7
(No Transcript)
8
Schmitt trigger
FromReference Manuals for the mid-range MCU
Family (document 33023a)
software debounce 4
9
software debounce 1
10
Software debounce 2
void Debounce() //see next sheet void init()
//reset PORTA latches CMCON07 ANSEL0 //no
analogue comparator, digital input PORTA0
TRISA0b11001111 //RA4 and RA5 output others
high impedance OPTION_REG 0b.1101.0111 //
Timer0, internal clock, prescale, 1256
// 4MHz 0.256 msec delay void main
() init() while(1) if (!PORTA.2)
if (PORTA.4) PORTA.40PORTA.51
else PORTA.41PORTA.50 Debounce()

11
Software debounce 3
/ wait unitil switch has been pushed/ void
Debounce() unsigned char COUNT40 //delay
counter while(1) if(!PORTA.2)
COUNT 40 // reset 10 msec if BUTTON is
pushed //400.256 msec else
// decrement timer COUNT for every
Timer0 overflow If(T0IF) T0IF 0 //
reset flag // exit on 10 consecutive msec
// without BUTTON closure count-1
if( COUNT 0) break //end
while
12
software debounce 4
13
Timer 0 configuration
  • OPTION_REG0b.0110.0111
  • PSA0 gt assigned to Timer0
  • T0SE0 gtL to H transition
  • TOCS0 gtinternal clock source
  • xTMR0
  • Question What to do in case of an external clock?

14
Timer0
From Reference Manuals for the mid-range MCU
Family (document 33023a)
15
timer 0 OPTION_REG
16
Problem 3
  • See also problem 3
  • Connect a switch with the controller
  • Write a program so that the LED shows if the
    switch is pressed or not.
  • Write a program which shows the bouncing of the
    switch.
  • Write a program that makes clear that the
    software debounced the switch.

17
3th hour(/- 1225)
  • Next week AD-converterSee also preparation
  • Evaluation

18
AD-converter
Write a Comment
User Comments (0)
About PowerShow.com