Bonjour;
j'ai eu quelque problème en essayant d'afficher sur LCD et utiliser le PWM au même temps par exemple quand je fais fonctionner que le PWM ça marche trés bien si je fais fonctionner que l'affichage sur LCD ça fonctionne impécablement mais quand je regroupe les deux rien ne marche.
a noter que je dois faire tourner 2 moteurs à l'aide de PWM1 et PWM2, ainsi que d'afficher l'heure et la date sur LCD; j'utilise un PIC 16F877A. le programme est comme suit:
Code:sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; char seconds, minutes, hours, day, month, year, ordrjr; int cap1=0,cap2=0,rapport_cyclique=0; void Read_Time() { I2C1_Start(); I2C1_Wr(0xD0); I2C1_Wr(0); I2C1_Repeated_Start(); I2C1_Wr(0xD1); seconds = I2C1_Rd(1); minutes = I2C1_Rd(1); hours = I2C1_Rd(1); ordrjr = I2C1_Rd(1); day = I2C1_Rd(1); month = I2C1_Rd(1); year = I2C1_Rd(0); I2C1_Stop(); } void Transform_Time() { seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); hours = ((hours & 0xF0) >> 4)*10 + (hours & 0x0F); day = ((day & 0x30) >> 4 )*10 + (day & 0x0F); month = ((month & 0x10) >> 4)*10 + (month & 0x0F); year = ((year & 0xF0) >> 6)*10 + (year & 0x0F); } void Display_Time() { Lcd_Chr(1, 6, (day / 10) + 48); Lcd_Chr(1, 7, (day % 10) + 48); Lcd_Chr(1, 9, (month / 10) + 48); Lcd_Chr(1,10, (month % 10) + 48); Lcd_Chr(1,15, year + 48); Lcd_Chr(2, 6, (hours / 10) + 48); Lcd_Chr(2, 7, (hours % 10) + 48); Lcd_Chr(2, 9, (minutes / 10) + 48); Lcd_Chr(2,10, (minutes % 10) + 48); Lcd_Chr(2,12, (seconds / 10) + 48); Lcd_Chr(2,13, (seconds % 10) + 48); } void Init_Main() { TRISB = 0; PORTB = 0xFF; TRISB = 0xff; I2C1_Init(100000); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(1,1,"Date:"); Lcd_Chr(1,8,'.'); Lcd_Chr(1,11,'.'); Lcd_Chr(1,16,'.'); Lcd_Out(2,1,"Time:"); Lcd_Chr(2,8,':'); Lcd_Chr(2,11,':'); Lcd_Out(1,12,"201"); } void main() { Delay_ms(500); Init_Main(); PWM1_Init(500); PWM2_Init(500); PWM1_Start(); PWM2_Start(); ADCON1=0X07; TRISA=0xFF; TRISC=0; PORTC=0; PWM1_Set_Duty(0); PWM2_Set_Duty(0); // Set current duty for PWM1 while (1) { Read_Time(); Transform_Time(); Display_Time(); cap1=ADC_Read(0); if(cap1<512) { Delay_ms(250); cap2=ADC_Read(0); if(cap2>cap1){ PWM1_Set_Duty(255); PWM2_Set_Duty(0); } else{ PWM1_Set_Duty(255); PWM2_Set_Duty(255); } } else if((cap1>=512)&&(cap1<1023)){ PWM1_Set_Duty(255); PWM2_Set_Duty(0); } else{ PWM1_Set_Duty(0); PWM2_Set_Duty(0); } } }
-----