void write_8253_cnt(uint8 chose_8253,uint8 dat_8253,uint8 a1a0)
{
if(!chose_8253)
Output(p0_25,0);//片选8253(1)cs
else
Output(p0_26,0);//片选8253(2)cs
//Output(p0_30,0);//选中wr
switch(a1a0)
{
case 0:
Output(p0_28,0);//A1
Output(p0_27,0);//A0
break;
case 1:
Output(p0_28,0);//A1
Output(p0_27,1);//A0
break;
case 2:
Output(p0_28,1);//A1
Output(p0_27,0);//A0
break;
case 3:
Output(p0_28,1);//A1
Output(p0_27,1);//A0
break;
}
write_8253_dat(dat_8253);
Output(p0_30,0);//选中wr
DelayNS(10);
Output(p0_30,1);//放弃wr
if(!chose_8253)
Output(25,1);//放弃8253(1)cs
else
Output(26,1);//放弃8253(2)cs
}
uint8 read_8253_dat(uint8 a1a0,uint8 chose_8253)
{
uint8 read_i=0;
if(!chose_8253)
Output(p0_25,0);//选中cs1
else
Output(p0_26,0);//选中cs2
//Output(p0_29,0);//选中rd
switch(a1a0)
{
case 0:
Output(p0_28,0);//A1
Output(p0_27,0);//A0
break;
case 1:
Output(p0_28,0);//A1
Output(p0_27,1);//A0
break;
case 2:
Output(p0_28,1);//A1
Output(p0_27,0);//A0
break;
}
DelayNS(1);
Output(p0_29,0);//选中rd
DelayNS(1);
read_i=(Read_pin(p1_24,p1_24)&0x01)<<7;
read_i=read_i|(Read_pin(p1_23,p1_23)&0x01)<<6;
read_i=read_i|(Read_pin(p1_22,p1_22)&0x01)<<5;
read_i=read_i|(Read_pin(p1_21,p1_21)&0x01)<<4;
read_i=read_i|(Read_pin(p1_19,p1_19)&0x01)<<3;
read_i=read_i|(Read_pin(p1_18,p1_18)&0x01)<<2;
read_i=read_i|(Read_pin(p1_17,p1_17)&0x01)<<1;
read_i=read_i|(Read_pin(p1_16,p1_16)&0x01);
Output(p0_29,1);//放弃rd
if(!chose_8253)
Output(p0_25,1);//放弃cs1
else
Output(p0_26,1);//放弃cs2
//Output(p0_29,1);//放弃rd
return(read_i);
}
这是我的读写函数 |