Download presentation
Presentation is loading. Please wait.
Published byCatherine Cook Modified over 8 years ago
1
27-6-20161 Microprocessors A practical approach.
2
27-6-2016 2 Digital input/output
3
27-6-20163 Digital pin configuration and on/off void DS1(void) { PORTC=0; //reset PORTC latches TRISC=0b11110000; //RC0-RC3 //output else High impedance PORTC.0=1; //RC0 High }
4
27-6-20164 Hardware description
5
27-6-20165 Delays Do,for or while loops Timers, no – interrupts Timers interrupt based.
6
27-6-20166 Delay : Simple loops while (z<1270) {z++; }
7
27-6-20167 Delay : Simple loops(2) Advantage : easy to program Disadvantage: Difficult to make a exact time delay Disadvantage: processor is busy in delay loop.
8
27-6-20168 Delays : Timer Seperate piece hardware. Easy to calculate
9
27-6-20169 Timer 0 8-bit timer/counter Readable and writable 8-bit software programmable prescaler Internal or external clock select Interrupt on overflow from FFh to 00h Edge select for external clock
10
27-6-2016 10 Timer 0 (2)
11
27-6-201611 Timer 0 (3)
12
27-6-201612 Timer 0 (3) // Delays a multiple of 1 milliseconds at 4 MHz // using the TMR0 timer void Delay_ms( uns16 millisec) { char next = 0; OPTION = 2; // prescaler divide TMR0 rate by 8 TMR0 = 1; // deduct 1*8 fixed instruction cycles delay do { next += 125; while (TMR0 != next) // 125 * 8 *1 us = 1000 us (= 1 ms) ; } while ( -- millisec != 0);}
13
27-6-201613 Timer 0 (3)
14
27-6-201614 Assignment 2a Make 2 programs with 2 variations of a running light. The first program with a simple delay based on a variable. The second program based on TIMER 0
15
27-6-201615 Microprocessoren lesson 3 Digital input and counters
16
27-6-201616 Contents lesson 3 Configuration input pin Switch connecting Bouncing Debouncing Schmitt –trigger input Counting
17
27-6-201617
18
27-6-201618 Program example simple input void init(void) { PORTA=0; //reset PORTA latches TRISA = 0b11111111; //al pins are input TRISC = 0b00000000; // al pins output for led ANSEL = 0b00000000; //All pins as digital I/O } void main( void) { uns8 x; //count value x=0; // set initial value to 0; init(); PORTA=0; while (1) { if (PORTA.2==1) {PORTC.0=1;} else {PORTC.0=0;} //if switch = 5v, //wait until x=0 again to wait for falling edge, wait 10 ms for debouncing }
19
27-6-201619
20
27-6-201620 Program Example bouncing void init(void) { PORTA=0; // reset PORTA latches TRISA = 0b11111111; // all pins are input TRISC = 0b00000000; // all pins output for led ANSEL = 0b00000000; //All pins as digital I/O } void main( void) { uns8 x; //count value x=0; // set initial value to 0; init(); while (1) { if (PORTA.2==1) {x++;while(PORTA.2==1);} //if switch = 5v increment x //,wait until x=0 again to wait for falling edge, wait 10 ms for debouncing PORTC=x; //show x value on led }
21
27-6-201621 Schmitt trigger input
22
27-6-201622
23
27-6-201623 software debounce 1
24
27-6-2016 24 timer 0 External clock
25
27-6-201625 timer 0 External clock OPTION_REG
26
27-6-201626 Timer 0 configuration for counting with TIMER0 OPTION_REG=0b00111000; x=TMR0;
27
27-6-201627 Assignment 4 1.Write a program for a that LED shows if the switch (on RA2) is pressed or not. 2.Write a program which shows the bouncing of the switch. 3.Write a program that makes clear that the software debounced the switch. 4.Write a program that counts the switch on a falling edge.(no use of timer0) 5. Write a program that counts the switch on a falling edge. (use :timer0)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.