Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example 5 Pushbutton Switches: S1 and S2

Similar presentations


Presentation on theme: "Example 5 Pushbutton Switches: S1 and S2"— Presentation transcript:

1 Example 5 Pushbutton Switches: S1 and S2
Lecture L3.1

2 miniDragon+ 2 pushbutton switches Serial cable A/D Pot I/O headers Run/Load switch Reset button 7-segment display Power plug

3

4 Pushbutton Switches: S1 and S2
(PORTAD0 & 0x10) == 0 TRUE if S1 is closed (PORTAD0 & 0x08) == 0 TRUE if S2 is closed

5 Example 5a // Example 5a: Pushbutton Switches
#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display ATD0DIEN = 0x18; // enable S1 and S2 while(1){ if((PORTAD0 & 0x10) == 0) seg7dec(1); else seg7_off(); if((PORTAD0 & 0x08) == 0) seg7dec(2); }

6 Example 5b // Example 5b: Pushbutton Switches using C function calls
#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display SW12_enable(); // enable S1 and S2 while(1){ if(SW1_down()) seg7dec(1); else seg7_off(); if(SW2_down()) seg7dec(2); }

7 Example 5

8 Example 5c // Example 5c: Pushbutton Switches - Problem 5.3
#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display SW12_enable(); // enable S1 and S2 while(1){ while(SW1_down()){ seg7dec(1); } seg7_off(); while(SW2_down()){ seg7dec(2);


Download ppt "Example 5 Pushbutton Switches: S1 and S2"

Similar presentations


Ads by Google