Title: Microprocessoren lesson 5 Digital input and counters Debouncing
1Microprocessoren lesson 5
Digital input and countersDebouncing
2Topics 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)
5Program 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
6Program example (code snip)no debounced input
void main (void) int var 0 init()
while(1) if (PORTA.20) var
CharToLed(var)
7(No Transcript)
8Schmitt trigger
FromReference Manuals for the mid-range MCU
Family (document 33023a)
software debounce 4
9software debounce 1
10Software 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()
11Software 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
12software debounce 4
13Timer 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?
14Timer0
From Reference Manuals for the mid-range MCU
Family (document 33023a)
15timer 0 OPTION_REG
16Problem 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.
173th hour(/- 1225)
- Next week AD-converterSee also preparation
- Evaluation
18AD-converter