Download presentation
Presentation is loading. Please wait.
Published byNathan Buddy Todd Modified over 8 years ago
1
Examples 1 - 4 Lecture L2.2
2
// Example 1a: Turn on every other segment on 7-seg display #include /* common defines and macros */ #include /* 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 */ } Example 1a
3
// Example 1b: 7-Segment Display #include /* common defines and macros */ #include /* 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 */ } Example 1b
4
Example 1
5
// Example 2a: Blinking 7-Segment Display #include /* common defines and macros */ #include /* 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++) { } Example 2a
6
// Example 2b: Blinking 7-Segment Display - ms_delay(ms) #include /* common defines and macros */ #include /* 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 } Example 2b
7
Example 2
8
// Example 3a: 7-Segment Decoder - C version #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void delay(void); void main(void) { const char seg7tbl[] = { 0x3F,0x06,0x5B,0x4f, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C, 0x39,0x5E,0x79,0x71 }; int i; Example 3a
9
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++) { } Example 3a (cont.)
10
// Example 3b: 7-Segment Decoder - seg7dec(i) #include /* common defines and macros */ #include /* 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); } Example 3b
11
Example 3
12
// Example 4a: Single segments in 7-Segment Display #include /* common defines and macros */ #include /* 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 Example 4a
13
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++) { } Example 4a (cont.)
14
// Example 4b: Single segments in 7-Segment Display #include /* common defines and macros */ #include /* 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 Example 4b
15
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 } Example 4b (cont.)
16
Example 4
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.