You Wei Lim
Newbie level 3
- Joined
- Jul 21, 2014
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Location
- Melaka, Malaysia
- Activity points
- 24
Hi guest , i have face the problem that i need to use the 3 PORT B pin as the input pin from hall sensored from bldc motor, and 6 PORT C pin as my output pin 5V to control the high side and low side of my motor driver the 3-phase BLDC motor by using a C-code programming~~below is my source code ,can compile but dint work~~ ANY SUGGESTION? URGENT!!!!!!!
PLS HELP!!!!!
Code:
void main()
{
TRISA = 0xFF;
TRISB = 0xFF; // Set PORTB as Input
TRISC = 0xFF;
TRISD = 0x00; // Set PORTD as Input
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
CMCON = 0x07;
ADCON1 = 0b10000110;
// or
// ADCON1 = 0b10000111;
while(1)
{
if(PORTB =0x14) // If RA0 is Toggled
{
TRISD = 0x00; // Set PORTB as Output
PORTD = 0x06; // Toggle On;
}
else if (PORTB= 0x10) //0x04 - 100
{
TRISD = 0x00 ;
PORTD= 0x24 ;
//hall_state = 5;
}
else if (PORTB= 0x18) //0x06 - 110
{
TRISD = 0x00 ;
PORTD= 0x21 ;
//hall_state = 6;
}
else if (PORTB= 0x08 ) //0x02 - 010
{
TRISD = 0x00 ;
PORTD= 0x09;
//hall_state = 1;
}
else if (PORTB= 0x0C) //0x03 - 011
{
TRISD = 0x00 ;
PORTD= 0x18;
//hall_state = 2;
}
else if (PORTB= 0x04)
//0x01 - 001
{
TRISD = 0x00 ;
PORTD = 0x12;
//hall_state = 3;
}
else
{
PORTD= 0x00;
}
}
}
Last edited by a moderator: