IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

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


Sujet :

C

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Collégien
    Inscrit en
    Février 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Février 2014
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Compilateur CCS C - Problème utilisation PORTB PIC 16F876a
    Bonsoir,

    j'utilise le compilateur c de ccs.
    -le compilateur indique 0error
    J'ai transféré le fichier HEX à Proteus mais il ne se passe rien au niveau du PORTB. S'il vous plait aidez moi.
    Voici le programme :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    #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,BROWNOUT,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,0b00000110,0b00000111,0b00000111,0b00000110,0b00000100,
    0b00000000}; //test mar
    int8
    outta2[8]={0b00000000,0b00000010,0b00000110,0b00000111,0b00000111,0b00000110,0b00000010,
    0b00000000}; //test mar
    int8
    outta3[8]={0b00000000,0b00000010,0b00000011,0b00000111,0b00000111,0b00000011,0b00000010,
    0b00000000}; //test mar
    int8
    outta4[8]={0b00000000,0b00000001,0b00000011,0b00000111,0b00000111,0b00000011,0b00000001,
    0b00000000}; //test mar
    int8
    outta5[8]={0b00000000,0b00000001,0b00000101,0b00000111,0b00000111,0b00000101,0b00000101,
    0b00000000}; //test mar
    int8
    outta6[8]={0b00000000,0b00000100,0b00000101,0b00000111,0b00000111,0b00000101,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
    Modérateur

    Avatar de Bktero
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2009
    Messages
    4 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Juin 2009
    Messages : 4 481
    Points : 13 679
    Points
    13 679
    Billets dans le blog
    1
    Par défaut
    Bonjour,

    Nul part tu ne modifies PORTx ou TRISx. Normal ?
    Qu'est ce que la fonction output_b() ?

    Au lieu de nous balancer un code de 10 km de long, essaye de faire un code simple. Un main avec juste la configuration de ton port et une écriture sur ce port. Tu vérifies avec le résultat au voltmètre ou à l'oscilloscope.

    Remarque aussi : tu utilises énormément de flottants. Je ne suis pas sûr que les calculs en flottant soit la force des PIC16. Regarde si tu en as vraiment besoin.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Collégien
    Inscrit en
    Février 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Février 2014
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    OUTPUT_x()
    Syntaxe
    OUTPUT_x(valeur)
    Rôle
    Permet de sortir l’octet «valeur» sur le port x , préalablement configuré en sortie.
    Exemple
    OUTut_B(0x1F)
    La valeur 1FH est envoyée sur le port B.

  4. #4
    Modérateur

    Avatar de Bktero
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2009
    Messages
    4 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Juin 2009
    Messages : 4 481
    Points : 13 679
    Points
    13 679
    Billets dans le blog
    1
    Par défaut
    préalablement configuré en sortie.
    Et où est faite cette configuration préalable ?

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Collégien
    Inscrit en
    Février 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Février 2014
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    valeur=outta1,outta2,.......ect
    outta1=outta1[8] = {0b00000000, 0b00000100, 0b00000110,
    0b00000111, 0b00000111, 0b00000110, 0b00000100, 0b00000000}

  6. #6
    Modérateur

    Avatar de Bktero
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2009
    Messages
    4 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Juin 2009
    Messages : 4 481
    Points : 13 679
    Points
    13 679
    Billets dans le blog
    1
    Par défaut
    Le mot "valeur" n'apparait pas dans ton code et nul part tu n'affectes la valeur outta1 ou outta2 à une variable.

Discussions similaires

  1. Réponses: 63
    Dernier message: 09/03/2008, 00h30
  2. Réponses: 2
    Dernier message: 07/01/2007, 10h06
  3. [JSTL] [EL] Problème utilisation <c:out>
    Par XavierL dans le forum Taglibs
    Réponses: 7
    Dernier message: 14/08/2005, 20h12
  4. (Problème) Utilisation de l'API mySQL [Delphi 2005 Perso]
    Par will-scs dans le forum Bases de données
    Réponses: 2
    Dernier message: 08/08/2005, 18h26
  5. [JAR]Problème utilisation manifest et jar
    Par doudine dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 07/01/2005, 10h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo