Bonjour,
Comme l'indique le titre du sujet, j'ai un souci avec le programe d'un Pic18F2520 pour indiquer une mesure sur un afficheur lcd 2 * 16.
Je suis loin d'être un Pro et je me debrouille avec des bouts de code chiner ici et là.
Le montage est un générateur PWM don la frequence et le rapport cylique sont reglable via le Can du PIC
et je veux affiché le % du rapport cyclique ainsi que la fréquence sur le LCD.
Le montage fonctionne à l'exeption que la broche 13 du PIC reliée a la broche RS du lcd qui ne repond pas.
Cela a pour consequence de faire défiler les valeur de droite a gauche et de haut en bas sur le LCD ...
J'ai donc fait une erreur biensur, mais je n'arrive pas a la localiser :
Si vous pouvez m'aider se serais sympa
Voici le code en MikroPascal :
Code:program const cFreq_00 = 500; cFreq_01 = 750; cFreq_02 = 1000; cFreq_03 = 2000; cFreq_04 = 3000; cFreq_05 = 4000; cFreq_06 = 5000; cFreq_07 = 7500; cFreq_08 = 10000; cFreq_09 = 15000; cFreq_10 = 20000; cFreq_11 = 25000; cFreq_12 = 30000; cFreq_13 = 35000; cFreq_14 = 40000; cFreq_15 = 45000; cFreq_16 = 50000; cFreq_17 = 55000; cFreq_18 = 60000; cFreq_19 = 65000; cFreq_20 = 70000; bShowUnit = 0; var iAdcPWMFreq, iAdcPWMDuty: word; PwmFreqNew, PwmFreqOld: word; PwmDutyNew, PwmDutyOld: byte; ArrValues: array[0..2] of dword; frecv: dword; fVal: real; txt: string[10]; txtflt: string[23]; TMR0_pin_dir : sbit at TRISB.5; RST_pin : sbit at LATB.4; RST_pin_dir : sbit at TRISB.4; // LCD display LCD_RS: sbit at RC2_bit; LCD_EN: sbit at RC3_bit; LCD_D4: sbit at RC4_bit; LCD_D5: sbit at RC5_bit; LCD_D6: sbit at RC6_bit; LCD_D7: sbit at RC7_bit; LCD_RS_Direction: sbit at TRISC2_bit; LCD_EN_Direction: sbit at TRISC3_bit; LCD_D7_Direction: sbit at TRISC7_bit; LCD_D6_Direction: sbit at TRISC6_bit; LCD_D5_Direction: sbit at TRISC5_bit; LCD_D4_Direction: sbit at TRISC4_bit; //s_LCD_Line1, s_LCD_Line2: string[16] procedure Main_Init; begin CMCON := %111; TRISA := %11111111; TRISB := %0; TRISC := %0; RCON.IPEN := 0; // Disable Priority Levels on interrupts ADCON0.ADON := 1; LATA := 0; LATB := 0; LATC := 0; // int 8 MHz osc without 4 x PLL OSCCON.IRCF2 := 1; OSCCON.IRCF1 := 1; OSCCON.IRCF0 := 1; OSCTUNE.PLLEN := 0; // PLL off // PWM init CCP2CON := CCP2CON or %00001111; PWM2_Init(cFreq_00); // Freq = 10 kHz PWM2_Set_Duty(255); PWM2_Start; PwmFreqNew := cFreq_00; PwmFreqOld := cFreq_00; PwmDutyNew := 0; PwmDutyOld := 0; end; procedure PWM_GetFreq; begin // freq is initially set to 10 kHz iAdcPWMFreq := ADC_Read(1); PwmFreqNew := iAdcPWMFreq; if PwmFreqNew <> PwmFreqOld then begin PWM1_Stop; PWM2_Stop; if ((PwmFreqNew > 0) and (PwmFreqNew < 50)) then begin PWM1_Init(cFreq_00); PWM2_Init(cFreq_00); end else if ((PwmFreqNew > 50) and (PwmFreqNew < 100)) then begin PWM1_Init(cFreq_01); PWM2_Init(cFreq_01); end else if ((PwmFreqNew >= 100) and (PwmFreqNew < 150)) then begin PWM1_Init(cFreq_02); PWM2_Init(cFreq_02); end else if ((PwmFreqNew >= 150) and (PwmFreqNew < 200)) then begin PWM1_Init(cFreq_03); PWM2_Init(cFreq_03); end else if ((PwmFreqNew >= 200) and (PwmFreqNew < 250)) then begin PWM1_Init(cFreq_04); PWM2_Init(cFreq_04); end else if ((PwmFreqNew >= 250) and (PwmFreqNew < 300)) then begin PWM1_Init(cFreq_05); PWM2_Init(cFreq_05); end else if ((PwmFreqNew >= 300) and (PwmFreqNew < 350)) then begin PWM1_Init(cFreq_06); PWM2_Init(cFreq_06); end else if ((PwmFreqNew >= 350) and (PwmFreqNew < 400)) then begin PWM1_Init(cFreq_07); PWM2_Init(cFreq_07); end else if ((PwmFreqNew >= 400) and (PwmFreqNew < 450)) then begin PWM1_Init(cFreq_08); PWM2_Init(cFreq_08); end else if ((PwmFreqNew > 450) and (PwmFreqNew < 500)) then begin PWM1_Init(cFreq_09); PWM2_Init(cFreq_09); end else if ((PwmFreqNew >= 500) and (PwmFreqNew < 550)) then begin PWM1_Init(cFreq_10); PWM2_Init(cFreq_10); end else if ((PwmFreqNew >= 550) and (PwmFreqNew < 600)) then begin PWM1_Init(cFreq_11); PWM2_Init(cFreq_11); end else if ((PwmFreqNew >= 600) and (PwmFreqNew < 650)) then begin PWM1_Init(cFreq_12); PWM2_Init(cFreq_12); end else if ((PwmFreqNew >= 650) and (PwmFreqNew < 700)) then begin PWM1_Init(cFreq_13); PWM2_Init(cFreq_13); end else if ((PwmFreqNew >= 700) and (PwmFreqNew < 750)) then begin PWM1_Init(cFreq_14); PWM2_Init(cFreq_14); end else if ((PwmFreqNew >= 750) and (PwmFreqNew < 800)) then begin PWM1_Init(cFreq_15); PWM2_Init(cFreq_15); end else if ((PwmFreqNew >= 800) and (PwmFreqNew < 850)) then begin PWM1_Init(cFreq_16); PWM2_Init(cFreq_16); end else if ((PwmFreqNew >= 850) and (PwmFreqNew < 900)) then begin PWM1_Init(cFreq_17); PWM2_Init(cFreq_17); end else if ((PwmFreqNew >= 900) and (PwmFreqNew < 950)) then begin PWM1_Init(cFreq_18); PWM2_Init(cFreq_18); end else if ((PwmFreqNew >= 950) and (PwmFreqNew < 1000)) then begin PWM1_Init(cFreq_19); PWM2_Init(cFreq_19); end else if ((PwmFreqNew >= 1000) and (PwmFreqNew < 1024)) then begin PWM1_Init(cFreq_20); PWM2_Init(cFreq_20); end; PWM2_Set_Duty(255 - PwmDutyNew); PWM2_Start; PwmFreqOld := PwmFreqNew; end; end; procedure PWM_GetDuty; begin iAdcPWMDuty := ADC_Read(0); if iAdcPWMDuty > 0 then //PwmDutyNew := iAdcPWMDuty shr 2 PwmDutyNew := iAdcPWMDuty / 4 else PwmDutyNew := 0; if PwmDutyNew <> PwmDutyOld then begin PWM2_Set_Duty(255 - PwmDutyNew); PwmDutyOld := PwmDutyNew; end; end; begin Main_Init; { Pin must be read as input with PORTx. Pin can be written as output with PORTx or with LATx. } Lcd_Init ; Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1, 1, 'Init'); Delay_ms(2000); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1, 1, ' Frequence (Hz) '); Lcd_Out(2, 1, ' ---'); delay_ms(4000); while true do begin if bShowUnit = 0 then begin LongWordToStr(PwmDutyNew, txt); Lcd_Out(1, 1, txt); LongWordToStr(PwmFreqNew, txt); Lcd_Out(2, 1, txt); Delay_ms(200); end; // change PWM freq value ? PWM_GetFreq; // change PWM duty value ? PWM_GetDuty; delay_ms(100); end; end.
-----