这是一个8255的单片机设计程序,相互学习哦
#include
#include
#define uint unsigned int
#define uchar unsigned char
***it LE=P3^0;
***it A0=P2^0;
***it A1=P2^1;
***it CS=P2^2;
uchar kmz[8]={
0x80, //c=out,b=out,a=out
0x90, //c=out,b=out,a=in
0x82, //c=out,b=in,a=out
0x92, //c=out,b=in,a=in
0x89, //c=in,b=out,a=out
0x99, //c=in,b=out,a=in
0x8b, //c=in,b=in,a=out
0x9b, //c=in,b=in,a=in
};
void cmd(uchar i) //写控制字
{
LE=1;
CS=0,A1=1,A0=1,RD=1,WR=0;
LE=0;
P2=kmz[i];
}
void write_PA(uchar a) //输出PA
{
LE=1;
CS=0,A1=0,A0=0,RD=1,WR=0;
LE=0;
P2=a;
}
void write_PB(uchar b) //输出PB
{
LE=1;
CS=0,A1=0,A0=1,RD=1,WR=0;
LE=0;
P2=b;
}
void write_PC(uchar c) //输出PC
{
LE=1;
CS=0,A1=1,A0=0,RD=1,WR=0;
LE=0;
P2=c;
}
uchar read_PA() //捕获PA
{
uchar a;
LE=1;
CS=0,A1=0,A0=0,RD=0,WR=1;
LE=0;
a=P2;
return a;
}
uchar read_PB() //捕获PB
{
uchar b;
LE=1;
CS=0,A1=0,A0=1,RD=0,WR=1;
LE=0;
b=P2;
return b;
}
uchar read_PC() //捕获PC
{
uchar c;
LE=1;
CS=0,A1=1,A0=0,RD=0,WR=1;
LE=0;
c=P2;
return c;
}
void main()
{
cmd(0);
write_PA(0x01);
write_PB(0x02);
write_PC(0x04);
while(1);
}
|
|
2011-4-27 13:48:08
评论
举报
|
|
|