Dioda - un site pentru marii pasionati de electronica  
Toggle ContentToggle Content .:: Home :: Downloads :: Community Forums :: Register ::.
Toggle Content Meniu Principal
 HOME
 Home
 Search Web Continut Community
 Forum
 Members options
 News
 Surveys

Toggle Content Produs Random

Toggle Content Mesaje Forum

Toggle Content Login

Welcome Anonymous

Nickname
Password

Membership:
Latest: Zoltan
New Today: 0
New Yesterday: 0
Overall: 898

People Online:
Members: 0
Visitors: 6
Total: 6
Who Is Where:
 Visitors:
01: Forum
02: Cauta Componenta
03: News
04: Forum
05: Contul meu
06: Forum

Staff Online:

No staff members are online!

Toggle Content Languages
English

Toggle Content Ultimile Imagini

News › Programarea microcontrolerelor AVR folosind compilatorul C GCC
MICROCONTROLERE
Acest articol isi propune a fi un ajutor in initierea in programarea microcontrolerelor AVR folosind compilatorul C GCC.
Compilatorul GCC este open source si provine din "universul" UNIX. Au fost realizate o serie de port-uri ale acestuia si pentru o buna serie de microcontrollere. Printre aceste "portari" o varianta bine raspandita este AVR GCC.
Pe internet sunt disponibile o serie de articole tutoriale pentru initierea in folosirea acestui compilator. Din nefericire o buna parte din acestea sunt incomplete, in progres sau contra cost .



Un bun si succint tutorial poate fi gasit (printre multe ale informatii interesante) la adresa http://www.mikrocontroller.net .
Din nefericire informatia este disponibila in germana si mai mult decat atat este prezentata intr-o singura pagina Web. Deoarece este prezentata intr-o singura pagina de dimensiune foarte mare nu poate fi tradusa automat in totalitate de translatoarele disponibile pe intrenet.

Pentru a putea beneficia de aceste informatii am impartit fisierul disponibil la adresa http://www.mikrocontroller.net in subcapitole prezentate fiecare separat in pagina sa.
Articolul original impartit poate fi gasit la adresa http://www.dioda.ro/avr/tutorial/de/avr_gcc_tutorial_toc.html .

Versiunea tradusa automat cu ajutorul uneltelor de traducere automata de la Google se poate gasi aici : http://www.google.com/translate?u=http%3A%2F%2Fwww.dioda.ro%2Favr%2Ftutorial%2Fde%2Favr_gcc_tutorial_toc.html&langpair=de%7Cen&hl=en&ie=UTF8.

Quick reference si cateva tips and trics-uri referitoare la programarea microcontroller -elor din familia AVR folosind limbajul C :
1. Operatori pe biti in C
| bit OR
& bit AND
~ bit NOT
^ bit EXLUSIVE OR (XOR)
<< bit LEFT SHIFT
>> bit RIGHT SHIFT

2. Pentru setarea bitilor intr-o variabila vom folosi ‘|’ OR si pentru a-i sterge vom folosi ‘&’ AND (operatori pe biti).
De exmplu pentru aprindederea/stingerea unui led conectat la +alim si un port putem scrie "
#define LED_ON(nr) PORTB &= ~(1 << (nr))
#define LED_OFF(nr) PORTB |= (1 << (nr))
Prima linie face acel pin port 0 si a doua va seta doar acel pin pe 1.


3. Exemplul 1 de macrouri pentru accesul si operatiunile cu pinii unui port
--- begin included file ---
#define BIT(p,b) (b)

#define PORT(p,b) (PORT ## p)
#define PIN(p,b) (PIN ## p)
#define DDR(p,b) (DDR ## p)

#define MASK(b) (1 << (b))

#define Set_Port_Bit(p,b) ((p) |= MASK(b))
#define Clr_Port_Bit(p,b) ((p) &= ~MASK(b))
#define Tgl_Port_Bit(p,b) ((p) ^= MASK(b))

#define Get_Port_Bit(p,b) (((p) & MASK(b)) != 0)

#define Set_Output(io) Set_Port_Bit(PORT(io),BIT(io))
#define Reset_Output(io) Clr_Port_Bit(PORT(io),BIT(io))
#define Toggle_Output(io) Tgl_Port_Bit(PORT(io),BIT(io))
#define Get_Output(io) Get_Port_Bit(PORT(io),BIT(io))

#define Get_Input(io) Get_Port_Bit(PIN(io),BIT(io))

#define Tristate(io) Clr_Port_Bit(DDR(io),BIT(io))
#define Drive(io) Set_Port_Bit(DDR(io),BIT(io))
--- end included file ---
Exemplu de scriere :

#define LED B,6
Set_Ouput(LED);
Daca va intrebati ce face operatorul ## este concatenare, detalii aici: http://gcc.gnu.org/onlinedocs/gcc-3.2.3/cpp/Concatenation.html


3. Exemplul 2 pentru acces pe biti.
#include <avr/io.h>

// Define the bits in the port
typedef struct
{
   unsigned char bit0 : 1,
                 bit1 : 1,
                 bit2 : 1,
                 bit3 : 1,
                 bit4 : 1,
                 bit5 : 1,
                 bit6 : 1,
                 bit7 : 1;
} bit_field;

// Define macro to get the value of each bit
#define GET_BIT(port) (*(volatile bit_field *) (_SFR_ADDR(port)))

// Define functions for each bit of the I/O ports in the program
#define SIG    GET_BIT(PINB).bit0
#define LED       GET_BIT(PORTD).bit0

int main (void)
{
    for (;;)
    {
        if (SIG) LED = 1;
            else LED = 0;
    }
}

4. Exemplu optimizat de convertire Uppercase :
// c este litera = 'a'
// Convertit la majuscula
if (c >= 'a')
c &= ~0x20;
Este mult mai rapid decat c-= 0x20 deoarece se executa doar cu instructiuni native procesor.

5. Fiecare port are asociate 3 locatii de memorie pentru I/O, care determina functionarea acelui port.
1. Data Direction Register - DDRx – Read/Write
2. Data Register – PORTx – Read/Write
3. Port Input Pins – PINx – Read Oonly
De exemplu portul A , are : PORTA, DDRA, si PINA. Daca dorim sa configuram cei mai de sus 4 pini ai portului D ca si intrare si cei mai de jos 4 ca si iesire vom seta : DDRD = 0x0F;

6. Secventele de escape (mostenite de la inceputurile programarii) :
a alert (bell)  backspace f formfeed newline
carriage return horizontal tab v vertical tab
ackslash ? question mark ’ single quote
” double quote

7. Directivele preprocesor - preprocesorul se executa inaintea compilatorului
#include
#define
Incluziunea conditionala
#indef


Posted by administrator on Tuesday, February 07, 2006 (18:44:33) (5521 reads) [ Administration ]

Associated Topics

ANUNTURI

"Programarea microcontrolerelor AVR folosind compilatorul C GCC" | Login/Create an Account | 1 comment
Threshold
The comments are owned by the poster. We aren't responsible for their content.

cheap handbags (Score: 1 )
by jku8oo on Thursday, November 03, 2011 (02:19:32)
(User Info | Send a Message)
In possession of expert technocrat team, sales executives cheap purses personnel, we strive to operating collectively towards the aim of taking the corporation to better heights.Welcome to Handbag Heaven, in which you could indulge your self in the most up-to-date handbags, trendy purses and additional! Our excellent handbags are hand chosen to provide substantial top quality with no the high price tag tag, so obtaining the hottest appears cheap handbags has certainly not been less complicated.

Our burberry scarves sale online store offer more new burberry scarves brand burberry outlet for you to choose, such as burberry cashmere scarf, burberry check scarf, burberry scarf replica, burberry silk scarf, burberry wool scarf, burberry shawl, men burberry cashmere scarf, burberry tie, burberry wallet, men burberry shirt, pink burberry scarf, burberry handbags purses, burberry nova scarf for sale, the price of burberry scarf sale burberry scarves on sale is very cheap, but they are authentic and new, welcome to our burberry scarf shop.



Toggle Content Related Links

Toggle Content Article Rating
Average Score: 4
Votes: 3


Please take a second and vote for this article:

Excellent
Very Good
Good
Regular
Bad


Toggle Content Options

Toggle Content Cauta Componenta

Toggle Content Sondaj
Ce program de proiectare electronice folositi ?

Orcad
37 %37 %37 %
Protel
11 %11 %11 %
Eagle
26 %26 %26 %
Target X001
3 %3 %3 %
WinPCB
3 %3 %3 %
Altul
17 %17 %17 %
Results :: Polls

Votes: 829
Comments: 1

Toggle Content Web Browsing Tools



Site-ul Dioda.ro este propietatea societatii Artirom PRO SRL - Cod Fiscal RO14235481 - Str. Bucegi Nr. 45 Sect 1 Bucuresti


You can syndicate our news using the file news.php or news2.php
Interactive software released under GNU GPL, Code Credits, Privacy Policy