提前谢谢!
https://imgur.com/a/ktTkvxI -------变形蛋白模拟
unsigned int adc_rd;
long current_duty;
void main() {
ANSELC = 0; // Configure PORTC as digital I/O;CU ANSEL SETAM PT FIECARE PIN/port DACA PORTUL E ANALOGIC SAU DIGITAL, DACA E 0 E DIGITAL;DACA E 1 E ANALOPGIC
ANSELB = 0; // Configure PORTB as digital I/O;CU ANSEL SETAM PT FIECARE PIN/port DACA PORTUL E ANALOGIC SAU DIGITAL, DACA E 0 E DIGITAL;DACA E 1 E ANALOPGIC
TRISA0_bit = 1; //Configure AN0 (RA0) as input; CU TRIS CONFIGURAM DIRECTIA PINILOR, DACA SUNT INTRARI SAU IESIRI, DACA E 1 E INTRARE...
TRISC = 0; //PORTC pins are outputs CU TRIS CONFIGURAM DIRECTIA PINILOR, DACA SUNT INTRARI SAU IESIRI, DACA E 0 E IESIRE...
TRISB = 0; //PORTB pins are outputs CU TRIS CONFIGURAM DIRECTIA PINILOR, DACA SUNT INTRARI SAU IESIRI, DACA E 0 E IESIRE...
TRISC3_bit = 1; //Configuram bitul RC3 ca intrare digitala(butonul1)
TRISC4_bit = 1; //Configuram bitul RC4 ca intrare digitala(butonul2)
PWM1_Init(1000); // Initialize PWM1 module at 1KHz
PWM1_Start(); // start PWM1
ADC_Init(); // Initialize ADC
LATB = 0x02; //Turn the motor Clockwise
while (1) { // endless loop
adc_rd = ADC_Read(0); //Read Analog value from Analog channel 0
//convert voltage level to duty cycle 0-->255
current_duty = (long) adc_rd * 255;
current_duty = current_duty/1023;
PWM1_Set_Duty(current_duty); //change duty cycle
Delay_ms(5); // slow down change pace a little
}
}