Operácie

AVR Example3.c: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
 
Balogh (diskusia | príspevky)
Bez shrnutí editace
 
(3 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.)
Riadok 4: Riadok 4:
/*  Monoliticke mikropocitace - Priklad 1.3                                  */
/*  Monoliticke mikropocitace - Priklad 1.3                                  */
/*                                                                            */
/*                                                                            */
/*  Program zasvieti/zhasne LED na PD5 s periodou ???                        */
/*  Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s]            */
/*                                                                            */
/*                                                                            */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
/*  Historia:                                                                */
/*  Historia:                                                                */
/*            3. 3. 2006 prva pokusna verzia                                  */
/*            3. 3. 2006 prva pokusna verzia                                  */
/*          12.10. 2012 upravene pre Acrob / Arduino (portD / portB)        */
/*  Verzia:                                                                  */
/*  Verzia:                                                                  */
/*            Pre studentov, chybajuce hodnoty                                */
/*            Pre studentov, chybajuce hodnoty                                */
Riadok 17: Riadok 18:
#include <avr/io.h>         
#include <avr/io.h>         


#define LEDon  PORTD &= ~(_BV(PD5)) // cbi(PORTD,PD5); ale cbi je nepodporovane  
#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane  
#define LEDoff (PORTD |= _BV(PD5))  // sbi(PORTD,PD5); ale sbi je nepodporovane
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,PB5); ale sbi je nepodporovane


#define F_CPU 8000000
#define F_CPU 16000000


void delay_ms(unsigned int ms);
void delay_ms(unsigned int ms);
Riadok 27: Riadok 28:
{
{
                        
                        
     DDRD = 0x??;            // bin: ???? ????  1 = out, 0 = in
     DDRB = 0x??;            // bin: ???? ????  1 = out, 0 = in
     PORTD = 0x??;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON
     PORTB = 0x??;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON


     do{
     do{
    
    
         LEDoff;            // bin  PORTD + 0010 0000 = nastav PD5, LED OFF
         LEDoff;            // bin  PORTB + 0010 0000 = nastav PB5, LED OFF
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PD5, LED ON
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         delay_ms(500);      // cakaj 500 ms (0,5 s)
          
          
Riadok 62: Riadok 63:
</source>
</source>


[[Category:AVR]][[Category:CAD_RS]]
[[Súbor:logo_Ardiuino.png]] Upravená verzia pre prostredie Arduino
 
<source lang="C">
/* ************************************************************************** */
/*                                                                            */
/*  Monoliticke mikropocitace - Priklad 1.3A                                  */
/*                                                                            */
/*  Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s]            */
/*                                                                            */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
/*  Historia:                                                                */
/*            3. 3. 2006 prva pokusna verzia                                  */
/*          12.10. 2012 upravene pre Acrob / Arduino (portD / portB)        */
/*          14.10. 2013 upravene pre Arduino IDE jazyk                      */
/*  Verzia:                                                                  */
/*            Pre studentov, chybajuce hodnoty                                */
/*  Prenositelnost:                                                          */
/*                                                                            */
/* ************************************************************************** */
 
#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,PB5); ale sbi je nepodporovane
 
#define F_CPU 16000000
 
void delay_ms(unsigned int ms);
 
 
  void setup() {
 
    DDRB = 0b????????;            // bin: ???? ????  1 = out, 0 = in
    PORTB = 0b????????;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON
 
}
 
void loop() {
 
        LEDoff;            // bin  PORTB + 0010 0000 = nastav PB5, LED OFF
        delay_ms(500);      // cakaj 500 ms (0,5 s)
        LEDon;              // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON
        delay_ms(500);      // cakaj 500 ms (0,5 s)
       
 
}
 
void delay_ms(unsigned int ms)
{
  unsigned int index;
 
  while (ms)
  {
  index = F_CPU / ????;    // vypocitajte, kolko treba, aby sme dostali 1ms!!
       
  while (index)
  {
    asm volatile ("nop");
    index--;
  }
 
  ms--;
  }
}
 
</source>
 
[[Category:AVR]][[Category:MMP]][[Category:CAD_RS]]

Aktuálna revízia z 20:24, 14. október 2013

/* ************************************************************************** */
/*                                                                            */
/*  Monoliticke mikropocitace - Priklad 1.3                                   */
/*                                                                            */
/*  Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s]             */
/*                                                                            */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                               */
/*  Historia:                                                                 */
/*            3. 3. 2006 prva pokusna verzia                                  */
/*           12.10. 2012 upravene pre Acrob / Arduino (portD / portB)         */
/*  Verzia:                                                                   */
/*            Pre studentov, chybajuce hodnoty                                */
/*  Prenositelnost:                                                           */
/*                                                                            */
/* ************************************************************************** */

#include <avr/io.h>        

#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane 
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,PB5); ale sbi je nepodporovane

#define F_CPU 16000000

void delay_ms(unsigned int ms);

int main (void)
{
                      
     DDRB = 0x??;            // bin: ???? ????  1 = out, 0 = in
    PORTB = 0x??;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON

    do{
   
         LEDoff;             // bin  PORTB + 0010 0000 = nastav PB5, LED OFF
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         
    } while(1);             // toto rob stale dokola

    return (0);             // formalita, nikdy sem neprideme
}


void delay_ms(unsigned int ms)
{
  unsigned int index;

  while (ms)
  {
   index = F_CPU / ????;    // vypocitajte, kolko treba, aby sme dostali 1ms!!
        
   while (index)
   {
    asm volatile ("nop");
    index--;
   }

   ms--;
  }
}

Upravená verzia pre prostredie Arduino

/* ************************************************************************** */
/*                                                                            */
/*  Monoliticke mikropocitace - Priklad 1.3A                                  */
/*                                                                            */
/*  Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s]             */
/*                                                                            */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                               */
/*  Historia:                                                                 */
/*            3. 3. 2006 prva pokusna verzia                                  */
/*           12.10. 2012 upravene pre Acrob / Arduino (portD / portB)         */
/*           14.10. 2013 upravene pre Arduino IDE jazyk                       */
/*  Verzia:                                                                   */
/*            Pre studentov, chybajuce hodnoty                                */
/*  Prenositelnost:                                                           */
/*                                                                            */
/* ************************************************************************** */

#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane 
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,PB5); ale sbi je nepodporovane

#define F_CPU 16000000

void delay_ms(unsigned int ms);


  void setup() {

     DDRB = 0b????????;            // bin: ???? ????  1 = out, 0 = in
    PORTB = 0b????????;            // bin: ???? ????  1 = LED zhasni, 1 = pull-up ON

}

void loop() {

         LEDoff;             // bin  PORTB + 0010 0000 = nastav PB5, LED OFF
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         LEDon;              // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON
         delay_ms(500);      // cakaj 500 ms (0,5 s)
         
  
}

void delay_ms(unsigned int ms)
{
  unsigned int index;

  while (ms)
  {
   index = F_CPU / ????;    // vypocitajte, kolko treba, aby sme dostali 1ms!!
        
   while (index)
   {
    asm volatile ("nop");
    index--;
   }

   ms--;
  }
}