读取8421拨码开关的值~~~
时间:10-02
整理:3721RD
点击:
请问怎么读取8421拨码开关的值呀,
假设3个拨码开关,公共端都接了地,
百,十,个,分别P0的8个口和P1的4个口,
我下面的程序有错吗?
void time_1(uint time_1)
{
unsigned char bai,shi,ge,temp;
unsigned int time1;
temp=P0;
bai=temp&0x0f;
shi=temp&0xf0;
temp=P1;
ge=temp&0x0f;
time_1=bai*100+shi*10+ge;
}
请高人指点。
假设3个拨码开关,公共端都接了地,
百,十,个,分别P0的8个口和P1的4个口,
我下面的程序有错吗?
void time_1(uint time_1)
{
unsigned char bai,shi,ge,temp;
unsigned int time1;
temp=P0;
bai=temp&0x0f;
shi=temp&0xf0;
temp=P1;
ge=temp&0x0f;
time_1=bai*100+shi*10+ge;
}
请高人指点。