//PIC18F1220
//全橋式輸出,INT0=0 then Autoshutdown
//檢查RB7還是INPIT
//ECCPASE 並未=1
IRCF0 = 1; // Used to set intrc speed to 8 MHz
IRCF1 = 1; // Used to set intrc speed to 8 MHz
IRCF2 = 1; // Used to set intrc speed to 8 MHz
TRISB = 0xff;
PR2 = 0x3F; // Sets PWM Period at 31.2 kHz
CCP1CON = 0b01001110; // Full bridge PWM forward,P1M0=1,
ECCPAS = 0b11001100; // INT0 pin low causes shutdown,Pins A/C=1,B/D=0
PWM1CON =0x0; // b7=0→clear ECCPASE ,b7=1→autorestart
TMR2IF = 0;
T2CON = 0; // TMR2 Off with no prescale
CCPR1L = 0x1F; // Sets Duty Cycle to
TMR2ON = 1; // Start Timer2
while(TMR2IF)
; // wait until TMR2 overflows(first period)
PORTA = 0;
TRISA = 0b00111111; // Set RA7 and RA6 as outputs
PORTB = 0;
TRISB = 0b00110011; // Set RB7,RB6,RB3,RB2 outputs
RBPU = 1; // RB pull up resister
ADCON0 = 1; // Use Vdd as Ref,Channel select AN0,ADON
ADCON1 = 0b11110000; // Configure AN0~AN3 as analog
ADCON2 = 0b10000101; // Right j
T0CS = 0; // Timer0 as timer not a counter
TMR0 = TMR0base; // Preload value
PSA = 0; // Prescaler to Timer0
T0PS0 = 0; // Prescale to 32 => 1024 Hz
T0PS1 = 0;
T0PS2 = 1;
INTCON = 0;
PIE1 = 0;
TMR0IE = 1; // Enable Timer0 int