/ Auteur: VB // Date: 09/05/2019 // Description: lecture BP1 BP (J4_0 J4_1) // affichage sur LCD alpha // sur clign sur RC0 (J3_0) // sortie PWM sur RC2 (J4_2) // Test configuration: // MCU: PIC16F887 // Dev.Board: celle de THierry // Oscillator: HS, 20.0000 MHz // SW: mikroCpro for PIC // NOTES: fonctionne, // déclaration pour pour utiliser l'afficheur 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; sbit LCD_D5_Direction at TRISB3_bit; sbit LCD_D6_Direction at TRISB4_bit; sbit LCD_D7_Direction at TRISB5_bit; // fin déclaration pour utiliser l'afficheur unsigned int alpha=128, step_alpha = 10; ADC0_int; char *valeur[13]; void main() { // utile dans old version, pas utile ici ... normalement //ADCON0 = 0x00; //ADCON1 = 0x80; // Configure analog inputs /OK //TRISA = 0x0F; // PORTA is input pour bits0123 PORTB = 0; // Initialize PORTB TRISB = 0; // PORTB is output for LCD PORTC = 0; // Initialize PORTC = 0 TRISC = 0; // PORTC, bit0 is output for LED //Lcd_Config(&PORTB, 0, 1, 7, 5, 4, 3, 2);// Initialize LCD connected to PORTB Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off PORTC = 0; // Initialize PORTC = 0 TRISC = 0; // PORTC is output for PWM PWM1_Init(20000); // Initialize PWM module (sortie sur RC2 : CCP1) PWM1_Set_Duty (128); PWM1_Start (); while(1){ PORTC.F0 = ~PORTC.F0; // inverse PORTC.bit0 Delay_ms(1000); // Delai de 1sec if (PORTD.B0 ==0){ //appuie sur BP1 relié à J4_0 alpha = alpha + step_alpha; Lcd_Out(1, 1, "monte "); // Print text to LCD, 1row, 1column } else if (PORTD.B1 ==0){ //appuie sur BP2 relié à J4_1 alpha = alpha - step_alpha; Lcd_Out(1, 1, "descend"); // Print text to LCD, 1row, 1column } if (alpha > 245) alpha = 245; if (alpha <10) alpha = 10; PWM1_Set_Duty (alpha); // Lcd_Cmd(_LCD_CLEAR); // Clear display IntToStr(alpha, valeur); Lcd_Out(2, 1, "alpha="); Lcd_Out(2, 5, valeur); } // Boucle sans fin }