Vlad.
Full Member level 3
- Joined
- Jun 4, 2012
- Messages
- 179
- Helped
- 3
- Reputation
- 6
- Reaction score
- 4
- Trophy points
- 1,298
- Location
- Bucharest/Romania
- Activity points
- 2,568
Hey, I design a code to control a dc motor with an h Bridge with pic16f876A and LAbview, i wrote a code but the code doesn't work. I send via serial value from 0 to 255 but the pwm don't start, can somebody help me?
Code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit; //conexiune LCD
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
char dist[] = "000.0";
int i;
unsigned short current_duty1,current_duty2;
void main() {
UART1_Init(9600); // Initialize USART module (8 bit, 38400 baud rate, no parity)
Delay_ms(300);
INTCON = 0; //DEZACTIVARE INTRRUPERI
TRISA= 0xFF; //PORTUL A CA INTRARE ANALOG
TRISB.F0=0; //CONTROL
TRISB.F1=0; //CONTROL
TRISB.F2=0; //CONTROL
TRISB.F3=0; //CONTROL
TRISC.F5=0; //LED
TRISC.F4=0; //LED
TRISC.F3=0; //BUZZER
PORTB.F0=0;
PORTB.F1=0;
PORTB.F2=0;
PORTB.F3=0;
PORTC.F4=0;
PORTC.F5=0;
PORTC.F3=0;
PWM1_Init(10000);
current_duty1 = 0;
PWM1_Start();
PWM1_Set_Duty(current_duty1);
PWM1_Init(10000);
current_duty2 = 0;
PWM2_Start();
PWM2_Set_Duty(current_duty2);
while (1) {
PORTB.F2=1;
if(UART1_Data_Ready()) //if data ready
{
if(UART1_Read() == 0x0D) //check for new line character
{
for(i=0;i<5;)
{
if(UART1_Data_Ready()) // if data ready
{
dist[i] = UART1_Read(); // read data
current_duty1 = dist[i];
PWM1_Set_Duty(current_duty1);
i++;
}
}
}
}