日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] //K程序主要是測試配置位的使用要調(diào)用87X.H杳看//定時中斷//原來4的程序是可能為沒有按鍵放開的程序//程序5修正按鍵松開的程序//biao是指示是否有按鍵按下如果沒有的話就指示為顯示4個8#include #inclu

//K程序主要是測試配置位的使用要調(diào)用87X.H杳看
//定時中斷
//原來4的程序是可能為沒有按鍵放開的程序
//程序5修正按鍵松開的程序
//biao是指示是否有按鍵按下如果沒有的話就指示為顯示4個8
#include
#include
#define PORTDIT(add,bit) ((unsigned)(&add)*8+(bit))

#define PORTBIT(add,bit) ((unsigned)(&add)*8+(bit))
//__IDLOC(1233) ;
//__CONFIG (XT&PWRTEN) ;
static bit PORT_0 @ PORTDIT(PORTD,0); /*定義PORTD 0位*/
static bit PORT_1 @ PORTDIT(PORTD,1); /*定義PORTD 1位*/
static bit PORT_2 @ PORTDIT(PORTD,2); /*定義PORTD 2位*/
static bit PORT_3 @ PORTDIT(PORTD,3); /*定義PORTD 3位*/
static bit PORT_4 @ PORTDIT(PORTD,4); /*定義PORTD 4位*/
static bit PORT_5 @ PORTDIT(PORTD,5); /*定義PORTD 5位*/
static bit PORT_6 @ PORTDIT(PORTD,6); /*定義PORTD 6位*/
static bit PORT_7 @ PORTDIT(PORTD,7); /*定義PORTD 7位*/
//-------------------------------------------------
static bit PORTD_0 @ PORTBIT(PORTB,0); /*定義PORTB 0位*/
static bit PORTD_1 @ PORTBIT(PORTB,1); /*定義PORTB 1位*/
static bit PORTD_2 @ PORTBIT(PORTB,2); /*定義PORTB 2位*/
static bit PORTD_3 @ PORTBIT(PORTB,3); /*定義PORTB 3位*/
static bit PORTD_4 @ PORTBIT(PORTB,4); /*定義PORTB 4位*/
static bit PORTD_5 @ PORTBIT(PORTB,5); /*定義PORTB 5位*/
static bit PORTD_6 @ PORTBIT(PORTB,6); /*定義PORTB 6位*/
static bit PORTD_7 @ PORTBIT(PORTB,7); /*定義PORTB 7位*/
//const char table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x7C};
unsigned char s; /*每0.125S累加1*/
unsigned char ss,fan; /*每1秒累加1*/
int i=0,tt;


unsigned charLEDadr,biao;
static unsigned char k,led1,led2,led2,led3,led4;
static unsigned char adrshow,count,show1,show2,show3,show4;//顯示位控制
const char table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39}; //A~F
/*0,1,2,3,4,5,6,7,8,9,A,b,C,c,d,E,*/
void keysCAN();
void delay10ms(unsigned char time);
void Dispaly(unsigned char k);
unsigned char key,temp;
void tmint(void)
{ T0CS=0;
PSA=0;
PS2=0;
PS1=1;
PS0=1;
T0IF=0;
T0IE=1;
}
void interrupt clkint(void) //定時器中斷函數(shù)
{ if(T0IF=1) //增加是定時中斷時進(jìn)入
{
TMR0=0x5b;
T0IF=0;
lEDAdr=ledadr+1;
if(biao==0)

{ if (ledadr>count)
{ledadr=0;}
}
if ((ledadr==1)&(show1==1||biao==1))
{if(biao==1)
{PORTC=0XFF;
PORTA=0;
RA0=1;}
else {PORTC=led1;
PORTA=0;
RA0=1;}
}
if ((ledadr==2)&(show2==1||biao==1))
{ PORTA=0;
if(biao==1)
{PORTC=0XFF;
PORTA=0;
RA1=1;}
else {
PORTA=0;
PORTC=led2;
RA1=1;}
}
if ((ledadr==3)&(show3==1||biao==1))
{PORTA=0;
if (biao==1)
{PORTC=0xff;
PORTA=0;
RA2=1;}
else {
PORTA=0;
PORTC=led3;
RA2=1;}
}
if ((ledadr==4)&(show4==1||biao==1))
{PORTA=0;
if (biao==1)
{PORTC=0XFF;
PORTA=0;
RA3=1;
ledadr=0;}
else{
PORTC=led4;
PORTA=0;
RA3=1;
ledadr=0;}
}
if(s++>8){ s=0;
if(ss++>05)/*每分鐘清0*/
ss=0;
}
/* RC3=(bit)(s>4);//可改變占空比1秒閃一次
RC1=(bit)(!ss);//1分閃一次
RC2=(bit)(s==0 || s==2 || s== 4 || s== 6);//0.25秒閃一次*/
}
}
main(void)
{
TRISD=0x0F;//低四位是輸入,高四位為輸出
TRISC=0;
// PORTD=0X55;
TRISB=0x00;
TRISC=0x00;
PORTB=0X00;
PORTC=0x00;
RB0=1;RB2=0;//接兩個LED,開始為全滅
PCFG3=0;
PCFG2=1;
PCFG1=1;
PCFG0=1;
TRISA=0;
PORTA=0;
//RTC=0xff;
T0CS=0;
RA4=0;
ledadr=0;
tmint(); //調(diào)用定時器初始化程序
GIE=1;
ledadr=0;
count=0;
// show1=1;biao=0;
// ledadr=2;
//if ((ledadr==2)&(show1==1||biao==1))
// {asm("nop");}

//show=0;//顯示清零
s=0 ;
ss=0;
adrshow=1;
TMR0=0x06; //裝入定時器初始值
biao=1;led1=led2=led3=led4=0xff;
show1=show2=show3=show4=0;
while(1)
{
// ledadr=0;
keyscan();
if(key!=0)
{ if (count<=4)
{ count=count+1;
if (count==1)
{ led1=table[key];
key=0;
show1=1;show2=0;show3=0;show4=0;biao=0;}
if(count==2)
{ led2=table[key];
key=0;
show2=1;show1=1;show3=0;show4=0;biao=0; }
if(count==3)
{ led3=table[key];
key=0;
show1=1;show2=1;show3=1;show4=0;biao=0;}
if(count==4)
{led4=table[key];
key=0;
show1=1;show2=1;show3=1;show4=1;biao=0;}
}
else count=0;

}
}
}
/* RC3=(bit)(s>4);//可改變占空比1秒閃一次
RC1=(bit)(!ss);//1分閃一次
RC2=(bit)(s==0 || s==2 || s== 4 || s== 6);//0.25秒閃一次 */

void keyscan() //按鍵掃描子程序
{
PORTD=0xFF;
RD7=0; //低四位的第四位為0(輸出)
temp=PORTD;
temp&=0x0F;//屏蔽掉高四位
if(temp !=0x0F) //如果有按鍵按下的話
{
delay10ms(1);
temp=PORTD;
temp&=0x0F;
if(temp !=0x0F) ;//如果確認(rèn)有按鍵按下
{
temp=PORTD;
temp&=0x0F;//屏蔽高位位
asm("nop");
switch(temp)
{
case 0x0E: //1110000b b4有按下
key=4;break;
case 0x0D:
key=8;break;// 10110000b d
case 0x0B:
key=12;break; //11010000b
}
Dispaly(key);
asm("nop");
}
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉