Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Using Embedded C
*
*
*Embedded C is nothing but a subset of C
language which is compatible with certain
microcontrollers.
*Some features are ...
*
*//Headers
*#include<avr/io.h>//Header file for AVR i/o
*#include<util/delay.h>//Header file for delay
*// main program
...
*
*Syntax:
if( condition)
{
statement…….
}
else
{
statement……..
}
*
Int a=4;
Int b=5;
If(a>b)
printf(“ a is largest”);
else
printf(“ b is largest”);
*
*Syntax:
Initial counter
Do
{
statement…….
update statement
}
While(condition);
*
Int a=4;
do
{
a++;
}
while(a>5);
*
*Syntax:
For( initial counter; test condition; update stmt)
{
statement……..
statement……...
}
*Program:
for(int i=0;i<5;i...
*
*We have four Ports
*PORT A
*PORT B
*PORT C
*PORT D
*All ports have Read-Modify-Write functionality.
*(all pins are capa...
*
*Each port pin have three register bits
*1. DDRx - Data Direction Register
*2. PORTx - Port output
*3. PINx - Port input
*
*If DDRx is configured as logic high,
the pin is configured as output pin.
*If DDRx is configured as logic low,
the pin ...
*
*If PORTx is written logic one when the pin is
configured as an output pin, the port pin is
driven high (one).
*If PORTx...
*
*PINx is used to read the data
*Ex: Say a sensor is connected to lsb of Port D.
* To read the status of the sensor, we u...
*
Program:
main()
{
DDRB=0XFF;
while(1)
{
PORTB=0XFF;
_delay_ms(255);
PORTB=0X00;
_delay_ms(255);
}
}
*
*
*
*
Nächste SlideShare
Wird geladen in …5
×
Nächste SlideShare
AVR programming - BASICS
Weiter
Herunterladen, um offline zu lesen und im Vollbildmodus anzuzeigen.

45

Teilen

Programming ATmega microcontroller using Embedded C

Herunterladen, um offline zu lesen

Basics on Embedded C and Programming ATmega micro-controller using embedded C.

Ähnliche Bücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Ähnliche Hörbücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Programming ATmega microcontroller using Embedded C

  1. 1. Using Embedded C *
  2. 2. * *Embedded C is nothing but a subset of C language which is compatible with certain microcontrollers. *Some features are added using header files like <avr/io.h>, <util/delay.h>. *scanf() and printf() are removed as the inputs are scanned from the sensors and outputs are given to the ports. *Control structures remain the same like if- statement, for loop, do-while etc.
  3. 3. * *//Headers *#include<avr/io.h>//Header file for AVR i/o *#include<util/delay.h>//Header file for delay *// main program *Int main() *{ *while(1) *{ code… } *Return (0); *}
  4. 4. * *Syntax: if( condition) { statement……. } else { statement…….. }
  5. 5. * Int a=4; Int b=5; If(a>b) printf(“ a is largest”); else printf(“ b is largest”);
  6. 6. * *Syntax: Initial counter Do { statement……. update statement } While(condition);
  7. 7. * Int a=4; do { a++; } while(a>5);
  8. 8. * *Syntax: For( initial counter; test condition; update stmt) { statement…….. statement……... } *Program: for(int i=0;i<5;i++) printf(“Hello Robofifa’14”);
  9. 9. * *We have four Ports *PORT A *PORT B *PORT C *PORT D *All ports have Read-Modify-Write functionality. *(all pins are capable of performing dual functions!)
  10. 10. * *Each port pin have three register bits *1. DDRx - Data Direction Register *2. PORTx - Port output *3. PINx - Port input
  11. 11. * *If DDRx is configured as logic high, the pin is configured as output pin. *If DDRx is configured as logic low, the pin is configured as input pin. *DDRx = 0xff; // configuring as o/p *DDRx = 0x00; // configuring as i/p
  12. 12. * *If PORTx is written logic one when the pin is configured as an output pin, the port pin is driven high (one). *If PORTxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). *Ex: DDRB = 0xff; //configured as o/p * PORTB = 0xff; //output high * give delay * PORTB = 0x00;//output low DDRx PORTx Output 1 0 0 1 1 1
  13. 13. * *PINx is used to read the data *Ex: Say a sensor is connected to lsb of Port D. * To read the status of the sensor, we use PIND * i.e., x=PIND;//x acquires the status of portD * if(x&0b00000001) * { sensor is ON } * else * { sensor is OFF }
  14. 14. * Program: main() { DDRB=0XFF; while(1) { PORTB=0XFF; _delay_ms(255); PORTB=0X00; _delay_ms(255); } }
  15. 15. *
  16. 16. *
  17. 17. *
  18. 18. *
  • DREng1

    Aug. 23, 2020
  • vaishnavidevika

    Apr. 21, 2020
  • SonuKumar1149

    Jan. 22, 2020
  • shivsagarkanojiya

    Sep. 2, 2019
  • myburningdestiny

    Feb. 26, 2019
  • NIVIAV

    Feb. 5, 2019
  • amreentk

    Aug. 16, 2018
  • adityatrivedi41

    Dec. 21, 2017
  • umrsraj

    Dec. 14, 2017
  • OKPOHOMONDAY

    Aug. 18, 2017
  • RoyceChua2

    Aug. 17, 2017
  • NilaRam

    Aug. 17, 2017
  • mahimachoudhary7

    Aug. 2, 2017
  • RishikeshKhadatkar

    Jul. 17, 2017
  • AhmedTarek42

    Apr. 27, 2017
  • DevendraKhatri3

    Apr. 23, 2017
  • RohitXtar

    Mar. 24, 2017
  • 9910662422_98

    Feb. 17, 2017
  • farzadhallajiazad

    Jan. 26, 2017
  • MohamedSalim24

    Jan. 16, 2017

Basics on Embedded C and Programming ATmega micro-controller using embedded C.

Aufrufe

Aufrufe insgesamt

46.828

Auf Slideshare

0

Aus Einbettungen

0

Anzahl der Einbettungen

65

Befehle

Downloads

1.991

Geteilt

0

Kommentare

0

Likes

45

×