Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CMP3006 Embedded Systems Programming Lecture 4: Digital Input, Lecture notes of Embedded Systems Programming

its for cmp3006 and 3010 some of the university notes it will be help

Typology: Lecture notes

2022/2023

Uploaded on 06/17/2023

fahd-2
fahd-2 🇹🇷

6 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMP3006
EMBEDDED
SYSTEMS
PROGRAMMING
LECTURE 4 D I GITAL INPU T
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download CMP3006 Embedded Systems Programming Lecture 4: Digital Input and more Lecture notes Embedded Systems Programming in PDF only on Docsity!

CMP

EMBEDDED

SYSTEMS

PROGRAMMING

LECTURE 4 DIGITAL INPUT

Switches as Digital Input

Mechanical

Connecting Switches to a Digital

System

Single-pole double-throw (SPDT) connection

1 (HIGH)

0 (LOW)

𝜇𝐶

Connecting Switches to a Digital

System

Single-pole single-throw (SPST) connection

Pullup &Pulldown

𝜇𝐶

𝜇𝐶

I/O Ports

  • Internal Pullups
    • (^) If a pin is an input (DDRxi = 0):
      • (^) PORTxi = 0 – pin is floating
      • PORTxi = 1 – connects a pullup to the pin
        • Keeps pin from floating if no one driving
        • Allows wired-OR bus

DDRxi PORTxi Function

Input - Floating

0 1 Input – internal Pullup connected

1 0 Output LOW

1 1 Output HIGH

Counting Event with Buttons

(Switch)

Mechanical

loop() {

b = digitalRead(0);

if(b == 1){

// PRESSED

digitalWrite(13,HIGH);

}

else{

digitalWrite(13,LOW);

}

}

count = 0;

loop() {

b = digitalRead(0);

if(b == 1){

count++;

}

}

count = 0;

presses = false;

loop() {

b = digitalRead(0);

if(b == 1 && !pressed){

count++;

pressed = true;

}

else

pressed = false;

}

Bouncing

Debouncing

INTEGRATED CIRCUIT

SOLUTIONS

Use switch debouncers like the MAX

Bouncing

Shift Register

int state =0;

loop() {

b = !digitalRead(0);

state= (state<<1) | b | 0xe000;

if(State==0xf000){

// PRESSED

}

}

0111111111111