0.png (21.33 KB, 下載次數: 47)
下載附件
2021-3-12 15:12 上傳
1.png (117.88 KB, 下載次數: 62)
下載附件
2021-3-12 15:12 上傳
2.png (103.39 KB, 下載次數: 63)
下載附件
2021-3-12 15:12 上傳
單片機源程序如下:
#include <STC89C5xRC.H>
#include <intrins.h>
sbit s7 = P3^0;
sbit s6 = P3^1;
sbit s5 = P3^2;
sbit s4 = P3^3;
unsigned char code SMG_NoDot[18] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void InitHC573(unsigned char i);
void show(unsigned char j);
void Delay100ms();
void scanfkey();
void main(){
scanfkey();
}
void Delay100ms() //@11.0592MHz
{
unsigned char i, j;
i = 180;
j = 73;
do
{
while (--j);
} while (--i);
}
void InitHC573(unsigned char i){
switch (i){
case 6:
P2 = ( P2 & 0x1f ) | 0xc0;
break;
case 7:
P2 = ( P2 & 0x1f ) | 0xe0;
break;
}
}
void show(unsigned char j){
InitHC573(6);
P0 = 0x01;
InitHC573(7);
P0 = j;
}
void scanfkey(){
if(s7 == 0){
Delay100ms();
if(s7 == 0){
while(s7 == 0);
show(SMG_NoDot[0]);
}
}
if(s6 == 0){
Delay100ms();
if(s6 == 0){
while(s6 == 0);
show(SMG_NoDot[1]);
}
}
if(s5 == 0){
Delay100ms();
if(s5 == 0){
while(s5 == 0);
show(SMG_NoDot[2]);
}
}
if(s4 == 0){
Delay100ms();
if(s4 == 0){
while(s4 == 0);
show(SMG_NoDot[3]);
}
}
}
|