PIC] Compilateur CCS C - Problème utilisation PORTB PIC 16F876a
Répondre à la discussion
Affichage des résultats 1 à 2 sur 2

PIC] Compilateur CCS C - Problème utilisation PORTB PIC 16F876a



  1. #1
    invite087fa5ab

    PIC] Compilateur CCS C - Problème utilisation PORTB PIC 16F876a


    ------

    Bonsoir,

    j'utilise le compilateur c de ccs.
    -le compilateur indique 0error j'ai transférer le fichier HEX à proteus mais il ne se passe rien au niveau du PORTB s il vous plait aidez moi .voici le programme:


    #include <16F876A.h>
    #include <float.h>
    #include <math.h>
    //#device *=16 ADC=8 //16bit pointer, 8-bit ADC
    #use delay(clock=20000000)
    #fuses HS,NOWDT,NOPROTECT,PUT,NOWRT,B ROWNOUT,NOLVP
    #define TRISA 0b00000000
    #define TRISB 0b00000000
    #define TRISC 0b00000000
    #define Port_Ai 0b00000000 //Initial valua for Port A
    #define Port_Bi 0b00000000 //Initial valua for Port B
    #define Port_Ci 0b00000000 //Initial valua for Port C
    typedef struct {
    int1 bit0;
    int1 bit1;
    int1 bit2;
    int1 bit3;
    int1 bit4;
    int1 bit5;
    int1 bit6;
    int1 bit7;
    } flags;
    //Important time variables
    float ts, ta, tb, t0, tmag; //time related variable
    //Important phase variables
    float phase, phaset1; //to identify sector number
    float phaset2, thetha, thetha1, thetha2; //to calculate related time variables
    float modin; //modulation index
    float ZZ; //to convert angles larger than 360 degrees into the scale of 0 to 360 degrees
    //Important voltage related variables
    float vref, vdc; //to calculate modulation index
    //Other variables
    int8 i, j, h; //counter
    float nsamp, result1; //condition for one complete cycle
    int8 n; //sector number
    //Variables for Rounding up Process
    float result, integral, integral1, XX; // variables for rounding up process
    int8 YY, integral2;
    float testa1;
    //Interrupt Bit
    flags sys01;
    #define flg_10ms sys01.bit0
    //Arrays of Outputs of Each Sector (1 to 6)
    int8
    outta1[8]={0b00000000,0b00000100,0b0000 0110,0b00000111,0b00000111,0b0 0000110,0b00000100,
    0b00000000}; //test mar
    int8
    outta2[8]={0b00000000,0b00000010,0b0000 0110,0b00000111,0b00000111,0b0 0000110,0b00000010,
    0b00000000}; //test mar
    int8
    outta3[8]={0b00000000,0b00000010,0b0000 0011,0b00000111,0b00000111,0b0 0000011,0b00000010,
    0b00000000}; //test mar
    int8
    outta4[8]={0b00000000,0b00000001,0b0000 0011,0b00000111,0b00000111,0b0 0000011,0b00000001,
    0b00000000}; //test mar
    int8
    outta5[8]={0b00000000,0b00000001,0b0000 0101,0b00000111,0b00000111,0b0 0000101,0b00000101,
    0b00000000}; //test mar
    int8
    outta6[8]={0b00000000,0b00000100,0b0000 0101,0b00000111,0b00000111,0b0 0000101,0b00000100,
    0b00000000}; //test mar
    int8 timema[8];
    //Initialization
    void init(){
    setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
    // enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);
    enable_interrupts(INT_TIMER1);
    }
    //Function to transfer output from array to output port
    void showout(){

    if(n == 1)
    {
    for(j=0;j<8;j++)
    {
    output_b(outta1[j]);
    delay_ms(timema[j]);
    }
    }
    if(n == 2)
    {
    for(j=0;j<8;j++)
    {
    output_b(outta2[j]);
    delay_ms(timema[j]);
    }
    }
    if(n == 3)
    {
    for(j=0;j<8;j++)
    {
    output_b(outta3[j]);
    delay_ms(timema[j]);
    }
    }
    if(n == 4)
    {
    for(j=0;j<8;j++)
    {
    output_b(outta4[j]);
    delay_ms(timema[j]);
    }
    }
    if(n == 5)
    {
    for(j=0;j<8;j++)
    {
    output_b(outta5[j]);
    delay_ms(timema[j]);
    }
    }
    if(n == 6)
    {
    for(j=0;j<8;j++)
    {
    output_b(outta6[j]);
    delay_ms(timema[j]);
    }
    }
    }

    //Function to round up ta, tb and t0
    void roundup()
    {
    result=modf(XX,&integral);
    YY = integral;
    if ((result >=0) && (result <0.5))
    {
    YY = YY + 0;
    }
    else{
    if ((result >= 0.5) && (result < 1))
    {
    YY = YY + 1;
    }
    }
    }
    //Function to identifying sector number
    void idsec()
    {
    for(i=1;i<=6;i++)
    {
    phaset1 = i*3.142/3;
    phaset1 = phaset1 - phase;
    phaset2 = phase - (i - 1)*3.142/3;
    if((phaset1 >=0) && (phaset2 >=0))
    {
    n = i;
    }
    }
    }
    //Function to collect and re-insert rounded up numbers for important time variables
    void rdjob()
    {
    XX = ta;
    roundup();
    ta = YY;
    XX = tb;
    roundup();
    tb = YY;
    XX = t0;
    roundup();
    t0 = YY;
    }
    //Function to obtain input details
    void in_put()
    {
    vdc = 10;
    vref = 10;
    //fundamental frequency of 10 Hz (100 samples)
    phase = 2*3.142*h*0.01;
    }
    // Calculation of time ta, tb, ts and t0
    void tcal()
    {
    ts = 1000/100;
    thetha = phase;
    thetha1 = (n*3.142/3) - thetha;
    thetha2 = thetha - (n - 1)*3.142/3;
    tmag = (sqrt(3))*(modin)*ts/4; //moin=vref1/vdc1
    ta = (tmag)*(sin(thetha1)); //test time
    tb = (tmag)*(sin(thetha2)); //test time
    t0 = ts - ta - tb;
    t0 = t0/2;
    rdjob();
    //Putting times into timema array
    timema[0]=t0;
    timema[3]=t0;
    timema[4]=t0;
    timema[7]=t0;
    timema[1]=ta;
    timema[6]=ta;
    timema[2]=tb;
    timema[5]=tb;
    }
    //Main function
    void main()
    {
    Mainloop:

    nsamp = 100;

    result1=modf(nsamp,&integral1) ;

    integral2=integral1+1;

    h=1;
    do
    {

    in_put();
    idsec();
    tcal();
    h++;
    } while (h < integral2);

    goto Mainloop;

    }

    -----

  2. #2
    carcan

    Re : PIC] Compilateur CCS C - Problème utilisation PORTB PIC 16F876a

    Hello !

    tu n'appelles jamais ta fonction "Init", un programme écrit en CCS soit avoir une structure de ce genre :

    Code:
    void main()
    {
       float Measure;
       int1 Hold = 0;
       char c;
       
       setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
       
       Offset = read_int16_eeprom(0); 
       Divid = read_float_eeprom(2);
       
       usb_cdc_init();
       usb_init();
       lcd_init();
          
       // [TOUT CE QUI FAIT PARTIE DE L'INITIALISATION]
       
       printf (lcd_putc,"\f");
       
       enable_interrupts(INT_TIMER1);
       enable_interrupts(GLOBAL);
       
         
       while(TRUE)
       {
           //USB Dialog
           usb_task();
           enable_interrupts(GLOBAL);
       
           // [TOUT CE QUI FAIT PARTIE DE LA BOUCLE PRINCIPALE]
       }
    
    }
    Sinon, je n'ai regardé qu'en vrac, mais ce n'est pas très judicieux (à mon avis) de faire des racines carrées et autres calculs longs avec un 16F !!!

    A+
    Laurent

Discussions similaires

  1. Problème utilisation PORTB PIC 16F876
    Par invite62afc4d2 dans le forum Électronique
    Réponses: 15
    Dernier message: 19/06/2011, 16h06
  2. Probléme Pour Configurer le PORTB
    Par invite7cda0f37 dans le forum Électronique
    Réponses: 6
    Dernier message: 06/02/2011, 11h26
  3. problème CAN pic 16F876A
    Par invitecd1c8761 dans le forum Électronique
    Réponses: 2
    Dernier message: 06/04/2010, 13h17
  4. problème programmation d'un pic 16F876A
    Par flyermike dans le forum Électronique
    Réponses: 14
    Dernier message: 29/08/2007, 15h18
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...