8255A可以不接单片机P0口吗?
时间:10-02
整理:3721RD
点击:
请问8255A可以不接单片机P0口吗? 地址和数据分开给可以吗?如果可以的话为什么仿真结果8255A的输出没有反应?求大神解答
程序如下:
#include <reg51.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define p_A 0xfc
#define p_B 0xfd
#define p_ctl 0xff
sbit BELL=P3^5;
sbit LED=P3^4;
sbit k1=P2^3;
sbit k2=P2^4;
uchar ad,temp1[4]={0,0,0,0},smok1[4]={0,0,0,0},temp2[4],smok2[4];
uint stop,i=0;
uchar xdata * adc;
uchar SEG_code[]={0xce,0x1c,0xee,0x9c,0x9e,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //{PLACE 0123456789}
uchar seleLED[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //0到5号管
void delay(uint x){ //延时1us
uint t;
while(x--) for(t=0; t<100; t++);
}
void display(uint a){ //显示函数
uint j;
P2= p_B; P1=0xff; //熄灭所有数码管
while (stop==0){
for (j=0;j<6;j++){
P2= p_B; P1=seleLED[j];
P2= p_A;
if(j==5) {P1=SEG_code[j+a]; delay(5);}
else {P1=SEG_code[j]; delay(5);}
P1=0x00;
}
}
}
void warning (){
LED=0; BELL=1; //声光报警
display(i); //显示火警发生地点
}
void warning2(){
}
void main(void)
{ adc=0x7fff; //adc地址
P2= p_ctl; P1=0x80; //初始化8255,port-A,B均为输出
P2= p_B; P1=0xff;
IT1=1; //中断初始化
IT0=0;
PX0=1;
EX0=1;
EX1=1;
EA=1;
delay(10);
* adc=i; //开始转换通道 0
while (1); //等待转换结束
}
void int1() interrupt 2 {
switch(i){ //选择通道进行判别;
case 0: //通道 0
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning (); //连续两次采样均超过上限时报警
temp1[i/2]=temp2[i/2];
i=1; break;
case 1: //通道 1
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning (); //连续两次采样均超过上限时报警
smok1[i/2]=smok2[i/2];
i=2; break;
case 2: //通道 2
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning ();
temp1[i/2]=temp2[i/2];
i=3; break;
case 3: //通道 3
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning ();
smok1[i/2]=smok2[i/2];
i=4; break;
case 4: //通道 4
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning ();
temp1[i/2]=temp2[i/2];
i=5; break;
case 5: //通道 5
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning ();
smok1[i/2]=smok2[i/2];
i=6; break;
case 6: //通道 6
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning ();
temp1[i/2]=temp2[i/2];
i=7; break;
case 7: //通道 7
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning ();
smok1[i/2]=smok2[i/2];
i=0; break;
}
if (i==0) delay(100); //完成一轮采集后等待
* adc=i;
}
void int0() interrupt 0{
if (k1==0){LED=1; BELL=0; stop=1;}
if (k2==0){
delay(100);
if(k2==0) warning2();
}
}
程序如下:
#include <reg51.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define p_A 0xfc
#define p_B 0xfd
#define p_ctl 0xff
sbit BELL=P3^5;
sbit LED=P3^4;
sbit k1=P2^3;
sbit k2=P2^4;
uchar ad,temp1[4]={0,0,0,0},smok1[4]={0,0,0,0},temp2[4],smok2[4];
uint stop,i=0;
uchar xdata * adc;
uchar SEG_code[]={0xce,0x1c,0xee,0x9c,0x9e,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //{PLACE 0123456789}
uchar seleLED[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //0到5号管
void delay(uint x){ //延时1us
uint t;
while(x--) for(t=0; t<100; t++);
}
void display(uint a){ //显示函数
uint j;
P2= p_B; P1=0xff; //熄灭所有数码管
while (stop==0){
for (j=0;j<6;j++){
P2= p_B; P1=seleLED[j];
P2= p_A;
if(j==5) {P1=SEG_code[j+a]; delay(5);}
else {P1=SEG_code[j]; delay(5);}
P1=0x00;
}
}
}
void warning (){
LED=0; BELL=1; //声光报警
display(i); //显示火警发生地点
}
void warning2(){
}
void main(void)
{ adc=0x7fff; //adc地址
P2= p_ctl; P1=0x80; //初始化8255,port-A,B均为输出
P2= p_B; P1=0xff;
IT1=1; //中断初始化
IT0=0;
PX0=1;
EX0=1;
EX1=1;
EA=1;
delay(10);
* adc=i; //开始转换通道 0
while (1); //等待转换结束
}
void int1() interrupt 2 {
switch(i){ //选择通道进行判别;
case 0: //通道 0
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning (); //连续两次采样均超过上限时报警
temp1[i/2]=temp2[i/2];
i=1; break;
case 1: //通道 1
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning (); //连续两次采样均超过上限时报警
smok1[i/2]=smok2[i/2];
i=2; break;
case 2: //通道 2
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning ();
temp1[i/2]=temp2[i/2];
i=3; break;
case 3: //通道 3
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning ();
smok1[i/2]=smok2[i/2];
i=4; break;
case 4: //通道 4
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning ();
temp1[i/2]=temp2[i/2];
i=5; break;
case 5: //通道 5
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning ();
smok1[i/2]=smok2[i/2];
i=6; break;
case 6: //通道 6
temp2[i/2]=* adc; // 读adc转换结果;
if((temp2[i/2]> 180)&&(temp1[i/2]>180)) warning ();
temp1[i/2]=temp2[i/2];
i=7; break;
case 7: //通道 7
smok2[i/2]=* adc; // 读adc转换结果;
if((smok2[i/2]> 77)&&(smok1[i/2]>77)) warning ();
smok1[i/2]=smok2[i/2];
i=0; break;
}
if (i==0) delay(100); //完成一轮采集后等待
* adc=i;
}
void int0() interrupt 0{
if (k1==0){LED=1; BELL=0; stop=1;}
if (k2==0){
delay(100);
if(k2==0) warning2();
}
}
不接P0口,那也就只能P2口了,地址要正确才可以