Operácie

AVR Example2.c: Rozdiel medzi revíziami

Z SensorWiki

 
(2 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.)
Riadok 4: Riadok 4:
 
/*  Monoliticke mikropocitace - Priklad 1.2                                  */
 
/*  Monoliticke mikropocitace - Priklad 1.2                                  */
 
/*                                                                            */
 
/*                                                                            */
/*  Program zasvieti/zhasne LED na PD5 podla stavu prepinaca na PD2          */
+
/*  Program zasvieti/zhasne LED na PORTB.5 podla stavu prepinaca na PORTB.4  */
 
/*  Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit    */
 
/*  Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit    */
 
/*                                                                            */
 
/*                                                                            */
 
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
 
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                              */
 
/*  Historia:                                                                */
 
/*  Historia:                                                                */
/*            19.2.2006 prva pokusna verzia                                   */
+
/*            19. 2.2006 prva pokusna verzia                                 */
/*  Prenositelnost:                                                           */
+
/*            12.10.2012 uprava pre Acrob/Arduino (PD -> PB)                  */
 +
/*  Verzia:                                                                   */
 +
/*            studentska bez konkretnych hodnot                              */
 
/*                                                                            */
 
/*                                                                            */
 
/* ************************************************************************** */
 
/* ************************************************************************** */
#include <avr/io.h>          // spolu s -mmcu=atmega16 nahra spravny .h subor
+
 
 +
#include <avr/io.h>          // spolu s -mmcu=atmega328 nahra spravny .h subor
 
                             // ktory potrebujeme kvoli PORTx, PINx a DDRx
 
                             // ktory potrebujeme kvoli PORTx, PINx a DDRx
  
#define SW1 (PIND & 0x??)
+
#define SW1 (PINB & 0x??)
#define LEDon  PORTD &= ~(_BV(PD5)) // cbi(PORTD,PD5); ale cbi je nepodporovane  
+
#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,5); ale cbi je nepodporovane  
#define LEDoff (PORTD |= _BV(PD5))  // sbi(PORTD,PD5); ale sbi je nepodporovane
+
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,5); ale sbi je nepodporovane
  
 
int main (void)
 
int main (void)
 
{
 
{
 
                        
 
                        
     DDRD = 0x??;            // bin: 1010 0010 1 = out, 0 = in
+
     DDRB = 0x??;            // bin: 00?? 0000 1 = out, 0 = in
     PORTD = 0x??;            // bin: 1x11 110x 1 = LED zhasni, 1 = pull-up ON
+
     PORTB = 0x??;            // bin: 00?? 1111 1 = LED zhasni, 1 = pull-up ON
  
 
     do{
 
     do{
 
    
 
    
       if ( SW1 )            // bin:  PIND & 0000 0100 = sw1 OFF?
+
       if ( SW1 )            // bin:  PINB & 0001 0000 = sw1 OFF?
         LEDoff;            // bin PORTD + 0010 0000 = nastav PD5, LED OFF
+
         LEDoff;            // bin: PORTB + 0010 0000 = nastav PB5, LED OFF
 
       else                  // t.j. ak sw1 ON:
 
       else                  // t.j. ak sw1 ON:
         LEDon;            // bin: PORTD & 1101 1111 = vynuluj PD5, LED ON
+
         LEDon;            // bin: PORTB & 1101 1111 = vynuluj PB5, LED ON
  
 
     } while(1);            // toto rob stale dokola
 
     } while(1);            // toto rob stale dokola
Riadok 42: Riadok 45:
  
  
[[CADRS_Cvi%C4%8Denie_8#Postup|Späť na cvičenie...]]
+
[[MMP_Cvi%C4%8Denie_2#Postup|Späť na cvičenie...]]
  
[[Category:AVR]][[Category:CAD_RS]]
+
[[Category:AVR]][[Category:MMP]]

Aktuálna revízia z 07:24, 12. október 2012

/* ************************************************************************** */
/*                                                                            */
/*  Monoliticke mikropocitace - Priklad 1.2                                   */
/*                                                                            */
/*  Program zasvieti/zhasne LED na PORTB.5 podla stavu prepinaca na PORTB.4   */
/*  Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit    */
/*                                                                            */
/*  Autor: Richard Balogh <balogh@elf.stuba.sk>                               */
/*  Historia:                                                                 */
/*            19. 2.2006 prva pokusna verzia                                  */
/*            12.10.2012 uprava pre Acrob/Arduino (PD -> PB)                  */
/*  Verzia:                                                                   */
/*            studentska bez konkretnych hodnot                               */
/*                                                                            */
/* ************************************************************************** */

#include <avr/io.h>          // spolu s -mmcu=atmega328 nahra spravny .h subor
                             // ktory potrebujeme kvoli PORTx, PINx a DDRx

#define SW1 (PINB & 0x??)
#define LEDon  PORTB &= ~(_BV(5)) // cbi(PORTB,5); ale cbi je nepodporovane 
#define LEDoff (PORTB |= _BV(5))  // sbi(PORTB,5); ale sbi je nepodporovane

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

    do{
   
      if ( SW1 )            // bin:  PINB & 0001 0000 = sw1 OFF?
         LEDoff;            // bin: PORTB + 0010 0000 = nastav PB5, LED OFF
      else                  // t.j. ak sw1 ON:
         LEDon;             // bin: PORTB & 1101 1111 = vynuluj PB5, LED ON

    } while(1);            // toto rob stale dokola

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


Späť na cvičenie...