C51 COMPILER V9.54 INTERRUPT_1 05/13/2018 18:13:58 PAGE 1 C51 COMPILER V9.54, COMPILATION OF MODULE INTERRUPT_1 OBJECT MODULE PLACED IN .\Objects\Interrupt_1.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE Interrupt_1.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listin -gs\Interrupt_1.lst) TABS(2) OBJECT(.\Objects\Interrupt_1.obj) line level source 1 // Timer 0 take as interrupt 2 // Timer 1 take as delay 3 4 #include 5 6 // 宣告延時函式 7 void delay_1500ms(void); 8 9 unsigned int timer0_counter = 150; 10 11 bit lightoff = 1; 12 bit lighton = 0; 13 sbit P1_0 = P1^0; 14 sbit P1_1 = P1^1; 15 sbit P1_2 = P1^2; 16 sbit P1_3 = P1^3; 17 sbit P1_4 = P1^4; 18 sbit P1_5 = P1^5; 19 sbit P1_6 = P1^6; 20 sbit P1_7 = P1^7; 21 22 void main(void){ 23 1 24 1 //開啟 Timer0 和 Timer1 25 1 TMOD = 0x11; 26 1 27 1 //interrupt control 28 1 TL0 = (65536 - 9216) % 256; 29 1 TH0 = (65536 - 9216) / 256; 30 1 TF0 = 0; 31 1 TR0 = 1; //開啟計時器 timer0 32 1 ET0 = 1; //開啟 TF0 的中斷模組開關 33 1 EA = 1; //開啟中斷模組總開關 34 1 35 1 while(1){ 36 2 // do LED move up to down per 1.5 sec 37 2 // using Timer 1 Mode 1 to generate 10ms delay 38 2 P1 = 0xFF; 39 2 while (1) { 40 3 delay_1500ms(); 41 3 42 3 P1_0 = lighton; 43 3 delay_1500ms(); 44 3 45 3 P1_1 = lighton; 46 3 delay_1500ms(); 47 3 48 3 P1_2 = lighton; 49 3 delay_1500ms(); 50 3 51 3 P1_3 = lighton; 52 3 delay_1500ms(); 53 3 54 3 P1_4 = lighton; C51 COMPILER V9.54 INTERRUPT_1 05/13/2018 18:13:58 PAGE 2 55 3 delay_1500ms(); 56 3 57 3 P1_5 = lighton; 58 3 delay_1500ms(); 59 3 60 3 P1_6 = lighton; 61 3 delay_1500ms(); 62 3 63 3 P1_7 = lighton; 64 3 delay_1500ms(); 65 3 66 3 P1_7 = lightoff; 67 3 delay_1500ms(); 68 3 69 3 P1_6 = lightoff; 70 3 delay_1500ms(); 71 3 72 3 P1_5 = lightoff; 73 3 delay_1500ms(); 74 3 75 3 P1_4 = lightoff; 76 3 delay_1500ms(); 77 3 78 3 P1_3 = lightoff; 79 3 delay_1500ms(); 80 3 81 3 P1_2 = lightoff; 82 3 delay_1500ms(); 83 3 84 3 P1_1 = lightoff; 85 3 delay_1500ms(); 86 3 87 3 P1_0 = lightoff; 88 3 } 89 2 } 90 1 } 91 92 93 void delay_1500ms(void){ 94 1 95 1 int time = 0; 96 1 while(time < 150) { 97 2 //設定初始值 98 2 TF1 = 0; 99 2 TR1 = 0; 100 2 TL1 = (65536-9216) % 256; 101 2 TH1 = (65536-9216) / 256; 102 2 103 2 //開啟計時器 timer1 104 2 TR1 = 1; 105 2 106 2 //當 TF1 沒有溢位 107 2 while(TF1 == 0); 108 2 109 2 //關閉計時器 110 2 TR1 = 0; 111 2 112 2 //將 TF1 歸零 113 2 TF1 = 0; 114 2 time++; 115 2 } 116 1 } C51 COMPILER V9.54 INTERRUPT_1 05/13/2018 18:13:58 PAGE 3 117 118 119 // timer0 在計時到的時候(TF0 = 1)會呼叫的中斷副函式 120 void my_timer0(void) interrupt 1 { 121 1 122 1 //設定初始值 123 1 TL0 = (65536 - 9216) % 256; 124 1 TH0 = (65536 - 9216) / 256; 125 1 TF0 = 0; 126 1 127 1 // timer0_counter 一直遞減 128 1 timer0_counter--; 129 1 130 1 131 1 //當 timer0_counter 為 0 時,實作七段顯示器 132 1 if (timer0_counter == 0){ 133 2 // 實作七段顯示器 134 2 135 2 136 2 //將 timer0_counter 的值設回 150 137 2 timer0_counter = 150; 138 2 139 2 } 140 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 200 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 2 ---- IDATA SIZE = ---- ---- BIT SIZE = 2 ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)