我需要帮助的PIC 18F2431,我需要使程序有8个数字输入从传感器,8个数字输入从DIP开关,1个控制输入(数字)和1个数字输出。程序需要检查哪些传感器被启用,如果控制输入是1,则需要在所有输入上都是AND函数,但如果在控制输入上的0需要是OR函数。这工作在内部振荡器32 kHz。我做了一些事情,但不知道是rightvoid main() {OSCCON=0b00000000;//设置32KHzADCON1=0xff的时钟;//数字输出TRISB=1;//端口B输入传感器TRISC=1;//端口C输入DIP交换机TRISA=0b00000001;//pin A0输入控制输入,A1输出{int tacno;PORTC=tacno; tacno=PORTB;if(PORTA.f0==1) (PORTB.f0==1)&&(PORTB.f1==1)&&(PORTB.f2==1)&&(PORTB.f3==1)&&(PORTB.f4==1)&&(PORTB.f5==1)&&(PORTB.f6==1)&&(PORTB.f7==1); else (PORTB.f0==1)||(PORTB.f1==1)||(PORTB.f2==1)||(PORTB.f3==1)||(PORTB.f4==1)||(PORTB.f5==1){(Purb.F6=1)〉(Purb.f7=1);}
以上来自于百度翻译
以下为原文
i need help for PIC 18F2431, i need to make program that have 8 digital inputs from sensors, 8 digital inputs from DIP Switch, 1 controll input (digital) and 1 digital output. Program need to chek which sensors are enabled and if on control input is 1, need to be AND func
tion on all inputs but if its 0 on control input need to be OR function. That work on internal oscilator 32KHz. I did something but don't know is that right
void main()
{
OSCCON = 0b00000000; //setting clock on 32KHz
ADCON1=0xff; //digital outputs
TRISB=1; //port B input for sensors
TRISC=1; //port C input for DIP Switch
TRISA=0b00000001; //pin A0 is input for control input and A1 output
{
int tacno;
PORTC=tacno;
tacno=PORTB;
if(PORTA.f0==1)
(PORTB.f0==1)&&(PORTB.f1==1)&&(PORTB.f2==1)&&(PORTB.f3==1)&&(PORTB.f4==1)&&(PORTB.f5==1)&&(PORTB.f6==1)&&(PORTB.f7==1);
else
(PORTB.f0==1)||(PORTB.f1==1)||(PORTB.f2==1)||(PORTB.f3==1)||(PORTB.f4==1)||(PORTB.f5==1)||(PORTB.f6==1)||(PORTB.f7==1);
}
}