Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

microC compiler errors

[es] :: Elektronika :: Mikrokontroleri :: microC compiler errors

[ Pregleda: 1413 | Odgovora: 13 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon microC compiler errors12.04.2012. u 10:38 - pre 146 meseci
Imam problem sa ovim kompajlerom. Jos uvek se ucim C i kada po Tutorialu unesem na primer PORTB.0=0 , PORTB.0 nece da kompajlira i prijavljuje gresku. Takodje char i int po nekad neće da "odrade svoj posao". Da li je ovo do kompajlera ili ja lose kucam program?

[Ovu poruku je menjao nikolapirot dana 12.04.2012. u 13:49 GMT+1]
 
Odgovor na temu

ZAS011
Uzgajivač šargarepe izakuće
Vanuatu

Član broj: 288510
Poruke: 4543

ICQ: 8713400
Sajt: www.justfuckinggoogleit.c..


+530 Profil

icon Re: microC compiler errors12.04.2012. u 13:09 - pre 146 meseci
Postavi i taj kod sto ti pravi probleme, a i napisi koji mikroC koristis.
Da bi ti pomogli moras da das malko vise podataka (koji uC, koji kompajler - Pro ili obican, konfiguracija uC-a, ...)
--
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.
 
Odgovor na temu

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon Re: microC compiler errors12.04.2012. u 15:44 - pre 146 meseci
Evo na primer nesto mnogo prosto, koristim microC pro verziju, pic 16f628a
void main()
{
for(;;)
{
PORTB.0=1
PORTB.0=0
}

I takodje za USART, je objasnjenje ovakvo
do
Temp = Soft_Uart_Read(&Rx_Error);
while (Rx_Error);

ALi Rx_Error ne prepoznaje, treba li nekako da se definise taj Rx_Error i kako ?

 
Odgovor na temu

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon Re: microC compiler errors12.04.2012. u 15:57 - pre 146 meseci
Ili na primer kada mi treba da kad dodje signal da odradi neku komandu
if(PORTB.1=1)
ne prepoznaje PORTB.1
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: microC compiler errors12.04.2012. u 16:04 - pre 146 meseci
pogledaj primere ... imas uz mikroC primer za uart

nemas potrebe da koristis soft uart sa 16F628A, on ima hardwerski UART
Code:

char uart_rd;

void main() {

  ADCON1 |= 0x0F;                 // Configure AN pins as digital
  CMCON  |= 7;                    // Disable comparators

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  while (1) {                     // Endless loop
   if (UART1_Data_Ready()) {      // If data is received,
     uart_rd = UART1_Read();      //   read the received data,
     UART1_Write(uart_rd);        //   and send data via UART
    }
  }
}


za PORTB.0 = 1 .. pogledaj help za "accessing individual bits" treba

PORTB.F0 = 1;
PORTB.F0 = 0;

Citat:

Accessing Individual Bits
The mikroC PRO for PIC allows you to access individual bits of 8-bit variables. It also supports sbit and bit data types

Lets use the Global Interrupt Bit (GIE) as an example. This bit is defined in the definition file of the particular MCU as :

const register unsigned short int GIE = 7;
sbit GIE_bit at INTCON.B7;To access this bit in your code by its name, you can write something like this:

// Clear Global Interrupt Bit (GIE)
INTCON.GIE = 0;In this way, if GIE bit changes its position in the register, you are sure that the appropriate bit will be affected.
But, if GIE bit is not located in the designated register, you may get errors.

Another way of accesing bits is by using the direct member selector (.) with a variable, followed by one of identifiers B0, B1, … , B7, or F0, F1, … F7, with F7 being the most significant bit, to access the desired bit :

// Clear bit 0 in INTCON register
INTCON.B0 = 0;

// Set bit 5 in ADCON0 register
ADCON0.F5 = 1;
In this way, if the target bit changes its position in the register, you cannot be sure that you are invoking the appropriate bit.

This kind of selective access is an intrinsic feature of mikroC PRO for PIC and can be used anywhere in the code. Identifiers B0–B7 are not case sensitive and have a specific namespace. You may override them with your own members B0–B7 within any given structure.

Note: If aiming at portability, avoid this style of accessing individual bits, use the bit fields instead.

Also, you can access the desired bit by using its alias name, in this case GIE_bit :

// Set Global Interrupt Bit (GIE)
GIE_bit = 1;In this way, if the GIE bit changes its register or position in the register, you are sure that the appropriate bit will be affected.

See Predefined Globals and Constants for more information on register/bit names.

sbit type
The mikroC PRO for PIC compiler has sbit data type which provides access to registers, SFRs, variables, etc.
You can declare a sbit varible in a unit in such way that it points to a specific bit in SFR register:

extern sfr sbit Abit; // Abit is precisely defined in some external file, for example in the main program unit
In the main program you have to specify to which register this sbit points to, for example:

sbit Abit at PORTB.F0; // this is where Abit is fully defined
...
void main() {
...
}
In this way the variable Abit will actually point to PORTB.0. Please note that we used the keyword sfr for declaration of Abit, because we are pointing it to PORTB which is defined as a sfr variable.
In case we want to declare a bit over a variable which is not defined as sfr, then the keyword sfr is not necessary, for example:

extern sbit AnotherBit; // AnotherBit is precisely defined in some external file, for example in the main program unit
char MyVar;
sbit AnotherBit at MyVar.F0; // this is where AnotherBit is fully defined
...
void main() {
...
}
at keyword
You can use the keyword "at" to make an alias to a variable, for example, you can write a library without using register names, and later in the main program to define those registers, for example:

extern char PORTAlias; // here in the library we can use its symbolic name
char PORTAlias at PORTB; // this is where PORTAlias is fully defined
...
void main() {
...
}
Note: Bear in mind that when using at operator in your code over a variable defined through a extern modifier, appropriate memory specifer must be appended also.

bit type
The mikroC PRO for PIC compiler provides a bit data type that may be used for variable declarations. It can not be used for argument lists, and function-return values.

bit bf; // bit variableThere are no pointers to bit variables:

bit *ptr; // invalidAn array of type bit is not valid:

bit arr [5]; // invalid Note :
Bit variables can not be initialized.
Bit variables can not be members of structures and unions.
Bit variables do not have addresses, therefore unary operator & (address of) is not applicable to these variables



Kako se pristupa odredjenom bitu je vezano za kompajler, to nije standardna c stvar, na C18 npr bi to bilo PORTBbits.RB0 = 1
 
Odgovor na temu

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon Re: microC compiler errors12.04.2012. u 16:41 - pre 146 meseci
Ali iz odredjenog razloga po nekad nece da kompajlira, na primer sad nece da kompajlira niti Soft_Usart_Init(9600); niti Usart_Init(9600);
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.com
Via: [es] mailing liste

Sajt: mysql.rs


+2377 Profil

icon Re: microC compiler errors12.04.2012. u 16:49 - pre 146 meseci
uvek ti napise u gresci gde je problem, kopiraj ovde source i gresku pa cemo ti reci sto nece da kompajlira
 
Odgovor na temu

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon Re: microC compiler errors12.04.2012. u 17:09 - pre 146 meseci
Ali sad sam zapeo odma

void main()
{

Usart_Init(9600);
Delay_ms(100);
Usart_Write(20);


}



Izbaci sledeci error
Undeclared inditifier 'Usart_Init' in expression
Undeclared inditifier 'Usart_Write' in expression
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.com
Via: [es] mailing liste

Sajt: mysql.rs


+2377 Profil

icon Re: microC compiler errors12.04.2012. u 17:16 - pre 146 meseci
zato sto nije Usart_Init() nego UART1_Init();

imas S viska + C je CASE SENSITIVE (mikroC ponekad i nije, ali ostali C kompajleri jesu)
 
Odgovor na temu

ZAS011
Uzgajivač šargarepe izakuće
Vanuatu

Član broj: 288510
Poruke: 4543

ICQ: 8713400
Sajt: www.justfuckinggoogleit.c..


+530 Profil

icon Re: microC compiler errors12.04.2012. u 20:00 - pre 146 meseci
Posto je Pro kompajler onda je
Code:
UART1_Init();
...
UART1_Write();

--
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.
 
Odgovor na temu

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon Re: microC compiler errors13.04.2012. u 11:30 - pre 146 meseci
Napokon je uspelo. Ali sad imam drugi problem. Kada testiram to u proteusu (nemam mogucnosti da ubacujem u cip i testiram na zalost) desava se sledece. Ja sam zamislio da kada dovedem signal na RB4 na predajniku da se upali RB4 na prijemniku, i tako isto za RB5 i RB6. Ali kad dovedem jedinicu na RB4 upale se RB4,RB5 i RB6. Da li bi neko mogao da mi kaze zasto.
Predajnik
Code:

void main() {
     TRISB.TRISB4=1;
     TRISB.TRISB5=1;
     TRISB.TRISB6=1;
     UART1_Init(9600);
     Delay_Ms(100)  ;
     for(;;)
     {
     if(PORTB.RB4=1)
     UART1_Write(4);
     if(PORTB.RB5=1)
     UART1_Write(5);
     if(PORTB.RB6=1)
     UART1_Write(6);
     }


}

Prijemnik
Code:

void main() {
    int Prijem;
    TRISB.TRISB4=0;
    TRISB.TRISB5=0;
    TRISB.TRISB6=0;
    PORTB.RB4=0;
    PORTB.RB5=0 ;
    PORTB.RB6=0  ;
     UART1_Init(9600);
    Delay_Ms(100);
    for(;;)
    {
      if(UART1_Data_Ready())
      {
         Prijem=UART1_Read() ;
         if(Prijem=4)
         PORTB.RB4=1;
         else
         PORTB.RB4=0     ;
         if(Prijem=5)
            PORTB.RB5=1 ;
         else
         PORTB.RB5=0   ;
         if(Prijem=6)
            PORTB.RB6=1 ;
         else
         PORTB.RB6=0;
         }
         }

}
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: microC compiler errors13.04.2012. u 11:55 - pre 146 meseci
Greska ti je sto je poredjenje == a ne =

dakle NIJE

if(Prijem=6)

nego

if(Prijem==6)

sad par hintova nevezano za tu gresku, za pocetak, kreni bolje da nazubljujes kod i uvek if() segmente u pocetku stavljaj u {}

Code:

void main() {
     TRISB.TRISB4=1;
     TRISB.TRISB5=1;
     TRISB.TRISB6=1;
     UART1_Init(9600);
     Delay_Ms(100)  ;
     for(;;)
     {
       if(PORTB.RB4=1)
       {
         UART1_Write(4);
       }
       if(PORTB.RB5=1)
       {
         UART1_Write(5);
       }
       if(PORTB.RB6=1)
       {
         UART1_Write(6);
       }
     }
}


Kada se izvezbas onda mozes da skracujes to sa
Code:

     for(;;)
     {
       if(PORTB.RB4==1)
         UART1_Write(4);

       if(PORTB.RB5==1)
         UART1_Write(5);

       if(PORTB.RB6==1)
         UART1_Write(6);
     }




probaj prijemnik ovako: (http://www.cprogramming.com/tutorial/lesson5.html)
Code:


void main() {
    int Prijem;
    TRISB.TRISB4=0;
    TRISB.TRISB5=0;
    TRISB.TRISB6=0;
    PORTB.RB4=0;
    PORTB.RB5=0 ;
    PORTB.RB6=0  ;
    UART1_Init(9600);
    Delay_Ms(100);
    for(;;)
    {
      if(UART1_Data_Ready())
      {
         Prijem=UART1_Read() ;
         switch(Prijem){
           case 4:
             PORTB.RB4=1;
             PORTB.RB5=0;
             PORTB.RB6=0;
           break;

           case 5:
             PORTB.RB4=0;
             PORTB.RB5=1;
             PORTB.RB6=0;
           break;

           case 6:
             PORTB.RB4=0;
             PORTB.RB5=0;
             PORTB.RB6=1;
           break;

           default:
             PORTB.RB4=0;
             PORTB.RB5=0;
             PORTB.RB6=0;
         }
      }
}




Mada ti je mnogo bolje da imas nesto tipa:


Code:

void main() {
     unsigned char old4;
     unsigned char old5;
     unsigned char old6;

     TRISB.TRISB4=1;
     TRISB.TRISB5=1;
     TRISB.TRISB6=1;
     UART1_Init(9600);
     Delay_Ms(100);

     old4=0;
     old5=0;
     old6=0;
     UART1_Write(104);
     UART1_Write(105);
     UART1_Write(106);

     for(;;)
     {
       if (PORTB.RB4 != old4)
       {
         old4 = PORTB.RB4;
         if(old4)
         {
           UART1_Write(4);
         } else {
           UART1_Write(104);
         }
       }

       if (PORTB.RB5 != old5)
       {
         old5 = PORTB.RB5;
         if(old5)
         {
           UART1_Write(5);
         } else {
           UART1_Write(105);
         }
       }

       if (PORTB.RB6 != old6)
       {
         old6 = PORTB.RB6;
         if(old6)
         {
           UART1_Write(6);
         } else {
           UART1_Write(106);
         }
       }


     }
}

 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: microC compiler errors13.04.2012. u 11:57 - pre 146 meseci
sada tebi ostavljam da napravis prijemnik za ovaj predajnik (malo veci, sa old) :)
hint: taj predajnik ti omogucuje da na prijemniku palis vise od jednog izlaza :)
 
Odgovor na temu

nikolapirot
Student
Srbija Pirot

Član broj: 235367
Poruke: 239
*.dynamic.isp.telekom.rs.



+1 Profil

icon Re: microC compiler errors13.04.2012. u 13:03 - pre 146 meseci
Hvala na odgovorima, uspeo sam :)
 
Odgovor na temu

[es] :: Elektronika :: Mikrokontroleri :: microC compiler errors

[ Pregleda: 1413 | Odgovora: 13 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.