1 / 8

Example 5 Pushbutton Switches: S1 and S2

Example 5 Pushbutton Switches: S1 and S2. Lecture L3.1. 2 pushbutton switches. Serial cable. A/D Pot. Run/Load switch. Reset button. 7-segment display. Power plug. I/O headers. miniDragon+. Pushbutton Switches: S1 and S2. (PORTAD0 & 0x10) == 0. TRUE if S1 is closed.

kyna
Download Presentation

Example 5 Pushbutton Switches: S1 and S2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. 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); else seg7_off(); } }

  5. 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); else seg7_off(); } }

  6. Example 5

  7. 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); } seg7_off(); } }

More Related