1 / 16

Examples 1 - 4

Examples 1 - 4. Lecture L2.2. Example 1a. // Example 1a: Turn on every other segment on 7-seg display # include <hidef.h> /* common defines and macros */ # include <mc9s12dp256.h> /* derivative information */ # include "main_asm.h" /* interface to the assembly module */

taurus
Download Presentation

Examples 1 - 4

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. Examples 1 - 4 Lecture L2.2

  2. Example 1a // Example 1a: Turn on every other segment on 7-seg display #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 DDRH = 0xff; // Port H is output PTH = 0x55; // switch on every other segment for(;;) {} /* wait forever */ }

  3. Example 1b // Example 1b: 7-Segment Display #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 seg7_on(0x55); // switch on every other segment for(;;) {} /* wait forever */ }

  4. Example 1

  5. Example 2a // Example 2a: Blinking 7-Segment Display #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 delay(void); void main(void) { seg7_enable(); // enable 7-segment display while(1){ seg7_on(0xFF); // switch on all segments delay(); seg7_on(0x00); // switch off all segments delay(); } } void delay() { int i,j; for(i = 0; i < 500; i++) { for(j = 0; j < 5999; j++) { } } }

  6. Example 2b // Example 2b: Blinking 7-Segment Display - ms_delay(ms) #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 while(1){ seg7_on(0xFF); // switch on all segments ms_delay(500); // half-second delay seg7_on(0x00); // switch off all segments ms_delay(500); // half-second delay } }

  7. Example 2

  8. Example 3a // Example 3a: 7-Segment Decoder - C version #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 delay(void); void main(void) { constchar seg7tbl[] = { 0x3F,0x06,0x5B,0x4f, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C, 0x39,0x5E,0x79,0x71 }; int i;

  9. Example 3a (cont.) PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display while(1){ for(i = 0; i < 16; i++) { PTH = seg7tbl[i]; delay(); } } } void delay() { int i,j; for(i = 0; i < 500; i++) { for(j = 0; j < 6248; j++) { } } }

  10. Example 3b // Example 3b: 7-Segment Decoder - seg7dec(i) #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) { int i; PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display while(1){ for(i = 0; i < 16; i++) { seg7dec(i); ms_delay(500); } } }

  11. Example 3

  12. Example 4a // Example 4a: Single segments in 7-Segment Display #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 delay(void); void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display

  13. Example 4a (cont.) while(1){ PTH |= 0x01; // turn on segment a delay(); PTH |= 0x40; // turn on segment g delay(); PTH |= 0x08; // turn on segment d delay(); PTH &= 0xFE; // turn off segment a delay(); PTH &= 0xBF; // turn off segment g delay(); PTH &= 0xF7; // turn off segment d delay(); } } void delay() { int i,j; for(i = 0; i < 500; i++) { for(j = 0; j < 6248; j++) { } } }

  14. Example 4b // Example 4b: Single segments in 7-Segment Display #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) { /* put your own code here */ seg7_enable(); // enable 7-segment display

  15. Example 4b (cont.) while(1){ PTH_HI(0); // turn on segment a ms_delay(500); // half-second delay PTH_HI(6); // turn on segment g ms_delay(500); // half-second delay PTH_HI(3); // turn on segment d ms_delay(500); // half-second delay PTH_LO(0); // turn off segment a ms_delay(500); // half-second delay PTH_LO(6); // turn off segment g ms_delay(500); // half-second delay PTH_LO(3); // turn off segment d ms_delay(500); // half-second delay } }

  16. Example 4

More Related