ninja01  0.1
Utilizzo di PIC4431 per pilotaggio motori DC in PWM LAP
 Tutto File Funzioni Definizioni
ninja01.c
Vai alla documentazione di questo file.
1 
15 #include <p18f4431.h>
16 #include <delays.h>
17 
18 #include "motors.h"
19 
20 #pragma config OSC = HSPLL // Oscillatore PLL 4x attivo
21 #pragma config WDTEN = OFF // Whatch dog disattivato
22 #pragma config PWRTEN = ON // Power UP timer abilitato
23 #pragma config LVP = OFF // Programmazione LVP disabilitata
24 #pragma config BOREN = OFF // Brown out Reset disabilitato
25 #pragma config BORV = 42 // Tensione per Brown out Reset 4.2 Volt
26 #pragma config PWM4MX = RB5 // RB5 = PWM4
27 
28 void initHW(void);
29 
30 void main(void){
31  int duty = 0;
32  char rc = 1;
33 
34  initHW();
36  setMotor(1, ENABLE, 0);
37  setMotor(2, ENABLE, 0);
38  Delay10KTCYx( 255 );
39 
40  while(1){
41  if (rc != 0)duty = -PWM_LIMIT;
42  rc = setMotor(2, ENABLE, duty ++);
43  EN_MOT3 = !EN_MOT3;
44  Delay1KTCYx( 20 );
45 
46  };
47  return;
48 }
49 
50 void initHW(void){
51 
52 // PINs Direction
53  TRISA = 0b11111111; // Ananlogs and Encoder
54  TRISB = 0b11000000; // uscite PWM e ICSP
55  TRISC = 0b10111001; // I2C, RS232, pwm
56  TRISD = 0x00000000; // display lcd
57  TRISE = 0x11110000; // led
58 
59 // PINs Initial State
60  PORTA = 0x11111111;
61  PORTB = 0x00000000;
62  PORTC = 0x00000000;
63  PORTD = 0x00000000;
64  PORTE = 0x00000000;
65  INTCON = 0; // Clear Interrupt
66  return;
67 }