Bnjr tt le monde je veux réaliser un algorithme sur mikrobasic qui compte le nombre de tours a partir de deux capteurs qui on deux signaux a et b ( prend en compte le sens de rotation du moteur cad incrémentation ou décrementation) puis l'affiché sur LCD j'ai fais se si et ca ne marche pas aider moi stp
Code:program xd dim LCD_RS as sbit at RB0_bit LCD_EN as sbit at RB1_bit LCD_D4 as sbit at RB2_bit LCD_D5 as sbit at RB3_bit LCD_D6 as sbit at RB4_bit LCD_D7 as sbit at RB5_bit LCD_RS_Direction as sbit at TRISB0_bit LCD_EN_Direction as sbit at TRISB1_bit LCD_D4_Direction as sbit at TRISB2_bit LCD_D5_Direction as sbit at TRISB3_bit LCD_D6_Direction as sbit at TRISB4_bit LCD_D7_Direction as sbit at TRISB5_bit dim Char_Tours as string [3] dim Nb_Tours as byte dim Nb_Tours_P as byte dim Compteur as word dim AB_state as byte dim A as sbit at RA0_bit dim B as sbit at RA1_bit dim AA as sbit at AB_State.0 dim AP as sbit at AB_State.1 dim BA as sbit at AB_State.2 dim BP as sbit at AB_State.3 ' End Lcd module connections dim txt1 as char[8] txt2 as char[7] i as byte ' Loop variable sub procedure Move_Delay() ' Function used for text moving Delay_ms(500) ' You can change the moving speed here end sub main: ADCON1 = 0x07 ' Configure AN pins as digital I/O ADCON0 = 0x00 PORTA = 0x00 TrisA=0x00 PORTB = 0xFF TRISB = 0xFF txt1 ="NB.Tours:" txt2 ="NB.Tours:" Lcd_Init() ' Initialize Lcd Lcd_Cmd(_LCD_CLEAR) ' Clear display Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off Lcd_Out(1,1,txt1) ' Write text in first row Lcd_Out(1,11,Char_Tours) ' Write text in second row Delay_ms(2000) while TRUE ' Endless loop if AA <> A then AP=AA AA=A end if if BA <> B then BP=BA BA=B end if if ((AP=0) and (BP=0)) then if ((AA=1) and (BA=0)) then Compteur = Compteur +1 end if if ((AA=0) and (BA=1)) then Compteur = Compteur -1 end if end if if ((Ap=1) and (BP=0)) then if ((AA=1) and (BA=1)) then Compteur = Compteur +1 end if if ((AA=0) and (BA=0)) then Compteur = Compteur -1 end if end if if ((Ap=1) and (BP=1)) then if ((AA=0) and (BA=1)) then Compteur = Compteur +1 end if if ((AA=1) and(BA=0)) then Compteur = Compteur -1 end if end if if ((Ap=0) and (BP=1)) then if ((AA=0) and (BA=0)) then Compteur = Compteur +1 end if if ((AA=1) and (BA=1)) then Compteur = Compteur -1 end if end if NB_Tours_P = NB_Tours NB_Tours = Compteur div 4 if NB_Tours_P <> NB_Tours then byteToStr ( Nb_Tours , Char_Tours) Lcd_out (1,11,Char_Tours) end if wend end.
-----