?? keysquar.c
字號:
#include<reg52.h>
#define uint unsigned int;
#define uchar unsigned char;
uchar bai,shi,ge,temp,tt;
sbit duan=P2^6;
sbit wei=P2^7;
uchar code Num_code[]={ //顯示數據編碼
0xc0,0xF9,0xA4,0xB0,0x99,//0-4
0x92,0x82,0xF8,0x80,0x90};//5-9
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(unsigned char bai,unsigned char shi,unsigned char ge)
{
P0=0x20;
wei=1;
wei=0;
P0=Num_code[ge];
duan=1;
duan=0;
// delay(1);
P0=0x10;
wei=1;
wei=0;
P0=Num_code[shi];
duan=1;
duan=0;
// delay(1);
P0=0x08;
wei=1;
wei=0;
P0=Num_code[bai];
duan=1;
duan=0;
//delay(1);
}
void main()
{
tt=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;//開總中斷
ET0=1;//允許timer0中斷
TR0=1;//啟動timer0
while(1)
{ // P0=0xff;
P1=0xef;
temp=P1;
temp=temp&0x0f;
if(temp!=0x0f)
{
temp=P1;
switch(temp)
{
case 0xee:bai=0;shi=0;ge=0;break;
case 0xed:bai=0;shi=0;ge=1;break;
case 0xeb:bai=0;shi=0;ge=4;break;
case 0xe7:bai=0;shi=0;ge=9;break;
}
display(bai,shi,ge);
}
P1=0xdf;
temp=P1;
temp=temp&0x0f;
if(temp!=0x0f)
{
temp=P1;
switch(temp)
{
case 0xde:bai=0;shi=1;ge=6;break;
case 0xdd:bai=0;shi=2;ge=5;break;
case 0xdb:bai=0;shi=3;ge=6;break;
case 0xd7:bai=0;shi=4;ge=9;break;
}
display(bai,shi,ge);
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -