davewhite
Newbie level 3
- Joined
- Oct 2, 2012
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,313
Hi. I am a beginner in C programming and I am trying to make this project, where an Input of 111 would make M2 spin, while an input of 000 would turn M1.
I've made a simple circuit and a program. My problem is no matter what the input is, only M1 would rotate. I've been trying to figure this one out for hours now but I just can't make it work. Any tips or suggestion would really help. Thanks
Here are the codes. I try to use both switch statement and if statement.
I've made a simple circuit and a program. My problem is no matter what the input is, only M1 would rotate. I've been trying to figure this one out for hours now but I just can't make it work. Any tips or suggestion would really help. Thanks
Here are the codes. I try to use both switch statement and if statement.
Code:
void InitMain() {
TRISD = 0x00;
TRISB = 0xff;
Pwm1_Init(5000);
Pwm2_Init(5000);
}
int i= 0;
void main() {
InitMain();
Pwm1_Start();
Pwm2_Start();
while (1) {
//white = 1 black =0
i = portb;
switch(i)
{
case 0x00:PORTD =0xA;
Pwm1_Set_Duty(200);
Pwm2_Set_Duty(0);
break;
case 0x07:PORTD=0x0A;
Pwm1_set_Duty(0);
Pwm2_Set_Duty(200);
break;
}
}
}
Code:
void InitMain() {
TRISD = 0x00;
TRISB = 0xFF;
Pwm1_Init(5000);
Pwm2_Init(5000);
}
void main() {
InitMain();
Pwm1_Start();
Pwm2_Start();
while (1) {
//white = 1 black =0
if(PORTB.B0==0&&PORTB.B1==0&&PORTB.B2==0){
portd=0x0A;
Pwm1_Set_Duty(200);
Pwm2_Set_Duty(0);
}
else if(PORTB.B0==0&&PORTB.B1==1&&PORTB.B2==1) {
portd=0x0A;
Pwm1_set_Duty(0);
Pwm2_Set_Duty(200);
}
}
}