怎么用15单片机外部中断0实现按一下从0开始加1(到六十归零),再按一
答案:1 悬赏:10 手机版
解决时间 2021-11-30 13:31
- 提问者网友:王者佥
- 2021-11-29 14:12
怎么用15单片机外部中断0实现按一下从0开始加1(到六十归零),再按一
最佳答案
- 五星知识达人网友:举杯邀酒敬孤独
- 2021-11-29 14:27
//试74164动态3.C,可以平稳显示小时,分,秒
#include
sbit DAT=P2^5; //1脚,数据 ,4模拟电力表电路
sbit CLK=P2^4; //8脚,时钟
sbit K1=P2^0; // K1
sbit K2=P2^1; // K2
sbit K3=P2^2; // K3
sbit K4=P2^3; // K4
unsigned char WW; //万位数组,WW0为左边,WW1为右边,WW3为设置值
unsigned char QW; //千位数组,QW0为左边,QW1为右边,QW3为设置值
unsigned char BW; //百位数组,BW0为左边,BW1为右边,BW3为设置值
unsigned char SW; //十位数组,SW0为左边,SW1为右边,SW3为设置值
unsigned char GW;
unsigned char sn1,sn2,sn3,sn4;
unsigned char xn1,xn2,xn3,xn4;
//unsigned char codetab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};// 显示0~9//显示数码管高电平亮
unsigned char codetab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF};// 显示0~9//显示数码管低电平亮
unsigned char code ff[]={0xFE,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x77};//位选;
unsigned char hour,minite,second;
void delay(unsigned int z);
void BCD(unsigned int R1); //转BCD码
void display(void); //74595显示子程序//全部显示
//开启计时
void loading()
{
TMOD=0x22;
TR0=1;
ET0=1;
EA=1;
}
void main(void)
{
K1=1;K2=1;K3=1;K4=1;
loading();
while(1)
{
BCD(second);
sn1=QW; sn2=BW; sn3=SW; sn4=GW;
BCD(minite);
xn1=QW; xn2=BW; xn3=SW; xn4=GW;
display(); //显示
//delay(5);
//K1=1;K2=1;K3=1;K4=1;
}
}
//========================================
//以下是显示程序,共八个,因为有八个数码管;
void delay(unsigned int z)
{
unsignedint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void dat(unsigned char byte,unsigned charbyte1)
{
unsigned char num,num1,c;
num=tab[byte];
num1=tab[byte1];
for(c=0;c<8;c++) //左边数据
{
CLK=0;
DAT=num&0x80;
CLK=1;
num<<=1;
}
for(c=0;c<8;c++) //右边数据
{
CLK=0;
DAT=num1&0x80;
CLK=1;
num1<<=1;
}
num=0x7F; //位选个位 ,第 1位
for(c=0;c<8;c++) //现在是指示灯
{
CLK=0;
DAT=num;
CLK=1;
num<<=1;
}
}
void display(void)
{
//========(正常方式下显示)=========
dat(sn1,xn1); //先右后左
K1=0;delay(3);
K1=1;
dat(sn2,xn2); //先右后左
K2=0;delay(3);
K2=1;
dat(sn3,xn3); //先右后左
K3=0;delay(3);
K3=1;
dat(sn4,xn4); //先右后左
K4=0;delay(3);
K1=1;K2=1;K3=1;K4=1;
// delay(15);
}
void time(void) interrupt 1
{
unsigned int tt;
tt++;
if(tt==3600)
{
tt=0;
second++;
if(second==60)
{
second=0;
minite++;
if(minite==60)
{
minite=0;
hour++;
if(hour==24)
hour=0;
}
}
}
}
void BCD(unsigned int R1)
{
//WW1=0;QW1=0;BW1=0;SW1=0;GW1=0;
WW=0;QW=0;BW=0;SW=0;GW=0;
while(R1>=10000)
{R1-=10000;WW++;}
while(R1>=1000)
{R1-=1000;QW++;}
while(R1>=100)
{R1-=100;BW++;}
while(R1>=10)
{R1-=10;SW++;}
GW=R1;
}追问图上的要求你能做出来吗
#include
sbit DAT=P2^5; //1脚,数据 ,4模拟电力表电路
sbit CLK=P2^4; //8脚,时钟
sbit K1=P2^0; // K1
sbit K2=P2^1; // K2
sbit K3=P2^2; // K3
sbit K4=P2^3; // K4
unsigned char WW; //万位数组,WW0为左边,WW1为右边,WW3为设置值
unsigned char QW; //千位数组,QW0为左边,QW1为右边,QW3为设置值
unsigned char BW; //百位数组,BW0为左边,BW1为右边,BW3为设置值
unsigned char SW; //十位数组,SW0为左边,SW1为右边,SW3为设置值
unsigned char GW;
unsigned char sn1,sn2,sn3,sn4;
unsigned char xn1,xn2,xn3,xn4;
//unsigned char codetab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};// 显示0~9//显示数码管高电平亮
unsigned char codetab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF};// 显示0~9//显示数码管低电平亮
unsigned char code ff[]={0xFE,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x77};//位选;
unsigned char hour,minite,second;
void delay(unsigned int z);
void BCD(unsigned int R1); //转BCD码
void display(void); //74595显示子程序//全部显示
//开启计时
void loading()
{
TMOD=0x22;
TR0=1;
ET0=1;
EA=1;
}
void main(void)
{
K1=1;K2=1;K3=1;K4=1;
loading();
while(1)
{
BCD(second);
sn1=QW; sn2=BW; sn3=SW; sn4=GW;
BCD(minite);
xn1=QW; xn2=BW; xn3=SW; xn4=GW;
display(); //显示
//delay(5);
//K1=1;K2=1;K3=1;K4=1;
}
}
//========================================
//以下是显示程序,共八个,因为有八个数码管;
void delay(unsigned int z)
{
unsignedint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void dat(unsigned char byte,unsigned charbyte1)
{
unsigned char num,num1,c;
num=tab[byte];
num1=tab[byte1];
for(c=0;c<8;c++) //左边数据
{
CLK=0;
DAT=num&0x80;
CLK=1;
num<<=1;
}
for(c=0;c<8;c++) //右边数据
{
CLK=0;
DAT=num1&0x80;
CLK=1;
num1<<=1;
}
num=0x7F; //位选个位 ,第 1位
for(c=0;c<8;c++) //现在是指示灯
{
CLK=0;
DAT=num;
CLK=1;
num<<=1;
}
}
void display(void)
{
//========(正常方式下显示)=========
dat(sn1,xn1); //先右后左
K1=0;delay(3);
K1=1;
dat(sn2,xn2); //先右后左
K2=0;delay(3);
K2=1;
dat(sn3,xn3); //先右后左
K3=0;delay(3);
K3=1;
dat(sn4,xn4); //先右后左
K4=0;delay(3);
K1=1;K2=1;K3=1;K4=1;
// delay(15);
}
void time(void) interrupt 1
{
unsigned int tt;
tt++;
if(tt==3600)
{
tt=0;
second++;
if(second==60)
{
second=0;
minite++;
if(minite==60)
{
minite=0;
hour++;
if(hour==24)
hour=0;
}
}
}
}
void BCD(unsigned int R1)
{
//WW1=0;QW1=0;BW1=0;SW1=0;GW1=0;
WW=0;QW=0;BW=0;SW=0;GW=0;
while(R1>=10000)
{R1-=10000;WW++;}
while(R1>=1000)
{R1-=1000;QW++;}
while(R1>=100)
{R1-=100;BW++;}
while(R1>=10)
{R1-=10;SW++;}
GW=R1;
}追问图上的要求你能做出来吗
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯