/*********************************************
LEDK.C 2006/3/16
P2.0 ~ P2.7 P0.7 ~ P0.0
4X4 KEYBOARD
*********************************************/
#include <REG51F.H>
#define uchar unsigned char
#define uint unsigned int
sbit COLUMN1 = P1^0;
sbit COLUMN2 = P1^1;
sbit COLUMN3 = P1^2;
sbit COLUMN4 = P1^3;
sbit ROW1 = P1^4;
sbit ROW2 = P1^5;
sbit ROW3 = P1^6;
sbit ROW4 = P1^7;
bdata FLAG = 0x20;
sbit C_FLAG = FLAG^0;
sbit D_FLAG = FLAG^1;
sbit F_FLAG = FLAG^2;
sbit J_FLAG = FLAG^3;
sbit L_FLAG = FLAG^4;
sbit M_FLAG = FLAG^5;
sbit N_FLAG = FLAG^6;
sbit O_FLAG = FLAG^7;
bdata FLAG1 = 0x21;
sbit B_FLAG = FLAG1^0;
uchar DCNT, KEY_NO, K_TEMP;
void BLINK(void);
void LRC(void);
void LRD(void);
void LRF(void);
void LRJ(void);
void LRL(void);
void LRM(void);
void LRN(void);
void LRO(void);
void Delay(uint del);
void Kdelay(void);
void SCAN(void);
void SCAN_ON(void);
void SCAN_OFF(void);
void KEY_PRO(void);
void main(void)
{
DCNT=5; SP+=2;
while (1)
{
P2=0; P0=0xFF; Kdelay();
P2=0xFF; P0=0; Kdelay();
}
}
void BLINK(void)
{
FLAG=0; FLAG1=0; B_FLAG=1;
while (1)
{
P2=P0=0; Kdelay();
P2=P0=0xFF; Kdelay();
}
}
void LRC(void)
{
uchar i,k=0;
FLAG=0; FLAG1=0; C_FLAG=1;
while (1)
{
for (i=8; i>0; i--)
{
P2=P0=k; Kdelay();
k<<=1; k+=1;
}
for (i=8; i>0; i--)
{
P2=P0=k; Kdelay();
k>>=1;
}
}
}
void LRD(void)
{
uchar i,k=0;
FLAG=0; FLAG1=0; D_FLAG=1;
while (1)
{
for (i=8; i>0; i--)
{
P2=P0=k; Kdelay();
k>>=1; k+=0x80;
}
for (i=8; i>0; i--)
{
P2=P0=k; Kdelay();
k<<=1;
}
}
}
void LRF(void)
{
uchar i,k;
FLAG=0; FLAG1=0; F_FLAG=1;
while (1)
{
k=0;
for (i=8; i>0; i--)
{
P2=0; P0=k; Kdelay();
k<<=1; k+=1;
}
k=0;
for (i=8; i>0; i--)
{
P2=k; P0=0xFF; Kdelay();
k>>=1; k+=0x80;
}
for (i=8; i>0; i--)
{
P2=k; P0=0xFF; Kdelay();
k<<=1;
}
k=0xFF;
for (i=8; i>0; i--)
{
P2=0; P0=k; Kdelay();
k>>=1;
}
}
}
void LRJ(void)
{
uchar i,k=1;
FLAG=0; FLAG1=0; J_FLAG=1;
P2=P0=0; Kdelay();
while (1)
{
for (i=8; i>0; i--)
{
P2=0; P0=k; Kdelay();
k<<=1;
}
k=0x80;
for (i=7; i>0; i--)
{
P2=k; P0=0; Kdelay();
k>>=1;
}
for (i=8; i>0; ..
訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容