1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| #include <STC15F2K60S2.H> #include <intrins.h>
unsigned char code SMG[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
void Delay1ms() { unsigned char i, j;
i = 12; j = 169; do { while (--j); } while (--i); }
void delay_ms(int x) { while(x--) { Delay1ms(); } }
void slect_138_573(unsigned char channel, unsigned char dat) { P0 = 0x00; P0 = dat; switch(channel) { case 4: P2 = (P2 & 0x1f) | 0x80; break; case 5: P2 = (P2 & 0x1f) | 0xa0; break; case 6: P2 = (P2 & 0x1f) | 0xc0; break; case 7: P2 = (P2 & 0x1f) | 0xe0; break; case 0: P2 = (P2 & 0x1f) | 0x00; break; } P2 = (P2 & 0x1f) | 0x00; }
void SMG_Display_Bit(unsigned char pos, unsigned char value) { slect_138_573(6, 0x01 << pos - 1); slect_138_573(7, value); delay_ms(2);
slect_138_573(6, 0x01 << pos - 1); slect_138_573(7, 0xff); }
void System_init(void) { slect_138_573(4, 0xff); slect_138_573(5, 0x00); }
unsigned int t_1s; unsigned int t_4s; unsigned char time; unsigned char mode;
void Timer0_Isr(void) interrupt 1 { if(++t_1s >= 1000) { t_1s = 0; time += 1; if(time == 10) time = 0; } if(++t_4s >= 4000) { t_4s = 0; mode ^= 1; } }
void Timer0_Init(void) { AUXR &= 0x7F; TMOD &= 0xF0; TL0 = 0x18; TH0 = 0xFC; TF0 = 0; TR0 = 1; ET0 = 1; EA = 1; }
void main(void) { System_init(); Timer0_Init(); while(1) { switch(mode) { case 0: SMG_Display_Bit(1, SMG[0]); SMG_Display_Bit(2, SMG[0]); SMG_Display_Bit(3, SMG[0]); SMG_Display_Bit(4, SMG[0]); SMG_Display_Bit(5, SMG[0]); SMG_Display_Bit(6, SMG[0]); SMG_Display_Bit(7, SMG[0]); SMG_Display_Bit(8, SMG[0]); break; case 1: SMG_Display_Bit(1, SMG[1]); SMG_Display_Bit(2, SMG[2]); SMG_Display_Bit(3, SMG[3]); SMG_Display_Bit(4, SMG[4]); SMG_Display_Bit(5, SMG[5]); SMG_Display_Bit(6, SMG[6]); SMG_Display_Bit(7, SMG[7]); SMG_Display_Bit(8, SMG[8]); break; default: break; } } }
|