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
|
#include <STC15F2K60S2.H> #define uint unsigned int #define uchar unsigned char
sbit sbtBeep = P3 ^ 4; sbit sbtKey1 = P3 ^ 2; sbit sbtKey2 = P3 ^ 3; sbit sbtSel0 = P2 ^ 0; sbit sbtSel1 = P2 ^ 1; sbit sbtSel2 = P2 ^ 2; sbit sbtSel3 = P2 ^ 3;
uint sbtKey1_state = 0; uint sbtKey2_state = 0; bit btBeepFlag; uint uiToneNum = 0; uchar arrSegSelect[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71 };
void Init() { P0M0 = 0xff; P0M1 = 0x00; P2M0 = 0x08; P2M1 = 0x00; P3M1 = 0x00; P3M0 = 0x10;
AUXR |= 0x80; TMOD &= 0xF0; TL0 = 0xCD; TH0 = 0xF4; TF0 = 0; TR0 = 1;
btBeepFlag = 0; P0 = 0x00;
sbtSel0 = 1; sbtSel1 = 1; sbtSel2 = 1;
sbtBeep = 0; ET0 = 1; EA = 1; }
void DelayMs( uint xms ) { uchar i; for( ; xms > 0; xms-- ) for( i = 114; i > 0; i-- ) { ; } }
void DisplaySeg7Led() { P0 = 0; sbtSel3 = 0; P0 = arrSegSelect[uiToneNum]; DelayMs( 1 );
P0 = 0; sbtSel3 = 1; P0 = 0x08; DelayMs( 1 ); }
void main() { Init(); while( 1 ) { if( sbtKey1 == 0 ) { if( sbtKey1_state == 0 ) { DelayMs( 10 ); if( sbtKey1 == 0 ) { uiToneNum++; if( uiToneNum == 10 ) uiToneNum = 0; TH0 = 0xF4 - uiToneNum; sbtKey1_state = 1; } } } else sbtKey1_state = 0;
if( sbtKey2 == 0 ) { if( sbtKey2_state == 0 ) { DelayMs( 10 ); if( sbtKey2 == 0 ) { btBeepFlag = !btBeepFlag; sbtKey2_state = 1; } } } else sbtKey2_state = 0;
DisplaySeg7Led(); } }
void T0_Process() interrupt 1 { if( btBeepFlag ) { sbtBeep = ~sbtBeep; } else sbtBeep = 0; }
|