moteur + lcd : assembleur + c
Répondre à la discussion
Affichage des résultats 1 à 4 sur 4

moteur + lcd : assembleur + c



  1. #1
    invite66d65435

    moteur + lcd : assembleur + c


    ------

    Bonsoir tout le monde ,

    En faite j'ai fait le programme d'un moteur commandé par pic16f877 + afficheur lcd qui affiche l'état de deux capteurs de fin de position.
    Le problème c'est que j'ai réalisé chaque code (celui de l'lcd et du moteur) chacun à part donc là en gros j'ai 2 portions de codes l'une réalisée par langage c sur le compilateur mikro c et l'autre en assembleur sur Mplab que je voudrai assembler en un seul code.
    voilà les 2 portions je voudrais bien une solution qui m'évite de recommencer à nouveau l'un des deux codes , (meme quand je compile le code de l'lcd avec mikro c j'ai un fichier .asm qui contient des instructions que mplab peut pas compiler).
    ****************************** *********************
    Le code de l'lcd :
    // Lcd pinout settings
    sbit LCD_RS at RC0_bit;
    sbit LCD_EN at RC1_bit;
    sbit LCD_D4 at RC2_bit;
    sbit LCD_D5 at RC3_bit;
    sbit LCD_D6 at RC4_bit;
    sbit LCD_D7 at RC5_bit;


    // Pin direction
    sbit LCD_RS_Direction at TRISC0_bit;
    sbit LCD_EN_Direction at TRISC1_bit;
    sbit LCD_D4_Direction at TRISC2_bit;
    sbit LCD_D5_Direction at TRISC3_bit;
    sbit LCD_D6_Direction at TRISC4_bit;
    sbit LCD_D7_Direction at TRISC5_bit;

    void main()
    {

    int i;
    portb=0b00000000;
    trisb=0b00001100;
    Lcd_Init();
    Lcd_out(1,1,"B");
    delay_ms(20);
    Lcd_out(1,2,"o");
    Lcd_cmd(_LCD_CURSOR_OFF);
    Lcd_out(1,3,"n");
    delay_ms(20);
    Lcd_out(1,4,"j");
    delay_ms(20);
    Lcd_out(1,5,"o");
    delay_ms(20);
    Lcd_out(1,6,"u");
    delay_ms(20);
    Lcd_out(1,7,"r");
    delay_ms(20);
    for(i=0; i<7; i++) { // Move text to the right 7 times
    Lcd_Cmd(_LCD_SHIFT_Right);
    }
    while (1)
    {
    if (PORTB.RB2 == 0)
    {
    Lcd_Out_Cp("Montee impossible");
    delay_ms(200);
    Lcd_cmd(_LCD_CLEAR);
    }
    if (PORTB.RB3 == 0)
    {Lcd_Out_Cp("Descente impossible");}
    delay_ms(200);
    Lcd_cmd(_LCD_CLEAR);
    }
    }
    ****************************** ***********************
    le code du moteur :

    LIST p=16F877 ; PIC16F877 is the target processor

    #include "P16F877.INC" ; Include header file

    CBLOCK 0x10 ; Temporary storage
    pos
    dc1
    dc2
    ENDC
    LIST p=16F877 ; PIC16F844 is the target processor

    #include "P16F877.INC" ; Include header file

    CBLOCK 0x10 ; Temporary storage
    ENDC

    ORG 0
    entrypoint goto start

    ORG 4
    intvector goto intvector

    start clrw ; Zero.

    movwf PORTD ; Ensure PORTD is zero before we enable it.
    bsf STATUS,RP0 ; Select Bank 1
    movlw 0xF0 ; Set port B bits 0-3 as outputs
    movwf TRISD ; Set TRISD register.

    bcf STATUS,RP0 ; Select Bank 0

    movlw 3 ; Initialize the motor position
    movwf pos
    movwf PORTD
    call delay
    clrf PORTD ; Motor drive off

    ;Main loop
    loop btfss PORTB,0 ; Test clockwise button
    call stepcw
    btfss PORTB,1 ; Test anti-clockwise button
    call stepccw
    goto loop

    ;Rotate one step clockwise
    stepcw bcf STATUS,C ; Clear the carry flag
    btfsc pos,3 ; Set carry if this bit set
    bsf STATUS,C
    rlf pos,W ; Pick up and rotate the motor's current position
    andlw 0x0F ; Mask to lower nibble
    movwf pos
    movwf PORTD ; Drive the outputs
    call delay ; Wait
    clrf PORTD ; Clear the output
    return

    ;Rotate one step counter clockwise
    stepccw bcf STATUS,C ; Clear the carry flag
    btfsc pos,0
    bsf pos,4
    rrf pos,W ; Pick up and rotate the motor's current position
    andlw 0x0F ; Mask to lower nibble
    movwf pos
    movwf PORTD ; Drive the outputs
    call delay ; Wait
    clrf PORTD ; Clear the output
    return

    ; This routine implements the delay between steps,
    ; and thus controls the motor speed.
    delay movlw 18 ; Outer loop iteration count
    movwf dc1
    dl1 clrf dc2 ; Initialize inner loop
    dl2 nop
    nop
    decfsz dc2,F
    goto dl2
    decfsz dc1,F
    goto dl1
    return

    END

    Merci d'avance

    -----

  2. #2
    Laboum

    Re : moteur + lcd : assembleur + c

    Bonjour naluri,

    Bon déjà pour que ce soit plus clair, il faut utiliser les balises code,car ça donne pas envie de si pencher.

    ****************************** *********************
    Le code de l'lcd :
    Code:
    // Lcd pinout settings
    sbit LCD_RS at RC0_bit;
    sbit LCD_EN at RC1_bit;
    sbit LCD_D4 at RC2_bit;
    sbit LCD_D5 at RC3_bit;
    sbit LCD_D6 at RC4_bit;
    sbit LCD_D7 at RC5_bit;
    
    
    // Pin direction
    sbit LCD_RS_Direction at TRISC0_bit;
    sbit LCD_EN_Direction at TRISC1_bit;
    sbit LCD_D4_Direction at TRISC2_bit;
    sbit LCD_D5_Direction at TRISC3_bit;
    sbit LCD_D6_Direction at TRISC4_bit;
    sbit LCD_D7_Direction at TRISC5_bit;
    
    void main()
    {
    
    int i;
    portb=0b00000000;
    trisb=0b00001100;
    Lcd_Init();
    Lcd_out(1,1,"B");
    delay_ms(20);
    Lcd_out(1,2,"o");
    Lcd_cmd(_LCD_CURSOR_OFF);
    Lcd_out(1,3,"n");
    delay_ms(20);
    Lcd_out(1,4,"j");
    delay_ms(20);
    Lcd_out(1,5,"o");
    delay_ms(20);
    Lcd_out(1,6,"u");
    delay_ms(20);
    Lcd_out(1,7,"r");
    delay_ms(20);
    for(i=0; i<7; i++) {               // Move text to the right 7 times
        Lcd_Cmd(_LCD_SHIFT_Right);
      }
    while (1)
    {
    if (PORTB.RB2 == 0)
    {
    Lcd_Out_Cp("Montee impossible");
    delay_ms(200);
    Lcd_cmd(_LCD_CLEAR);
    }
    if (PORTB.RB3 == 0)
    {Lcd_Out_Cp("Descente impossible");}
    delay_ms(200);
    Lcd_cmd(_LCD_CLEAR);
     }
    }
    ****************************** ***********************
    le code du moteur :
    Code:
                      LIST    p=16F877 ; PIC16F877 is the target processor
    
                  #include "P16F877.INC" ; Include header file
    
                  CBLOCK 0x10   ; Temporary storage                 
                     pos
                     dc1
                     dc2
                  ENDC
                  LIST    p=16F877 ; PIC16F844 is the target processor
    
                  #include "P16F877.INC" ; Include header file
    
                  CBLOCK 0x10   ; Temporary storage
                  ENDC
    
                  ORG   0
    entrypoint    goto  start
    
                  ORG   4
    intvector     goto  intvector
            
    start         clrw                    ; Zero.
    
                  movwf   PORTD           ; Ensure PORTD is zero before we enable it.
                  bsf     STATUS,RP0      ; Select Bank 1
                  movlw   0xF0            ; Set port B bits 0-3 as outputs
                  movwf   TRISD           ; Set TRISD register.           
                                                                   
                  bcf     STATUS,RP0      ; Select Bank 0
                     
                  movlw   3  	      ; Initialize the motor position 
                  movwf   pos                                             
                  movwf   PORTD
                  call    delay
                  clrf    PORTD	      ; Motor drive off	
    
    ;Main loop               
    loop	      btfss   PORTB,0         ; Test clockwise button
    	      call    stepcw
    	      btfss   PORTB,1         ; Test anti-clockwise button
    	      call    stepccw
    	      goto loop
                                   
    ;Rotate one step clockwise                               
    stepcw        bcf    STATUS,C	      ; Clear the carry flag
     	      btfsc  pos,3            ; Set carry if this bit set
     	      bsf    STATUS,C
    	      rlf    pos,W	      ; Pick up and rotate the motor's current position
                  andlw  0x0F             ; Mask to lower nibble
                  movwf  pos
                  movwf  PORTD	      ; Drive the outputs
                  call   delay	      ; Wait
                  clrf   PORTD            ; Clear the output
                  return
    
    ;Rotate one step counter clockwise                                                                             		
    stepccw       bcf    STATUS,C	      ; Clear the carry flag
    	      btfsc  pos,0
    	      bsf    pos,4
    	      rrf    pos,W	      ; Pick up and rotate the motor's current position
                  andlw  0x0F             ; Mask to lower nibble
                  movwf  pos
                  movwf  PORTD	      ; Drive the outputs
                  call   delay	      ; Wait
                  clrf   PORTD            ; Clear the output
                  return
    
    ; This routine implements the delay between steps,
    ; and thus controls the motor speed.
    delay         movlw   18	     ; Outer loop iteration count
    	      movwf   dc1		
    dl1	      clrf    dc2            ; Initialize inner loop
    dl2	      nop
    	      nop
    	      decfsz  dc2,F         
    	      goto    dl2
    	      decfsz  dc1,F
    	      goto    dl1
    	      return
    
    	      END
    Voici ma modeste contribution, je fais un tout petit peu d'assembleur
    Attend l'avis de d'autres experts
    Bon courage
    Dernière modification par Laboum ; 18/07/2013 à 14h13.

  3. #3
    inoxxam

    Re : moteur + lcd : assembleur + c

    Salut,
    Tu n'y échapperas pas, tu ne peux pas mettre deux codes sur un microcontrôleur de façon triviale. Il faut que tu fasses un code, unique, qui réalise toutes les fonctions voulues. Après ça peut être mélange de C et d'assembleur si ça t'arrange, mais c'est une autre affaire.
    Donc en gros, oui, tu es bon pour te retaper du code, cela dit ça ne devrait pas être très compliqué non plus.

  4. #4
    invite66d65435

    Re : moteur + lcd : assembleur + c

    Merci pour votre aide , oui inoxxam en faite j'ai pas pu y échapper j'ai refait tout le code en c et mon programme fonctionne à merveille

  5. A voir en vidéo sur Futura

Discussions similaires

  1. assembleur
    Par invite11df21b5 dans le forum Programmation et langages, Algorithmique
    Réponses: 6
    Dernier message: 26/02/2013, 14h00
  2. compréhension d'un programme assembleur pour afficher un afficheur lcd.
    Par invite71a200f7 dans le forum Électronique
    Réponses: 1
    Dernier message: 09/03/2012, 10h43
  3. assembleur
    Par bird12358 dans le forum Logiciel - Software - Open Source
    Réponses: 2
    Dernier message: 30/09/2009, 18h07
  4. initaliser lcd en Assembleur
    Par inviteb6f74ab5 dans le forum Électronique
    Réponses: 1
    Dernier message: 31/03/2009, 02h53
  5. pb assembleur
    Par invite89798d3f dans le forum Électronique
    Réponses: 3
    Dernier message: 24/04/2008, 11h11
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...